rbsync 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/rbsync.rb +20 -9
  3. data/rbsync.gemspec +1 -1
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
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,cmp
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] , e[1] ,{:preserve=>self.preserve?,:verbose=>self.verbose? } )
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 > 10 then
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.05
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.2
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] if options[:update] == nil
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rbsync}
8
- s.version = "0.0.11"
8
+ s.version = "0.0.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["takuya"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbsync
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - takuya