rbsync 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
data/lib/rbsync.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
 
4
4
  require 'fileutils'
5
-
6
5
  # Synchronize files src to dest .
7
6
  # this class can sync files and recuresively
8
7
  # options are
@@ -133,6 +132,7 @@ class RbSync
133
132
  #files
134
133
  files =[]
135
134
  files = (files_not_in_dest + same_name_files ).flatten
135
+ files
136
136
  end
137
137
  def sync_by_hash(src,dest,options={})
138
138
  src_files = collet_hash(find_as_relative(src, options[:excludes]), src, options)
@@ -328,14 +328,16 @@ class RbSync
328
328
  while(src_size!=dst_size)
329
329
  src_size = File.size(e[0]).to_f
330
330
  dst_size = File.size(e[1]).to_f
331
- bar.progress(((dst_size/src_size)*100).to_int)
331
+ break if dst_size == 0
332
+ percent = dst_size/src_size*100
333
+ bar.progress(percent.to_int)
332
334
  sleep 0.2
333
335
  end
334
336
  bar.end("done")
335
337
  }
336
338
  end
337
- copy_thread.join
338
339
  progress_thread.join if progress_thread
340
+ copy_thread.join
339
341
  }
340
342
  end
341
343
  def sync(src,dest,options={})
@@ -345,6 +347,7 @@ class RbSync
345
347
  options[:hash_limit_size] = @conf[:hash_limit_size] if options[:hash_limit_size] == nil
346
348
  options[:overwrite] = @conf[:overwrite] if options[:overwrite] == nil
347
349
  options[:overwrite] = false if options[:no_overwrite]
350
+ FileUtils.mkdir_p dest unless File.exists? dest
348
351
  if options[:rename]
349
352
  return self.sync_by_anothername(src,dest,options)
350
353
  elsif options[:backup]
@@ -475,19 +478,31 @@ if __FILE__ == $0
475
478
  require 'tmpdir'
476
479
  require 'find'
477
480
  require 'pp'
478
- Dir.mktmpdir('goo') do |dir|
479
- Dir.chdir dir do
480
- Dir.mkdir("old")
481
- Dir.mkdir("new")
482
- open("./old/test.txt", "w+"){|f| 10.times{f.puts("test")}}
483
- time1 = Time.local(2008, 1, 1, 1, 1, 1)
484
- File::utime( time1 , time1, "./old/test.txt")
485
- rsync = RbSync.new
486
- rsync.sync("old","new",{:update=>true})
487
- # timestamp is preserved?
488
- p File.mtime("./new/test.txt") == time1
489
- p File.atime("./new/test.txt") == time1
490
- end
491
- end
481
+ #Dir.mktmpdir('foo') do |dir|
482
+ #Dir.chdir dir do
483
+ #Dir.mkdir("src")
484
+ #Dir.mkdir("dst")
485
+ #open("./src/test1.txt", "w+"){|f| 10.times{f.puts("test")}}
486
+ #open("./dst/test2.txt", "w+"){|f| 10.times{f.puts("aaaa")}}
487
+ #rsync = RbSync.new
488
+ #$count = $count+ 1
489
+ #rsync.sync("src","dst",{:update=>true})
490
+ #$count = $count+ 1
491
+ #rsync.sync("dst","src",{:update=>true})
492
+ #p File.mtime("./src/test2.txt")
493
+ ##p FileUtils.cmp("src/test1.txt","dst/test1.txt")
494
+ ##p FileUtils.cmp("src/test2.txt","dst/test2.txt")
495
+ ##p open("./dst/test2.txt", "r").read
496
+ ##p open("./src/test2.txt", "r").read
497
+ #open("./src/test2.txt", "w+"){|f| 10.times{f.puts("bbb")}}
498
+ #p File.mtime("./src/test2.txt")
499
+ #$count = $count+ 1
500
+ #rsync.sync("src","dst",{:update=>true,})
501
+ ##rsync.sync("dst","src",{:update=>true})
502
+ #p open("./dst/test2.txt", "r").read
503
+ #p open("./src/test2.txt", "r").read
504
+ #p FileUtils.cmp("src/test2.txt","dst/test2.txt")
505
+ #end
506
+ #end
492
507
  puts :END
493
508
  end
data/rbsync.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rbsync}
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["takuya"]
12
- s.date = %q{2011-06-14}
12
+ s.date = %q{2011-06-15}
13
13
  s.description = %q{rbsync is sync file utility.this can sync directory even if filename differed.checking content insted.}
14
14
  s.email = %q{takuya.1st@gmail}
15
15
  s.extra_rdoc_files = [
data/test/test_rbsync.rb CHANGED
@@ -248,5 +248,83 @@ class TestRbsync < Test::Unit::TestCase
248
248
  end
249
249
  end
250
250
  end
251
+ def test_sync_both
252
+ Dir.mktmpdir('foo') do |dir|
253
+ Dir.chdir dir do
254
+ Dir.mkdir("src")
255
+ Dir.mkdir("dst")
256
+ open("./src/test1.txt", "w+"){|f| 10.times{f.puts("test")}}
257
+ open("./dst/test2.txt", "w+"){|f| 10.times{f.puts("aaaa")}}
258
+ rsync = RbSync.new
259
+ rsync.sync("src","dst",{:update=>true})
260
+ rsync.sync("dst","src",{:update=>true})
261
+ assert FileUtils.cmp("src/test1.txt","dst/test1.txt")
262
+ assert FileUtils.cmp("src/test2.txt","dst/test2.txt")
263
+ end
264
+ end
265
+ end
266
+ def test_sync_both_twice
267
+ Dir.mktmpdir('foo') do |dir|
268
+ Dir.chdir dir do
269
+ Dir.mkdir("src")
270
+ Dir.mkdir("dst")
271
+ open("./src/test1.txt", "w+"){|f| 10.times{f.puts("test")}}
272
+ open("./dst/test2.txt", "w+"){|f| 10.times{f.puts("aaaa")}}
273
+ rsync = RbSync.new
274
+ rsync.sync("src","dst",{:update=>true})
275
+ rsync.sync("dst","src",{:update=>true})
276
+ assert FileUtils.cmp("src/test1.txt","dst/test1.txt")
277
+ assert FileUtils.cmp("src/test2.txt","dst/test2.txt")
278
+ open("./src/test2.txt", "w+"){|f| 10.times{f.puts("bbb")}}
279
+ File::utime( Time.now+10 , Time.now+10, "./src/test2.txt")# for windows , mtime can not get mili sec
280
+ rsync.sync("src","dst",{:update=>true,})
281
+ rsync.sync("dst","src",{:update=>true})
282
+ assert FileUtils.cmp("src/test1.txt","dst/test1.txt")
283
+ assert FileUtils.cmp("src/test2.txt","dst/test2.txt")
284
+ end
285
+ end
286
+ end
287
+ def test_sync_both_twice_dirty_order
288
+ Dir.mktmpdir('foo') do |dir|
289
+ Dir.chdir dir do
290
+ Dir.mkdir("src")
291
+ Dir.mkdir("dst")
292
+ open("./src/test1.txt", "w+"){|f| 10.times{f.puts("test")}}
293
+ open("./dst/test2.txt", "w+"){|f| 10.times{f.puts("aaaa")}}
294
+ rsync = RbSync.new
295
+ rsync.sync("src","dst",{:update=>true})
296
+ rsync.sync("dst","src",{:update=>true})
297
+ assert FileUtils.cmp("src/test1.txt","dst/test1.txt")
298
+ assert FileUtils.cmp("src/test2.txt","dst/test2.txt")
299
+ open("./src/test2.txt", "w+"){|f| 10.times{f.puts("bbb")}}
300
+ File::utime( Time.now+10 , Time.now+10, "./src/test2.txt")# for windows , mtime can not get mili sec
301
+ rsync.sync("dst","src",{:update=>true}) #
302
+ rsync.sync("src","dst",{:update=>true,})#
303
+ assert FileUtils.cmp("src/test1.txt","dst/test1.txt")
304
+ assert FileUtils.cmp("src/test2.txt","dst/test2.txt")
305
+ end
306
+ end
307
+ end
308
+ def test_sync_both_hash
309
+ Dir.mktmpdir('foo') do |dir|
310
+ Dir.chdir dir do
311
+ Dir.mkdir("src")
312
+ Dir.mkdir("dst")
313
+ open("./src/test1.txt", "w+"){|f| 10.times{f.puts("test")}}
314
+ open("./dst/test2.txt", "w+"){|f| 10.times{f.puts("aaaa")}}
315
+ rsync = RbSync.new
316
+ rsync.sync("src","dst",{:check_hash=>true})
317
+ rsync.sync("dst","src",{:check_hash=>true})
318
+ assert FileUtils.cmp("src/test1.txt","dst/test1.txt")
319
+ assert FileUtils.cmp("src/test2.txt","dst/test2.txt")
320
+ open("./src/test2.txt", "w+"){|f| 10.times{f.puts("bbb")}}
321
+ File::utime( Time.now+10 , Time.now+10, "./src/test2.txt")# for windows , mtime can not get mili sec
322
+ rsync.sync("src","dst",{:check_hash=>true,})#
323
+ rsync.sync("dst","src",{:check_hash=>true}) #
324
+ assert FileUtils.cmp("src/test1.txt","dst/test1.txt")
325
+ assert FileUtils.cmp("src/test2.txt","dst/test2.txt")
326
+ end
327
+ end
328
+ end
251
329
 
252
330
  end
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - takuya
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-14 00:00:00 +09:00
18
+ date: 2011-06-15 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency