Created
June 14, 2009 21:09
-
-
Save anotherjesse/129822 to your computer and use it in GitHub Desktop.
simple paranoid deletion (save to disk, upload to s3)
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
AWS::S3::Bucket.create('uso_paranoid') | |
Dir[$uso['paranoid']+'/*/*.json'].each do |fn| | |
next if File.stat(fn).ctime > Time.now() - 5 | |
key = fn[$uso['paranoid'].size+1..-1] | |
puts "sending: #{key}" | |
resp = AWS::S3::S3Object.store(key, open(fn), 'uso_paranoid', | |
:access => :private, | |
:content_type => 'text/javascript') | |
File.delete(fn) if resp.etag == Digest::MD5.hexdigest(open(fn).read) | |
end |
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
def after_destroy | |
fn = "#{$uso['paranoid']}/#{self.class.name.downcase}/#{self.id}.json" | |
File.makedirs(File.dirname(fn)) | |
File.open(fn, 'w') { |f| f.write self.attributes.to_json } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment