rbsync 0.0.9 → 0.0.10
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 +59 -12
- data/rbsync.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
data/lib/rbsync.rb
CHANGED
@@ -79,8 +79,24 @@ require 'fileutils'
|
|
79
79
|
# rsync.updated_file_only = true
|
80
80
|
# rsync.sync( "src", "dest" )
|
81
81
|
# rsync.sync( "dest", "src" )# swap src to dest , dest to src
|
82
|
+
#### TODO:
|
83
|
+
## FileUtils/Dir.chdir をSSH対応に切替える
|
84
|
+
## progress 表示のために fileutils.copy を 自作する
|
82
85
|
class RbSync
|
83
86
|
attr_accessor :conf
|
87
|
+
# for ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
|
88
|
+
# File.dirname of cygwin doesn't work corrently for JAPANESE hiragana pathname
|
89
|
+
# Cygwinの日本語UTF8/SJIS環境だと「ひらがな」パス名が正しく扱えないのでmonkey patch
|
90
|
+
if ((RUBY_PLATFORM =~ /cygwin/) and RUBY_VERSION == "1.8.7")then
|
91
|
+
def File.dirname(e)
|
92
|
+
paths = e.split("/")
|
93
|
+
paths.pop
|
94
|
+
paths.join("/")
|
95
|
+
end
|
96
|
+
def FileUtils.mkdir_p(e)
|
97
|
+
`mkdir -p "#{e}"`
|
98
|
+
end
|
99
|
+
end
|
84
100
|
def initialize()
|
85
101
|
@conf ={}
|
86
102
|
@conf[:update] = false
|
@@ -91,11 +107,14 @@ class RbSync
|
|
91
107
|
def find_as_relative(dir_name,excludes=[])
|
92
108
|
files =[]
|
93
109
|
excludes = [] unless excludes
|
110
|
+
#todo write this two line . exculude initialize test
|
111
|
+
excludes = excludes.split(",") if excludes.class == String
|
112
|
+
excludes = [excludes] unless excludes.class == Array
|
113
|
+
|
94
114
|
Dir.chdir(dir_name){
|
95
115
|
files = Dir.glob "./**/*", File::FNM_DOTMATCH
|
96
116
|
exclude_files =[]
|
97
117
|
exclude_files = excludes.map{|g| Dir.glob "./**/#{g}",File::FNM_DOTMATCH }
|
98
|
-
#files.each{|e|pp [e, File.directory?(e)] }
|
99
118
|
files = files.reject{|e| File.directory?(e) }
|
100
119
|
files = files - exclude_files.flatten
|
101
120
|
}
|
@@ -169,33 +188,40 @@ class RbSync
|
|
169
188
|
def collet_hash(file_names,basedir,options={})
|
170
189
|
#prepare
|
171
190
|
require 'thread'
|
191
|
+
self.patch_digest_base
|
172
192
|
threads =[]
|
173
193
|
output = Hash.new{|s,key| s[key]=[] }
|
174
194
|
q = Queue.new
|
175
195
|
limitsize = options[:hash_limit_size]
|
176
196
|
# compute digests
|
177
197
|
file_names.each{|e| q.push e }
|
178
|
-
|
198
|
+
3.times{
|
179
199
|
threads.push(
|
180
200
|
Thread.start{
|
181
201
|
while(!q.empty?)
|
182
202
|
name = q.pop
|
203
|
+
#$stdout.puts "reading #{name}" if options[:verbose]
|
204
|
+
#$stdout.flush if options[:verbose]
|
183
205
|
hash = compute_digest_file(File.expand_path(name,basedir),limitsize)
|
184
206
|
output[hash].push name
|
185
207
|
end
|
186
208
|
}
|
187
209
|
)
|
188
210
|
}
|
211
|
+
if options[:verbose] then
|
212
|
+
t = Thread.start{
|
213
|
+
until(q.empty?)
|
214
|
+
puts( "#{q.size}/#{file_names.size}");
|
215
|
+
$stdout.flush;
|
216
|
+
sleep 1;
|
217
|
+
end
|
218
|
+
}
|
219
|
+
threads.push(t )
|
220
|
+
end
|
189
221
|
threads.each{|t|t.join}
|
190
222
|
return output
|
191
223
|
end
|
192
|
-
|
193
|
-
# ==limitsize
|
194
|
-
# If file size is very large,
|
195
|
-
# and a few bytes at head of file is enough to compare.
|
196
|
-
# for speed-up, Set limit size to enable to avoid reading a whole of file.
|
197
|
-
# もしファイルがとても巨大で、かつ、先頭の数キロバイトが比較に十分であれば、limitsize 以降をスキップする
|
198
|
-
def compute_digest_file(filename, limitsize=nil)
|
224
|
+
def patch_digest_base()
|
199
225
|
require 'digest/md5'
|
200
226
|
s = %{
|
201
227
|
class Digest::Base
|
@@ -213,6 +239,14 @@ class RbSync
|
|
213
239
|
end
|
214
240
|
}
|
215
241
|
eval s
|
242
|
+
end
|
243
|
+
# compute digest md5
|
244
|
+
# ==limitsize
|
245
|
+
# If file size is very large,
|
246
|
+
# and a few bytes at head of file is enough to compare.
|
247
|
+
# for speed-up, Set limit size to enable to avoid reading a whole of file.
|
248
|
+
# もしファイルがとても巨大で、かつ、先頭の数キロバイトが比較に十分であれば、limitsize 以降をスキップする
|
249
|
+
def compute_digest_file(filename, limitsize=nil)
|
216
250
|
Digest::MD5.open(filename,limitsize).hexdigest
|
217
251
|
end
|
218
252
|
|
@@ -314,8 +348,10 @@ class RbSync
|
|
314
348
|
#main
|
315
349
|
copy_thread = Thread.start{
|
316
350
|
FileUtils.mkdir_p File.dirname(e[1]) unless File.exists?(File.dirname(e[1]))
|
351
|
+
## todo copy file as stream for progress
|
317
352
|
FileUtils.copy( e[0] , e[1] ,{:preserve=>self.preserve?,:verbose=>self.verbose? } )
|
318
353
|
}
|
354
|
+
|
319
355
|
#progress of each file
|
320
356
|
progress_thread = nil
|
321
357
|
if(@conf[:progress])
|
@@ -324,11 +360,22 @@ class RbSync
|
|
324
360
|
bar.size = 30
|
325
361
|
src_size = File.size(e[0])
|
326
362
|
dst_size = -1
|
327
|
-
bar.start("copying #{e[0]} to #{e[1]}")
|
363
|
+
bar.start("copying #{e[0]} \r\n to #{e[1]}")
|
364
|
+
cnt = 0
|
328
365
|
while(src_size!=dst_size)
|
366
|
+
unless File.exists?(e[1]) then
|
367
|
+
cnt = cnt + 1
|
368
|
+
if cnt > 10 then
|
369
|
+
puts "copying #{e[1]} timeout error"
|
370
|
+
throw Error
|
371
|
+
break
|
372
|
+
end
|
373
|
+
sleep 0.05
|
374
|
+
next
|
375
|
+
end
|
329
376
|
src_size = File.size(e[0]).to_f
|
330
377
|
dst_size = File.size(e[1]).to_f
|
331
|
-
|
378
|
+
next if dst_size == 0 # preven zero divide
|
332
379
|
percent = dst_size/src_size*100
|
333
380
|
bar.progress(percent.to_int)
|
334
381
|
sleep 0.2
|
@@ -343,7 +390,7 @@ class RbSync
|
|
343
390
|
def sync(src,dest,options={})
|
344
391
|
options[:excludes] = self.excludes.push(options[:excludes]).flatten.uniq if options[:excludes]
|
345
392
|
options[:update] = @conf[:update] if options[:update] == nil
|
346
|
-
options[:check_hash] = options[:check_hash]
|
393
|
+
options[:check_hash] = options[:check_hash] or @conf[:check_hash]
|
347
394
|
options[:hash_limit_size] = @conf[:hash_limit_size] if options[:hash_limit_size] == nil
|
348
395
|
options[:overwrite] = @conf[:overwrite] if options[:overwrite] == nil
|
349
396
|
options[:overwrite] = false if options[:no_overwrite]
|
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
|
+
s.version = "0.0.10"
|
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-
|
12
|
+
s.date = %q{2011-07-10}
|
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 = [
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 10
|
10
|
+
version: 0.0.10
|
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-
|
18
|
+
date: 2011-07-10 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|