Skip to content

Instantly share code, notes, and snippets.

@tesfabpel
Created April 22, 2015 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tesfabpel/a8fc1695f9951d787963 to your computer and use it in GitHub Desktop.
Save tesfabpel/a8fc1695f9951d787963 to your computer and use it in GitHub Desktop.
#!/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