six-rsync 0.6.1 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/six/rsync/lib.rb +185 -109
- data/lib/six/rsync-app.rb +1 -1
- data/lib/six/rsync.rb +1 -1
- data/lib/six/wrapper.rb +3 -0
- metadata +4 -3
data/Rakefile
CHANGED
data/lib/six/rsync/lib.rb
CHANGED
@@ -88,6 +88,16 @@ module Six
|
|
88
88
|
@logger.info "Removed: #{key}"
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
@repos_local[:pack].each_pair do |key, value|
|
93
|
+
i += 1
|
94
|
+
localkey = "#{key}"
|
95
|
+
localkey.gsub!(/\.gz$/, "")
|
96
|
+
if @repos_local[:wd][localkey].nil?
|
97
|
+
@logger.info "Removed: #{key}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
91
101
|
end
|
92
102
|
|
93
103
|
def init
|
@@ -216,11 +226,26 @@ module Six
|
|
216
226
|
|
217
227
|
@logger.info "Removing: #{packed}"
|
218
228
|
@repos_local[:wd].delete key
|
219
|
-
@repos_local[:pack].delete packed
|
229
|
+
@repos_local[:pack].delete packed
|
230
|
+
FileUtils.rm_f(file) if File.exists?(file)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
@repos_local[:pack].each_pair do |key, value|
|
235
|
+
i += 1
|
236
|
+
localkey = "#{key}"
|
237
|
+
localkey.gsub!(/\.gz$/, "")
|
238
|
+
if @repos_local[:wd][localkey].nil?
|
239
|
+
@logger.info "Removing: #{key}"
|
240
|
+
|
241
|
+
change = true
|
242
|
+
file = pack_path(key)
|
243
|
+
@repos_local[:pack].delete key
|
220
244
|
FileUtils.rm_f(file) if File.exists?(file)
|
221
245
|
end
|
222
246
|
end
|
223
247
|
|
248
|
+
|
224
249
|
if change
|
225
250
|
@logger.info "Changes found!"
|
226
251
|
save_repos(:local)
|
@@ -282,10 +307,10 @@ module Six
|
|
282
307
|
@logger = opts[:log] if opts[:log]
|
283
308
|
|
284
309
|
case repository
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
310
|
+
when Array
|
311
|
+
config[:hosts] += repository
|
312
|
+
when String
|
313
|
+
config[:hosts] << repository
|
289
314
|
end
|
290
315
|
|
291
316
|
# TODO: Eval move to update?
|
@@ -434,67 +459,67 @@ module Six
|
|
434
459
|
|
435
460
|
if mismatch.size > 0
|
436
461
|
case typ
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
462
|
+
when :pack
|
463
|
+
# direct unpack of gz into working folder
|
464
|
+
done = false
|
465
|
+
|
466
|
+
## Pack
|
467
|
+
if online
|
468
|
+
hosts = config[:hosts].clone
|
469
|
+
host = hosts.sample unless host
|
470
|
+
b, i = false, 0
|
471
|
+
until hosts.empty? || done do
|
472
|
+
i += 1
|
473
|
+
# FIXME: Nasty
|
474
|
+
if b
|
475
|
+
host = hosts.sample
|
476
|
+
@logger.info "Trying #{i}/#{config[:hosts].size}: #{host}"
|
477
|
+
end
|
478
|
+
slist = nil
|
479
|
+
b = true
|
480
|
+
hosts -= [host]
|
481
|
+
|
482
|
+
# TODO: Progress bar
|
483
|
+
arr_opts = []
|
484
|
+
arr_opts << PARAMS
|
485
|
+
arr_opts << @rsh if host[/^(\w)*\@/]
|
486
|
+
|
487
|
+
if mismatch.size > (@repos_remote[typ].size / 2)
|
488
|
+
# Process full folder
|
489
|
+
@logger.info "Many files mismatched (#{mismatch.size}), running full update on .pack folder"
|
490
|
+
else
|
491
|
+
# Process only selective
|
492
|
+
@logger.info "Fetching #{mismatch.size} files... Please wait"
|
493
|
+
slist = File.join(TEMP_PATH, ".six-rsync_#{rand 9999}-list")
|
494
|
+
slist.gsub!("\\", "/")
|
495
|
+
File.open(slist, 'w') { |f| mismatch.each { |e| f.puts e } }
|
496
|
+
|
497
|
+
arr_opts << "--files-from=#{win2cyg("\"#{slist}\"")}"
|
498
|
+
end
|
499
|
+
|
500
|
+
begin
|
501
|
+
arr_opts << esc(File.join(host, '.pack/.'))
|
502
|
+
arr_opts << esc(pack_path)
|
503
|
+
command('', arr_opts)
|
504
|
+
|
505
|
+
done = true
|
506
|
+
rescue => e
|
507
|
+
@logger.debug "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
|
508
|
+
ensure
|
509
|
+
FileUtils.rm_f slist if slist
|
510
|
+
end
|
452
511
|
end
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
# TODO: Progress bar
|
458
|
-
arr_opts = []
|
459
|
-
arr_opts << PARAMS
|
460
|
-
arr_opts << @rsh if host[/^(\w)*\@/]
|
461
|
-
|
462
|
-
if mismatch.size > (@repos_remote[typ].size / 2)
|
463
|
-
# Process full folder
|
464
|
-
@logger.info "Many files mismatched (#{mismatch.size}), running full update on .pack folder"
|
465
|
-
else
|
466
|
-
# Process only selective
|
467
|
-
@logger.info "Fetching #{mismatch.size} files... Please wait"
|
468
|
-
slist = File.join(TEMP_PATH, ".six-rsync_#{rand 9999}-list")
|
469
|
-
slist.gsub!("\\", "/")
|
470
|
-
File.open(slist, 'w') { |f| mismatch.each { |e| f.puts e } }
|
471
|
-
|
472
|
-
arr_opts << "--files-from=#{win2cyg("\"#{slist}\"")}"
|
473
|
-
end
|
474
|
-
|
475
|
-
begin
|
476
|
-
arr_opts << esc(File.join(host, '.pack/.'))
|
477
|
-
arr_opts << esc(pack_path)
|
478
|
-
command('', arr_opts)
|
479
|
-
|
480
|
-
done = true
|
481
|
-
rescue => e
|
482
|
-
@logger.debug "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}"
|
483
|
-
ensure
|
484
|
-
FileUtils.rm_f slist if slist
|
512
|
+
unless done
|
513
|
+
@logger.warn "Exhausted all mirrors, please retry!"
|
514
|
+
raise RsyncError
|
485
515
|
end
|
486
516
|
end
|
487
|
-
|
488
|
-
|
489
|
-
|
517
|
+
when :wd
|
518
|
+
mismatch.each_with_index do |e, index|
|
519
|
+
# TODO: Nicer progress bar...
|
520
|
+
@logger.info "Unpacking #{index + 1}/#{mismatch.size}: #{e}"
|
521
|
+
unpack(:path => "#{e}.gz")
|
490
522
|
end
|
491
|
-
end
|
492
|
-
when :wd
|
493
|
-
mismatch.each_with_index do |e, index|
|
494
|
-
# TODO: Nicer progress bar...
|
495
|
-
@logger.info "Unpacking #{index + 1}/#{mismatch.size}: #{e}"
|
496
|
-
unpack(:path => "#{e}.gz")
|
497
|
-
end
|
498
523
|
end
|
499
524
|
end
|
500
525
|
|
@@ -583,12 +608,12 @@ module Six
|
|
583
608
|
@logger.debug "Calculating checksums of #{typ} files"
|
584
609
|
ar = []
|
585
610
|
reg = case typ
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
611
|
+
when :pack
|
612
|
+
ar = Dir[pack_path('**/*')]
|
613
|
+
/^[\\|\/]\.rsync[\\|\/]\.pack[\\|\/]/
|
614
|
+
when :wd
|
615
|
+
ar = Dir[File.join(@rsync_work_dir, '/**/*')]
|
616
|
+
/^[\\|\/]/
|
592
617
|
end
|
593
618
|
h = Hash.new
|
594
619
|
ar.each do |file|
|
@@ -621,12 +646,12 @@ module Six
|
|
621
646
|
def save_repos(typ = :local)
|
622
647
|
file, config = nil, nil
|
623
648
|
case typ
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
649
|
+
when :local
|
650
|
+
file = rsync_path('.repository.yml')
|
651
|
+
config = @repos_local.clone
|
652
|
+
when :remote
|
653
|
+
file = pack_path('.repository.yml')
|
654
|
+
config = @repos_remote.clone
|
630
655
|
end
|
631
656
|
config[:pack] = config[:pack].sort
|
632
657
|
config[:wd] = config[:wd].sort
|
@@ -635,10 +660,10 @@ module Six
|
|
635
660
|
|
636
661
|
def load_repos(typ)
|
637
662
|
config = case typ
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
663
|
+
when :local
|
664
|
+
YAML::load_file(rsync_path('.repository.yml'))
|
665
|
+
when :remote
|
666
|
+
YAML::load_file(pack_path('.repository.yml'))
|
642
667
|
end
|
643
668
|
|
644
669
|
[:wd, :pack].each do |t|
|
@@ -648,19 +673,19 @@ module Six
|
|
648
673
|
end
|
649
674
|
|
650
675
|
case typ
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
676
|
+
when :local
|
677
|
+
@repos_local = config
|
678
|
+
when :remote
|
679
|
+
@repos_remote = config
|
655
680
|
end
|
656
681
|
end
|
657
682
|
|
658
683
|
def del_file(file, typ, opts = {})
|
659
684
|
path = case typ
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
685
|
+
when :pack
|
686
|
+
File.join(@rsync_work_dir, DIR_PACK, file)
|
687
|
+
when :wd
|
688
|
+
File.join(@rsync_work_dir, file)
|
664
689
|
end
|
665
690
|
if File.exists?(path)
|
666
691
|
FileUtils.rm_f File.join(path)
|
@@ -760,55 +785,106 @@ module Six
|
|
760
785
|
|
761
786
|
@logger.debug(rsync_cmd) if @logger
|
762
787
|
|
763
|
-
out = chdir && (Dir.getwd != path) ? Dir.chdir(path) { run_command(rsync_cmd, &block) } : run_command(rsync_cmd, &block)
|
788
|
+
out = chdir && (Dir.getwd != path) ? Dir.chdir(path) { run_command(rsync_cmd, &block) } : run_command(rsync_cmd, &block)
|
764
789
|
out
|
765
790
|
end
|
766
791
|
|
767
792
|
def run_command(rsync_cmd, &block)
|
768
793
|
out, err = '', ''
|
769
794
|
buff = []
|
770
|
-
status = nil
|
795
|
+
#status = nil
|
796
|
+
shebang = nil
|
771
797
|
oldsync = STDOUT.sync
|
772
798
|
STDOUT.sync = true
|
799
|
+
cmd = case RUBY_PLATFORM
|
800
|
+
when /-mingw32$/, /-mswin32$/
|
801
|
+
"ruby \"#{File.join(File.dirname(__FILE__), "..", "wrapper.rb")}\" #{rsync_cmd}"
|
802
|
+
else
|
803
|
+
rsync_cmd
|
804
|
+
end
|
773
805
|
|
774
|
-
po = Open3.popen3(rsync_cmd) do |io_in, io_out, io_err, waitth|
|
806
|
+
po = IO.popen("#{cmd} 2>&1") do |io_out| #Open3.popen3(rsync_cmd) do |io_in, io_out, io_err, waitth|
|
807
|
+
#io_in.close
|
808
|
+
io_out.sync = true
|
775
809
|
io_out.each_byte do |buffer|
|
776
810
|
char = buffer.chr
|
777
811
|
buff << char
|
778
812
|
if ["\n", "\r"].include?(char)
|
779
|
-
|
780
|
-
|
781
|
-
|
813
|
+
msg = buff.join("")
|
814
|
+
|
815
|
+
case RUBY_PLATFORM
|
816
|
+
when /-mingw32$/, /-mswin32$/
|
817
|
+
if msg =~ /^SIX-SHEBANG: /
|
818
|
+
shebang = msg
|
819
|
+
else
|
820
|
+
print msg if @verbose
|
821
|
+
end
|
822
|
+
else
|
823
|
+
print msg if @verbose
|
824
|
+
end
|
825
|
+
|
826
|
+
out << msg
|
782
827
|
buff = []
|
783
828
|
end
|
784
829
|
end
|
785
830
|
|
786
|
-
io_err.each do |line|
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
end
|
794
|
-
status = waitth.value
|
831
|
+
#io_err.each do |line|
|
832
|
+
# print line
|
833
|
+
# case line
|
834
|
+
# when /max connections \((.*)\) reached/
|
835
|
+
# @logger.warn "Server reached maximum connections."
|
836
|
+
# end
|
837
|
+
# err << line
|
838
|
+
#end
|
839
|
+
#status = waitth.value
|
795
840
|
end
|
796
841
|
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
842
|
+
pid, status = nil, 1
|
843
|
+
case RUBY_PLATFORM
|
844
|
+
when /-mingw32$/, /-mswin32$/
|
845
|
+
# Handle last bits in the buffer
|
846
|
+
unless buff.empty?
|
847
|
+
msg = buff.join("")
|
848
|
+
if msg =~ /^SIX-SHEBANG: /
|
849
|
+
shebang = msg
|
850
|
+
else
|
851
|
+
print msg if @verbose
|
852
|
+
end
|
853
|
+
end
|
854
|
+
|
855
|
+
if shebang
|
856
|
+
shebang[/^SIX-SHEBANG: ([0-9]*), ([0-9]*)/]
|
857
|
+
pid, status = $1.to_i, $2.to_i
|
858
|
+
end
|
859
|
+
else
|
860
|
+
# Handle last bits in the buffer
|
861
|
+
unless buff.empty?
|
862
|
+
msg = buff.join("")
|
863
|
+
print msg if @verbose
|
864
|
+
end
|
865
|
+
pid, status = $?.pid, $?.status
|
801
866
|
end
|
802
867
|
|
803
|
-
|
868
|
+
|
869
|
+
@logger.debug "Pid: #{pid} Status: #{status}"
|
804
870
|
@logger.debug "Err: #{err}" # TODO: Throw this into the info/error log?
|
805
871
|
@logger.debug "Output: #{out}"
|
806
872
|
|
807
|
-
if status
|
808
|
-
|
809
|
-
|
873
|
+
if status > 0
|
874
|
+
case out
|
875
|
+
when /max connections \((.*)\) reached/
|
876
|
+
@logger.warn "Server reached maximum connections."
|
877
|
+
end
|
878
|
+
raise Rsync::RsyncExecuteError.new(rsync_cmd + ", [#{status}, #{pid}]" + ':' + out)
|
879
|
+
#messages << Log.new(:logsession_id => ses, :content => "Abnormal program termination. #{pid}: #{status}")
|
810
880
|
end
|
811
881
|
|
882
|
+
|
883
|
+
# if status.exitstatus > 0
|
884
|
+
#return 0 if status.exitstatus == 1 && out == ''
|
885
|
+
#raise Rsync::RsyncExecuteError.new(rsync_cmd + ':' + err + ':' + out)
|
886
|
+
#end
|
887
|
+
|
812
888
|
STDOUT.sync = false unless STDOUT.sync == oldsync
|
813
889
|
|
814
890
|
status
|
data/lib/six/rsync-app.rb
CHANGED
@@ -90,7 +90,7 @@ module Six
|
|
90
90
|
if options[:logging]
|
91
91
|
o_file = Log4r::FileOutputter.new "#{COMPONENT}-file",
|
92
92
|
'level' => 0, # All
|
93
|
-
:filename => File.join(DATA_PATH, 'logs', "#{COMPONENT}
|
93
|
+
:filename => File.join(DATA_PATH, 'logs', "#{COMPONENT}.log"),
|
94
94
|
'formatter' => format2
|
95
95
|
#:maxsize => 1024
|
96
96
|
@@log.outputters << o_file
|
data/lib/six/rsync.rb
CHANGED
data/lib/six/wrapper.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 0.6.
|
8
|
+
- 3
|
9
|
+
version: 0.6.3
|
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-09 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/six/rsync-app.rb
|
57
57
|
- lib/six/rsync-mirror.rb
|
58
58
|
- lib/six/rsync.rb
|
59
|
+
- lib/six/wrapper.rb
|
59
60
|
has_rdoc: true
|
60
61
|
homepage:
|
61
62
|
licenses: []
|