rbsync 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rbsync.rb +20 -9
- data/rbsync.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
data/lib/rbsync.rb
CHANGED
@@ -102,6 +102,8 @@ class RbSync
|
|
102
102
|
@conf[:update] = false
|
103
103
|
@conf[:excludes] = []
|
104
104
|
@conf[:preserve] = true
|
105
|
+
@conf[:overwrite] = true
|
106
|
+
@conf[:strict] = true
|
105
107
|
end
|
106
108
|
# collect file paths. paths are relatetive path.
|
107
109
|
def find_as_relative(dir_name,excludes=[])
|
@@ -120,7 +122,7 @@ class RbSync
|
|
120
122
|
}
|
121
123
|
files = files.reject{|e| [".",".."].any?{|s| s== File::basename(e) }}
|
122
124
|
end
|
123
|
-
# compare two directory by name and FileUtis
|
125
|
+
# compare two directory by name and FileUtis.cmp
|
124
126
|
def find_files(src,dest,options)
|
125
127
|
src_files = self.find_as_relative( src, options[:excludes] )
|
126
128
|
dest_files = self.find_as_relative( dest, options[:excludes] )
|
@@ -136,7 +138,12 @@ class RbSync
|
|
136
138
|
same_name_files.reject!{|e|
|
137
139
|
#ファイルが同じモノは省く
|
138
140
|
FileUtils.cmp( File.expand_path(e,src) , File.expand_path(e,dest) )
|
139
|
-
}
|
141
|
+
} if options[:strict]
|
142
|
+
same_name_files.reject!{|e|
|
143
|
+
#ファイルサイズが同じモノを省く(全部比較する代替手段)
|
144
|
+
File.size(File.expand_path(e,src)) == File.size( File.expand_path(e,dest))
|
145
|
+
#&& File.mtime(File.expand_path(e,src)) == File.mtime( File.expand_path(e,dest) )
|
146
|
+
} unless options[:strict]
|
140
147
|
if options[:update] then
|
141
148
|
same_name_files= same_name_files.select{|e|
|
142
149
|
(File.mtime(File.expand_path(e,src)) > File.mtime( File.expand_path(e,dest)))
|
@@ -252,6 +259,7 @@ class RbSync
|
|
252
259
|
|
253
260
|
# called from sync
|
254
261
|
def sync_normally(src,dest,options={})
|
262
|
+
Thread.abort_on_exception = true if self.debug?
|
255
263
|
files = self.find_files(src,dest,options)
|
256
264
|
puts "同期対象のファイルはありません" if self.debug? && files.size==0
|
257
265
|
return true if files.size == 0
|
@@ -348,8 +356,10 @@ class RbSync
|
|
348
356
|
#main
|
349
357
|
copy_thread = Thread.start{
|
350
358
|
FileUtils.mkdir_p File.dirname(e[1]) unless File.exists?(File.dirname(e[1]))
|
359
|
+
tmp_name = "#{e[1]}.copy_tmp"
|
351
360
|
## todo copy file as stream for progress
|
352
|
-
FileUtils.copy( e[0] ,
|
361
|
+
FileUtils.copy( e[0] , tmp_name ,{:preserve=>self.preserve?,:verbose=>self.verbose? } )
|
362
|
+
FileUtils.mv(tmp_name,e[1])
|
353
363
|
}
|
354
364
|
|
355
365
|
#progress of each file
|
@@ -365,21 +375,21 @@ class RbSync
|
|
365
375
|
while(src_size!=dst_size)
|
366
376
|
unless File.exists?(e[1]) then
|
367
377
|
cnt = cnt + 1
|
368
|
-
if cnt >
|
369
|
-
puts "copying #{e[1]} timeout error"
|
378
|
+
if cnt > 25 then
|
379
|
+
puts "copying #{e[1]} is terminated.\r\n timeout error"
|
370
380
|
throw Error
|
371
381
|
break
|
372
382
|
end
|
373
|
-
sleep 0.
|
383
|
+
sleep 0.2
|
374
384
|
next
|
375
385
|
end
|
376
386
|
src_size = File.size(e[0]).to_f
|
377
387
|
dst_size = File.size(e[1]).to_f
|
378
388
|
break if src_size == 0 # preven zero divide
|
379
|
-
next if dst_size == 0 # preven zero divide
|
389
|
+
# next if dst_size == 0 # preven zero divide
|
380
390
|
percent = dst_size/src_size*100
|
381
391
|
bar.progress(percent.to_int)
|
382
|
-
sleep 0.
|
392
|
+
sleep 0.1
|
383
393
|
end
|
384
394
|
bar.end("done")
|
385
395
|
}
|
@@ -390,7 +400,8 @@ class RbSync
|
|
390
400
|
end
|
391
401
|
def sync(src,dest,options={})
|
392
402
|
options[:excludes] = self.excludes.push(options[:excludes]).flatten.uniq if options[:excludes]
|
393
|
-
options[:update] = @conf[:update]
|
403
|
+
options[:update] = @conf[:update] if options[:update] == nil
|
404
|
+
options[:strict] = @conf[:strict] if options[:strict] == nil
|
394
405
|
options[:check_hash] = options[:check_hash] or @conf[:check_hash]
|
395
406
|
options[:hash_limit_size] = @conf[:hash_limit_size] if options[:hash_limit_size] == nil
|
396
407
|
options[:overwrite] = @conf[:overwrite] if options[:overwrite] == nil
|
data/rbsync.gemspec
CHANGED
metadata
CHANGED