Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Created June 14, 2009 21:09
Show Gist options
  • Save anotherjesse/129822 to your computer and use it in GitHub Desktop.
Save anotherjesse/129822 to your computer and use it in GitHub Desktop.
simple paranoid deletion (save to disk, upload to s3)
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
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