Module: DRbQS::FileTransfer
- Defined in:
- lib/drbqs/ssh/transfer.rb
Overview
To compress files, we use gzip and tar command. Note that if we compress files then we delete the source files.
Constant Summary collapse
- @@files =
Queue.new
Class Method Summary collapse
- .compress_enqueue(path) ⇒ Object
- .decompress(server, filename) ⇒ Object
- .dequeue ⇒ Object
- .empty? ⇒ Boolean
- .enqueue(path, compress = false) ⇒ Object
Class Method Details
.compress_enqueue(path) ⇒ Object
85 86 87 |
# File 'lib/drbqs/ssh/transfer.rb', line 85 def self.compress_enqueue(path) self.enqueue(path, true) end |
.decompress(server, filename) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/drbqs/ssh/transfer.rb', line 97 def self.decompress(server, filename) dir = server.transfer_directory path = File.join(dir, filename) if File.exist?(path) case path when /\.tar\.gz$/ cmd = "tar xvzf #{path} -C #{dir} > /dev/null 2>&1" when /\.gz$/ cmd = "gunzip #{path} > /dev/null 2>&1" else cmd = nil end system(cmd) if cmd end end |
.dequeue ⇒ Object
89 90 91 |
# File 'lib/drbqs/ssh/transfer.rb', line 89 def self.dequeue @@files.deq end |
.empty? ⇒ Boolean
93 94 95 |
# File 'lib/drbqs/ssh/transfer.rb', line 93 def self.empty? @@files.empty? end |
.enqueue(path, compress = false) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/drbqs/ssh/transfer.rb', line 62 def self.enqueue(path, compress = false) if compress if File.directory?(path) gz_path = "#{path.sub(/\/$/, '')}.tar.gz" cmd = "tar czf #{gz_path} -C #{File.dirname(path)} #{File.basename(path)} > /dev/null 2>&1" else gz_path = path + '.gz' cmd = "gzip --best #{path} > /dev/null 2>&1" end if File.exist?(gz_path) raise "File has already existed: #{gz_path}" elsif !system(cmd) raise "Can not compress: #{path}" end FileUtils.rm_r(path) if File.exist?(path) path_to_send = gz_path else path_to_send = path end @@files.enq(path_to_send) File.basename(path_to_send) end |