anotherjesse (owner)

Revisions

gist: 129822 Download_button fork
public
Description:
simple paranoid deletion (save to disk, upload to s3)
Public Clone URL: git://gist.github.com/129822.git
Embed All Files: show embed
paranoia.rake #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    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
 
paranoia.rb #
1
2
3
4
5
6
  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