Created
April 22, 2015 11:51
-
-
Save tesfabpel/a8fc1695f9951d787963 to your computer and use it in GitHub Desktop.
This file contains 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 'shellwords' | |
$LAST_MOD_FILE = 'GDRIVE_SYNC_LAST_MOD' | |
# date "+%s" | |
$LAST_MOD = Time.at 0 | |
# Find the last modification time | |
if File.exists? $LAST_MOD_FILE | |
s = File.read($LAST_MOD_FILE).chomp | |
time = s.to_i | |
$LAST_MOD = Time.at time | |
end | |
begin | |
# Find files modified after time | |
pwd = Dir.pwd | |
entries = Dir.glob "**/*" | |
entries.each do |fn| | |
next if fn == $LAST_MOD_FILE | |
stat = File.stat fn | |
if stat.mtime > $LAST_MOD | |
#fnsh = fn.shellescape # NOT NEEDED! | |
ok = system "drive", "upload", "--file", fn | |
raise "ERR" unless ok | |
end | |
end | |
File.open($LAST_MOD_FILE, "w") { |f| | |
f.puts Time.now.to_i | |
} | |
rescue RuntimeError => ex | |
puts "ERROR!!!" if ex.message == "ERR" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment