Created
November 22, 2010 09:59
-
-
Save antonlindstrom/709765 to your computer and use it in GitHub Desktop.
A few minutes work to check diff in directory (rsync does not exist on remote)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'find' | |
require 'digest/md5' | |
skip = [/.+\.swp$/, /ikihashfile/, /.+\.rb/] | |
scp_string = "hisiki:~/public_php/" | |
temp_file = "./ikihashfile" | |
# Hashes | |
files = Hash.new | |
cached = Array.new | |
wqueue = Hash.new | |
if ARGV.length == 0 | |
puts "Usage: #$0 [PATH]" | |
exit 1 | |
end | |
# Load physical data | |
Find.find(ARGV[0]) do |file| | |
next if File.directory?(file) | |
skip_file = false | |
skip.each { |s| skip_file = true if file =~ s } | |
next if skip_file | |
digest = Digest::MD5.hexdigest(File.open(file, "r").read) | |
files[file] = digest | |
end | |
# Temporary fix | |
files.each_pair { |k,v| wqueue[k] = v } | |
# Open files | |
f = File.open(temp_file, "rb").read | |
# Compair | |
f.split("\n").each do |i| | |
a = i.split(":") | |
hash = a.shift | |
fname = a.shift | |
next unless File.exists?(fname) | |
unless hash == files[fname] | |
path = File.dirname(fname).gsub(/^\.\/|\./, '') | |
#puts "File changed #{files[fname]} #{File.basename(fname)}" | |
system("scp #{fname} #{scp_string}/#{path}") | |
end | |
files.delete(fname) | |
end | |
# Send new data | |
files.each_pair do |k,v| | |
path = File.dirname(k).gsub(/^\.\/|^\./, '') | |
system("scp #{k} #{scp_string}/#{path}") | |
#puts "New data #{v} #{File.basename(k)}" | |
end | |
# Write all in wqueue | |
fw = File.open(temp_file, "w+") | |
wqueue.each_pair { |k,v| fw.puts "#{v}:#{k}" } | |
fw.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment