lib/backup/jar.rb in encbs-0.2.5 vs lib/backup/jar.rb in encbs-0.2.5.1
- old
+ new
@@ -74,33 +74,44 @@
end
pbar.bar_mark = '*'
begin
- @local_files.keys.each do |file|
- if @meta_index[file].nil?
- unless File.directory? file
- data = StringIO.new File.open(file, 'rb').read
- checksum = Digest::MD5.hexdigest(data.read)
+ files_to_push = @local_files.keys
+ threads = []
+
+ 32.times do
+ threads << Thread.new do
- data.seek 0
- data = compression.compress(data.read, 3) unless compression.nil?
+ while file = files_to_push.pop
+ if @meta_index[file].nil?
+ unless File.directory? file
+ data = StringIO.new File.open(file, 'rb').read
+ checksum = Digest::MD5.hexdigest(data.read)
- data = @key.encrypt_to_stream(data) if @key
+ data.seek 0
+ data = compression.compress(data.read, 3) unless compression.nil?
- @file_item.create_file_once(
- "#{jar_data_path}/#{@file_item.file_hash file}",
- data
- )
+ data = @key.encrypt_to_stream(data) if @key
- pbar.inc
- end
+ @file_item.create_file_once(
+ "#{jar_data_path}/#{@file_item.file_hash file}",
+ data
+ )
- @meta_index[file] = @local_files[file]
- @meta_index[file][:checksum] = checksum
- @meta_index[file][:timestamp] = @timestamp
+ pbar.inc
+ end
+
+ @meta_index[file] = @local_files[file]
+ @meta_index[file][:checksum] = checksum
+ @meta_index[file][:timestamp] = @timestamp
+ end
+ end
end
end
+
+ threads.each &:join
+
rescue Exception => e
@meta_index.merge!({
:jar_path => meta_jar_path,
:timestamp => @timestamp
})