six-rsync 0.5.3 → 0.6.0
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.
- data/Rakefile +1 -1
- data/bin/six-rsync +1 -1
- data/bin/six-rsync-mirror +1 -1
- data/lib/six/rsync/lib.rb +219 -245
- data/lib/six/rsync-app.rb +6 -2
- data/lib/six/rsync.rb +2 -2
- metadata +4 -4
data/Rakefile
CHANGED
data/bin/six-rsync
CHANGED
data/bin/six-rsync-mirror
CHANGED
data/lib/six/rsync/lib.rb
CHANGED
@@ -59,11 +59,7 @@ module Six
|
|
59
59
|
|
60
60
|
def status
|
61
61
|
@logger.info "Showing changes on #{@rsync_work_dir}"
|
62
|
-
|
63
|
-
unless @config
|
64
|
-
@logger.error "Not an Rsync repository!"
|
65
|
-
return
|
66
|
-
end
|
62
|
+
handle_config
|
67
63
|
|
68
64
|
load_repos(:local)
|
69
65
|
load_repos(:remote)
|
@@ -113,101 +109,6 @@ module Six
|
|
113
109
|
save_repos(:remote)
|
114
110
|
end
|
115
111
|
|
116
|
-
def clone(repository, name, opts = {})
|
117
|
-
@path = opts[:path] || '.'
|
118
|
-
@rsync_work_dir = opts[:path] ? File.join(@path, name) : name
|
119
|
-
|
120
|
-
# TODO: Solve logger mess completely.
|
121
|
-
@logger = opts[:log] if opts[:log]
|
122
|
-
|
123
|
-
case repository
|
124
|
-
when Array
|
125
|
-
config[:hosts] += repository
|
126
|
-
when String
|
127
|
-
config[:hosts] << repository
|
128
|
-
end
|
129
|
-
|
130
|
-
begin
|
131
|
-
init
|
132
|
-
|
133
|
-
# TODO: Eval move to update?
|
134
|
-
arr_opts = []
|
135
|
-
arr_opts << "-I" if opts[:force]
|
136
|
-
begin
|
137
|
-
update('', arr_opts)
|
138
|
-
rescue RsyncError => e
|
139
|
-
@logger.error "Unable to sucessfully update, aborting... (#{e.class}: #{e.message})"
|
140
|
-
@logger.debug e.backtrace.join("\n")
|
141
|
-
FileUtils.rm_rf @rsync_work_dir if File.exists?(@rsync_work_dir)
|
142
|
-
end
|
143
|
-
rescue RsyncError => e
|
144
|
-
@logger.error "Unable to initialize (#{e.class}: #{e.message})"
|
145
|
-
@logger.debug e.backtrace.join("\n")
|
146
|
-
end
|
147
|
-
|
148
|
-
opts[:bare] ? {:repository => @rsync_work_dir} : {:working_directory => @rsync_work_dir}
|
149
|
-
end
|
150
|
-
|
151
|
-
def update(cmd, x_opts = [], opts = {})
|
152
|
-
@logger.debug "Checking for updates..."
|
153
|
-
@config = load_config
|
154
|
-
unless @config
|
155
|
-
@logger.error "Not an Rsync repository!"
|
156
|
-
raise RsyncError
|
157
|
-
end
|
158
|
-
|
159
|
-
unless config[:hosts].size > 0
|
160
|
-
@logger.error "No hosts configured!"
|
161
|
-
raise RsyncError
|
162
|
-
end
|
163
|
-
|
164
|
-
load_repos(:local)
|
165
|
-
load_repos(:remote)
|
166
|
-
|
167
|
-
hosts = config[:hosts].clone
|
168
|
-
host = hosts.sample
|
169
|
-
|
170
|
-
if opts[:force]
|
171
|
-
done = false
|
172
|
-
b = false
|
173
|
-
verbose = @verbose
|
174
|
-
@verbose = false
|
175
|
-
while hosts.size > 0 && !done do
|
176
|
-
# FIXME: Nasty
|
177
|
-
host = hosts.sample if b
|
178
|
-
b = true
|
179
|
-
hosts -= [host]
|
180
|
-
@logger.info "Trying #{host}"
|
181
|
-
begin
|
182
|
-
arr_opts = []
|
183
|
-
arr_opts << PARAMS
|
184
|
-
arr_opts += x_opts
|
185
|
-
if host[/\A(\w)*\@/]
|
186
|
-
arr_opts << @rsh #"-e ssh"
|
187
|
-
end
|
188
|
-
arr_opts << esc(File.join(host, '.pack/.'))
|
189
|
-
arr_opts << esc(pack_path)
|
190
|
-
command(cmd, arr_opts)
|
191
|
-
calc
|
192
|
-
save_repos
|
193
|
-
done = true
|
194
|
-
rescue => e
|
195
|
-
@logger.warn "#{e.class}: #{e.message}"
|
196
|
-
@logger.debug e.backtrace.join("\n")
|
197
|
-
end
|
198
|
-
end
|
199
|
-
@verbose = verbose
|
200
|
-
raise RsyncError if !done
|
201
|
-
else
|
202
|
-
#reset(:hard => true)
|
203
|
-
calc
|
204
|
-
save_repos
|
205
|
-
|
206
|
-
# fetch latest sums and only update when changed
|
207
|
-
compare_sums(true, host)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
112
|
# TODO: Allow local-self healing, AND remote healing. reset and fetch?
|
212
113
|
def reset(opts = {})
|
213
114
|
@logger.info "Resetting!"
|
@@ -230,18 +131,16 @@ module Six
|
|
230
131
|
ar = Dir[File.join(@rsync_work_dir, '/**/*')]
|
231
132
|
|
232
133
|
change = false
|
233
|
-
|
234
|
-
|
235
|
-
i += 1
|
236
|
-
unless file[/\.gz\Z/]
|
134
|
+
ar.each_with_index do |file, i|
|
135
|
+
unless file[/\.gz$/]
|
237
136
|
relative = file.clone
|
238
137
|
relative.gsub!(@rsync_work_dir, '')
|
239
|
-
relative.gsub!(
|
138
|
+
relative.gsub!(/^[\\|\/]/, '')
|
240
139
|
|
241
140
|
checksum = md5(file)
|
242
141
|
if checksum != @repos_remote[:wd][relative]
|
243
142
|
change = true
|
244
|
-
@logger.info "Packing #{i}/#{ar.size}: #{file}"
|
143
|
+
@logger.info "Packing #{i + 1}/#{ar.size}: #{file}"
|
245
144
|
gzip(file)
|
246
145
|
@repos_remote[:wd][relative] = checksum
|
247
146
|
@repos_remote[:pack]["#{relative}.gz"] = md5("#{file}.gz")
|
@@ -255,29 +154,15 @@ module Six
|
|
255
154
|
end
|
256
155
|
end
|
257
156
|
|
258
|
-
def rename(entry, newentry)
|
259
|
-
FileUtils.mv(entry, "#{entry}_tmp")
|
260
|
-
FileUtils.mv("#{entry}_tmp", newentry)
|
261
|
-
end
|
262
|
-
|
263
157
|
def commit
|
264
158
|
cfg = CONFIG[:commit] ? CONFIG[:commit] : Hash.new
|
265
159
|
@logger.info "Committing changes on #{@rsync_work_dir}"
|
266
|
-
|
267
|
-
|
268
|
-
@logger.error "Not an Rsync repository!"
|
269
|
-
return
|
270
|
-
end
|
271
|
-
|
272
|
-
unless config[:hosts].size > 0
|
273
|
-
@logger.error "No hosts configured!"
|
274
|
-
return
|
275
|
-
end
|
160
|
+
handle_config
|
161
|
+
handle_hosts
|
276
162
|
|
277
163
|
load_repos(:local)
|
278
164
|
load_repos(:remote)
|
279
165
|
|
280
|
-
|
281
166
|
=begin
|
282
167
|
# TODO: Rewrite
|
283
168
|
if cfg[:force_downcase]
|
@@ -379,14 +264,16 @@ module Six
|
|
379
264
|
|
380
265
|
def push(host = nil)
|
381
266
|
@logger.info "Pushing..."
|
382
|
-
|
267
|
+
handle_config
|
268
|
+
handle_hosts
|
269
|
+
|
383
270
|
host = config[:hosts].sample unless host
|
384
271
|
# TODO: UNCLUSTERFUCK
|
385
272
|
arr_opts = []
|
386
273
|
arr_opts << PARAMS
|
387
274
|
|
388
275
|
# Upload .pack changes
|
389
|
-
if host[
|
276
|
+
if host[/^(\w)*\@/]
|
390
277
|
arr_opts << @rsh
|
391
278
|
end
|
392
279
|
arr_opts << esc(pack_path('.'))
|
@@ -395,10 +282,147 @@ module Six
|
|
395
282
|
command('', arr_opts)
|
396
283
|
end
|
397
284
|
|
398
|
-
def
|
285
|
+
def clone(repository, name, opts = {})
|
286
|
+
@path = opts[:path] || '.'
|
287
|
+
@rsync_work_dir = opts[:path] ? File.join(@path, name) : name
|
288
|
+
|
289
|
+
# TODO: Solve logger mess completely.
|
290
|
+
@logger = opts[:log] if opts[:log]
|
291
|
+
|
292
|
+
case repository
|
293
|
+
when Array
|
294
|
+
config[:hosts] += repository
|
295
|
+
when String
|
296
|
+
config[:hosts] << repository
|
297
|
+
end
|
298
|
+
|
299
|
+
# TODO: Eval move to update?
|
300
|
+
arr_opts = []
|
301
|
+
arr_opts << "-I" if opts[:force]
|
302
|
+
|
303
|
+
begin
|
304
|
+
init
|
305
|
+
begin
|
306
|
+
update('', arr_opts)
|
307
|
+
rescue RsyncError => e
|
308
|
+
@logger.error "Unable to sucessfully update... (#{e.class}: #{e.message})"
|
309
|
+
@logger.debug e.backtrace.join("\n")
|
310
|
+
end
|
311
|
+
rescue => e
|
312
|
+
@logger.error "Unable to initialize (#{e.class}: #{e.message})"
|
313
|
+
@logger.debug e.backtrace.join("\n")
|
314
|
+
FileUtils.rm_rf @rsync_work_dir if File.exists?(@rsync_work_dir)
|
315
|
+
raise RsyncError
|
316
|
+
end
|
317
|
+
|
318
|
+
opts[:bare] ? {:repository => @rsync_work_dir} : {:working_directory => @rsync_work_dir}
|
319
|
+
end
|
320
|
+
|
321
|
+
def update(cmd, x_opts = [], opts = {})
|
322
|
+
@logger.debug "Checking for updates..."
|
323
|
+
|
324
|
+
handle_config
|
325
|
+
handle_hosts
|
326
|
+
|
399
327
|
load_repos(:local)
|
400
328
|
load_repos(:remote)
|
401
329
|
|
330
|
+
hosts = config[:hosts].clone
|
331
|
+
host = hosts.sample
|
332
|
+
|
333
|
+
if opts[:force]
|
334
|
+
done = false
|
335
|
+
b = false
|
336
|
+
verbose = @verbose
|
337
|
+
@verbose = false
|
338
|
+
until hosts.empty? || done do
|
339
|
+
# FIXME: Nasty
|
340
|
+
host = hosts.sample if b
|
341
|
+
b = true
|
342
|
+
hosts -= [host]
|
343
|
+
@logger.info "Trying #{host}"
|
344
|
+
begin
|
345
|
+
arr_opts = []
|
346
|
+
arr_opts << PARAMS
|
347
|
+
arr_opts += x_opts
|
348
|
+
arr_opts << @rsh if host[/^(\w)*\@/]
|
349
|
+
arr_opts << esc(File.join(host, '.pack/.'))
|
350
|
+
arr_opts << esc(pack_path)
|
351
|
+
command(cmd, arr_opts)
|
352
|
+
calc
|
353
|
+
save_repos
|
354
|
+
done = true
|
355
|
+
rescue => e
|
356
|
+
@logger.warn "#{e.class}: #{e.message}"
|
357
|
+
@logger.debug e.backtrace.join("\n")
|
358
|
+
end
|
359
|
+
end
|
360
|
+
@verbose = verbose
|
361
|
+
raise RsyncError if !done
|
362
|
+
else
|
363
|
+
#reset(:hard => true)
|
364
|
+
calc
|
365
|
+
save_repos
|
366
|
+
|
367
|
+
# fetch latest sums and only update when changed
|
368
|
+
compare_sums(true, host)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
def compare_sums(online = true, host = config[:hosts].sample)
|
373
|
+
load_repos(:local)
|
374
|
+
done = false
|
375
|
+
|
376
|
+
if online
|
377
|
+
hosts = config[:hosts].clone
|
378
|
+
b = false
|
379
|
+
verbose = @verbose
|
380
|
+
@verbose = false
|
381
|
+
|
382
|
+
until hosts.empty? || done do
|
383
|
+
# FIXME: Nasty
|
384
|
+
host = hosts.sample if b
|
385
|
+
b = true
|
386
|
+
hosts -= [host]
|
387
|
+
@logger.info "Trying #{host}"
|
388
|
+
|
389
|
+
begin
|
390
|
+
FileUtils.cp(pack_path(".repository.yml"), rsync_path(".repository-pack.yml")) if File.exists?(pack_path(".repository.yml"))
|
391
|
+
fetch_file(".pack/.repository.yml", host)
|
392
|
+
load_repos(:remote)
|
393
|
+
|
394
|
+
if @repos_local[:version] > @repos_remote[:version] # && !force
|
395
|
+
@logger.warn "WARNING, version on server is OLDER, aborting!"
|
396
|
+
raise RsyncError
|
397
|
+
end
|
398
|
+
done = true
|
399
|
+
rescue => e
|
400
|
+
@logger.warn "#{e.class}: #{e.message}"
|
401
|
+
@logger.debug e.backtrace.join("\n")
|
402
|
+
FileUtils.cp(rsync_path(".repository-pack.yml"), pack_path(".repository.yml")) if File.exists?(rsync_path(".repository-pack.yml"))
|
403
|
+
ensure
|
404
|
+
FileUtils.rm(rsync_path(".repository-pack.yml")) if File.exists?(rsync_path(".repository-pack.yml"))
|
405
|
+
end
|
406
|
+
end
|
407
|
+
@verbose = verbose
|
408
|
+
else
|
409
|
+
load_repos(:remote)
|
410
|
+
end
|
411
|
+
|
412
|
+
if done && online
|
413
|
+
@logger.info "Verifying Packed files..."
|
414
|
+
compare_set(:pack, host)
|
415
|
+
|
416
|
+
@logger.info "Verifying Unpacked files..."
|
417
|
+
compare_set(:wd, host)
|
418
|
+
|
419
|
+
# Bump version and make final save
|
420
|
+
@repos_local[:version] = @repos_remote[:version]
|
421
|
+
save_repos
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
def compare_set(typ, host, online = true)
|
402
426
|
#if local[typ][:md5] == remote[typ][:md5]
|
403
427
|
# @logger.info "#{typ} Match!"
|
404
428
|
#else
|
@@ -426,7 +450,7 @@ module Six
|
|
426
450
|
## Pack
|
427
451
|
if online
|
428
452
|
b = false
|
429
|
-
|
453
|
+
until hosts.empty? || done do
|
430
454
|
# FIXME: Nasty
|
431
455
|
if b
|
432
456
|
host = hosts.sample
|
@@ -435,44 +459,30 @@ module Six
|
|
435
459
|
slist = nil
|
436
460
|
b = true
|
437
461
|
hosts -= [host]
|
462
|
+
|
463
|
+
# TODO: Progress bar
|
464
|
+
arr_opts = []
|
465
|
+
arr_opts << PARAMS
|
466
|
+
arr_opts << @rsh if host[/^(\w)*\@/]
|
467
|
+
|
468
|
+
if mismatch.size > (@repos_remote[typ].size / 2)
|
469
|
+
# Process full folder
|
470
|
+
@logger.info "Many files mismatched (#{mismatch.size}), running full update on .pack folder"
|
471
|
+
else
|
472
|
+
# Process only selective
|
473
|
+
@logger.info "Fetching #{mismatch.size} files... Please wait"
|
474
|
+
slist = File.join(TEMP_PATH, ".six-rsync_#{rand 9999}-list")
|
475
|
+
slist.gsub!("\\", "/")
|
476
|
+
File.open(slist, 'w') { |f| mismatch.each { |e| f.puts e } }
|
477
|
+
|
478
|
+
arr_opts << "--files-from=#{win2cyg("\"#{slist}\"")}"
|
479
|
+
end
|
480
|
+
|
438
481
|
begin
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
arr_opts << PARAMS
|
444
|
-
if host[/\A(\w)*\@/]
|
445
|
-
arr_opts << @rsh
|
446
|
-
end
|
447
|
-
|
448
|
-
arr_opts << esc(File.join(host, '.pack/.'))
|
449
|
-
arr_opts << esc(pack_path)
|
450
|
-
command('', arr_opts)
|
451
|
-
else
|
452
|
-
c = mismatch.size
|
453
|
-
@logger.info "Fetching #{mismatch.size} files... Please wait"
|
454
|
-
slist = File.join(TEMP_PATH, ".six-rsync_#{rand 9999}-list")
|
455
|
-
slist.gsub!("\\", "/")
|
456
|
-
File.open(slist, 'w') do |f|
|
457
|
-
mismatch.each { |e| f.puts e }
|
458
|
-
end
|
459
|
-
arr_opts = []
|
460
|
-
arr_opts << PARAMS
|
461
|
-
arr_opts << @rsh if host[/\A(\w)*\@/]
|
462
|
-
|
463
|
-
cyg_slist = "\"#{slist}\""
|
464
|
-
|
465
|
-
while cyg_slist[WINDRIVE] do
|
466
|
-
drive = cyg_slist[WINDRIVE]
|
467
|
-
cyg_slist.gsub!(drive, "\"/cygdrive/#{$1}")
|
468
|
-
end
|
469
|
-
arr_opts << "--files-from=#{cyg_slist}"
|
470
|
-
|
471
|
-
arr_opts << esc(File.join(host, '.pack/.'))
|
472
|
-
arr_opts << esc(pack_path)
|
473
|
-
|
474
|
-
command('', arr_opts)
|
475
|
-
end
|
482
|
+
arr_opts << esc(File.join(host, '.pack/.'))
|
483
|
+
arr_opts << esc(pack_path)
|
484
|
+
command('', arr_opts)
|
485
|
+
|
476
486
|
done = true
|
477
487
|
rescue => e
|
478
488
|
@logger.warn "Failure"
|
@@ -497,60 +507,45 @@ module Six
|
|
497
507
|
del_file(key, typ) unless config[:exclude].include?(key) || !@repos_remote[typ][key].nil?
|
498
508
|
end
|
499
509
|
|
510
|
+
# Calculate new sums
|
500
511
|
@repos_local[typ] = calc_sums(typ)
|
501
|
-
|
512
|
+
|
513
|
+
# Save current progress, incase somewhere else goes wrong.
|
502
514
|
save_repos
|
503
515
|
end
|
504
516
|
|
505
|
-
def compare_sums(online = true, host = config[:hosts].sample)
|
506
|
-
hosts = config[:hosts].clone
|
507
|
-
done = false
|
508
517
|
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
@
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
b = true
|
518
|
-
hosts -= [host]
|
519
|
-
@logger.info "Trying #{host}"
|
518
|
+
private
|
519
|
+
def handle_config
|
520
|
+
@config = load_config
|
521
|
+
unless @config
|
522
|
+
@logger.error "Not an Rsync repository!"
|
523
|
+
raise RsyncError
|
524
|
+
end
|
525
|
+
end
|
520
526
|
|
521
|
-
|
522
|
-
|
523
|
-
|
527
|
+
def handle_hosts
|
528
|
+
unless config[:hosts].size > 0
|
529
|
+
@logger.error "No hosts configured!"
|
530
|
+
raise RsyncError
|
531
|
+
end
|
532
|
+
end
|
524
533
|
|
525
|
-
|
526
|
-
|
534
|
+
def rename(entry, newentry)
|
535
|
+
FileUtils.mv(entry, "#{entry}_tmp")
|
536
|
+
FileUtils.mv("#{entry}_tmp", newentry)
|
537
|
+
end
|
527
538
|
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
rescue => e
|
535
|
-
@logger.warn "#{e.class}: #{e.message}"
|
536
|
-
@logger.debug e.backtrace.join("\n")
|
537
|
-
ensure
|
538
|
-
FileUtils.rm(rsync_path(".repository-pack.yml"))
|
539
|
-
end
|
540
|
-
end
|
541
|
-
@verbose = verbose
|
542
|
-
end
|
543
|
-
if done && online
|
544
|
-
# TODO: Don't do actions when not online
|
545
|
-
@logger.info "Verifying Packed files..."
|
546
|
-
compare_set(:pack, host)
|
547
|
-
@logger.info "Verifying Unpacked files..."
|
548
|
-
compare_set(:wd, host)
|
549
|
-
save_repos
|
539
|
+
def win2cyg(path)
|
540
|
+
path = path.clone
|
541
|
+
#path.gsub!(WINDRIVE) {|s| "\"/cygdrive/#{s}" }
|
542
|
+
while path[WINDRIVE]
|
543
|
+
drive = path[WINDRIVE]
|
544
|
+
path.gsub!(drive, "\"/cygdrive/#{$1}")
|
550
545
|
end
|
546
|
+
path
|
551
547
|
end
|
552
548
|
|
553
|
-
private
|
554
549
|
def esc(val); "\"#{val}\""; end
|
555
550
|
def escape(s); "\"" + s.to_s.gsub('\"', '\"\\\"\"') + "\""; end
|
556
551
|
|
@@ -563,14 +558,12 @@ module Six
|
|
563
558
|
|
564
559
|
def rsync_path(path = '')
|
565
560
|
p = File.join(@rsync_work_dir, DIR_RSYNC)
|
566
|
-
p
|
567
|
-
p
|
561
|
+
path.size == 0 ? p : File.join(p, path)
|
568
562
|
end
|
569
563
|
|
570
564
|
def pack_path(path = '')
|
571
565
|
p = File.join(@rsync_work_dir, DIR_PACK)
|
572
|
-
p
|
573
|
-
p
|
566
|
+
path.size == 0 ? p : File.join(p, path)
|
574
567
|
end
|
575
568
|
|
576
569
|
def fetch_file(path, host)
|
@@ -582,9 +575,7 @@ module Six
|
|
582
575
|
@logger.debug "Fetching #{path} from #{host}"
|
583
576
|
arr_opts = []
|
584
577
|
arr_opts << PARAMS
|
585
|
-
if host[
|
586
|
-
arr_opts << @rsh
|
587
|
-
end
|
578
|
+
arr_opts << @rsh if host[/^(\w)*\@/]
|
588
579
|
arr_opts << esc(File.join(host, path))
|
589
580
|
arr_opts << esc(rsync_path(folder))
|
590
581
|
|
@@ -602,10 +593,10 @@ module Six
|
|
602
593
|
reg = case typ
|
603
594
|
when :pack
|
604
595
|
ar = Dir[pack_path('**/*')]
|
605
|
-
|
596
|
+
/^[\\|\/]\.rsync[\\|\/]\.pack[\\|\/]/
|
606
597
|
when :wd
|
607
598
|
ar = Dir[File.join(@rsync_work_dir, '/**/*')]
|
608
|
-
|
599
|
+
/^[\\|\/]/
|
609
600
|
end
|
610
601
|
h = Hash.new
|
611
602
|
ar.each do |file|
|
@@ -613,8 +604,9 @@ module Six
|
|
613
604
|
relative.gsub!(@rsync_work_dir, '')
|
614
605
|
relative.gsub!(reg, '')
|
615
606
|
|
607
|
+
next if config[:exclude].include?(relative)
|
616
608
|
sum = md5(file)
|
617
|
-
h[relative] = sum if sum
|
609
|
+
h[relative] = sum if sum
|
618
610
|
end
|
619
611
|
h
|
620
612
|
end
|
@@ -622,11 +614,7 @@ module Six
|
|
622
614
|
def load_config; load_yaml(File.join(rsync_path, 'config.yml')); end
|
623
615
|
|
624
616
|
def load_yaml(file)
|
625
|
-
|
626
|
-
YAML::load_file(file)
|
627
|
-
else
|
628
|
-
nil
|
629
|
-
end
|
617
|
+
File.exists?(file) ? YAML::load_file(file) : nil
|
630
618
|
end
|
631
619
|
|
632
620
|
def save_default_config
|
@@ -654,12 +642,11 @@ module Six
|
|
654
642
|
end
|
655
643
|
|
656
644
|
def load_repos(typ)
|
657
|
-
config =
|
658
|
-
case typ
|
645
|
+
config = case typ
|
659
646
|
when :local
|
660
|
-
|
647
|
+
YAML::load_file(rsync_path('.repository.yml'))
|
661
648
|
when :remote
|
662
|
-
|
649
|
+
YAML::load_file(pack_path('.repository.yml'))
|
663
650
|
end
|
664
651
|
|
665
652
|
[:wd, :pack].each do |t|
|
@@ -696,12 +683,11 @@ module Six
|
|
696
683
|
end
|
697
684
|
|
698
685
|
unless File.directory? path
|
699
|
-
path
|
700
|
-
folder, file = $1, $2
|
686
|
+
folder, file = File.dirname(path), File.basename(path)
|
701
687
|
Dir.chdir(folder) do
|
702
688
|
r = %x[md5sum #{esc(file)}]
|
703
689
|
@logger.debug r
|
704
|
-
r[
|
690
|
+
r[/^\w*/]
|
705
691
|
end
|
706
692
|
end
|
707
693
|
end
|
@@ -726,6 +712,7 @@ module Six
|
|
726
712
|
out = %x[gzip -f --best --rsyncable --keep #{esc(file)}]
|
727
713
|
@logger.debug out
|
728
714
|
raise RsyncError if $? != 0
|
715
|
+
out
|
729
716
|
end
|
730
717
|
|
731
718
|
def unpack_file(file, path)
|
@@ -756,7 +743,7 @@ module Six
|
|
756
743
|
unless File.directory? file
|
757
744
|
relative = file.clone
|
758
745
|
relative.gsub!(@rsync_work_dir, '')
|
759
|
-
relative.gsub!(
|
746
|
+
relative.gsub!(/^[\\|\/]\.rsync[\\|\/]\.pack[\\|\/]/, '')
|
760
747
|
fil = relative
|
761
748
|
folder = "."
|
762
749
|
folder, fil = $1, $2 if relative[/(.*)\/(.*)/]
|
@@ -780,24 +767,11 @@ module Six
|
|
780
767
|
opts << "--timeout=#{DEFAULT_TIMEOUT}"
|
781
768
|
|
782
769
|
opts = [opts].flatten.map {|s| s }.join(' ') # escape()
|
783
|
-
rsync_cmd = "rsync #{cmd} #{opts} #{redirect} 2>&1"
|
784
|
-
|
785
|
-
while rsync_cmd[WINDRIVE] do
|
786
|
-
drive = rsync_cmd[WINDRIVE]
|
787
|
-
rsync_cmd.gsub!(drive, "\"/cygdrive/#{$1}")
|
788
|
-
end
|
770
|
+
rsync_cmd = win2cyg("rsync #{cmd} #{opts} #{redirect} 2>&1")
|
789
771
|
|
790
|
-
if @logger
|
791
|
-
@logger.debug(rsync_cmd)
|
792
|
-
end
|
793
|
-
|
794
|
-
out = nil
|
795
|
-
if chdir && (Dir.getwd != path)
|
796
|
-
Dir.chdir(path) { out = run_command(rsync_cmd, &block) }
|
797
|
-
else
|
798
|
-
out = run_command(rsync_cmd, &block)
|
799
|
-
end
|
772
|
+
@logger.debug(rsync_cmd) if @logger
|
800
773
|
|
774
|
+
out = chdir && (Dir.getwd != path) ? Dir.chdir(path) { run_command(rsync_cmd, &block) } : run_command(rsync_cmd, &block)
|
801
775
|
out
|
802
776
|
end
|
803
777
|
|
data/lib/six/rsync-app.rb
CHANGED
@@ -56,8 +56,12 @@ module Six
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def self.clone(folder)
|
59
|
-
folder[/
|
60
|
-
|
59
|
+
pa = if folder[/[\/|\\]/]
|
60
|
+
folder = File.basename(folder)
|
61
|
+
File.dirname(folder)
|
62
|
+
else
|
63
|
+
Dir.pwd
|
64
|
+
end
|
61
65
|
@repo = Six::Repositories::Rsync.clone(Six::Repositories::Rsync.host, folder, :path => pa, :log => Six::Repositories::Rsync.logger)
|
62
66
|
end
|
63
67
|
|
data/lib/six/rsync.rb
CHANGED
@@ -19,7 +19,7 @@ case RUBY_VERSION
|
|
19
19
|
when /1\.8\.[0-9]/
|
20
20
|
class Array
|
21
21
|
def sample
|
22
|
-
self[rand
|
22
|
+
self[rand(self.size)]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -31,7 +31,7 @@ module Six
|
|
31
31
|
|
32
32
|
module Rsync
|
33
33
|
COMPONENT = 'six-rsync'
|
34
|
-
VERSION = '0.
|
34
|
+
VERSION = '0.6.0'
|
35
35
|
FOLDER = /(.*)\/(.*)/
|
36
36
|
|
37
37
|
case RUBY_PLATFORM
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 0.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sickboy
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-07 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|