Sha256: bfe9717cf1efcbc7cc87e543723276a7e8bb78780090d5172bff98691d469186

Contents?: true

Size: 1.07 KB

Versions: 18

Compression:

Stored size: 1.07 KB

Contents

require 'tmpdir'
module Astrails
  module Safe
    module TmpFile
      @keep_files = []

      def self.tmproot
        @tmproot ||= Dir.mktmpdir
      end

      def self.cleanup
        begin
          FileUtils.remove_entry_secure tmproot
        rescue ArgumentError => e
          if e.message =~ /parent directory is world writable/
            puts <<-ERR


********************************************************************************
It looks like you have wrong permissions on your TEMP directory.  The usual
case is when you have world writable TEMP directory withOUT the sticky bit.

Try "chmod +t" on it.

********************************************************************************

ERR
          else
            raise
          end
        end
        @tmproot = nil
      end

      def self.create(name)
        # create temp directory

        file = Tempfile.new(name, tmproot)

        yield file

        file.close
        @keep_files << file # so that it will not get gcollected and removed from filesystem until the end
        file.path
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 6 rubygems

Version Path
astrails-safe-0.2.0 lib/astrails/safe/tmp_file.rb
astrails-safe-0.2.1 lib/astrails/safe/tmp_file.rb
astrails-safe-0.2.2 lib/astrails/safe/tmp_file.rb
astrails-safe-0.2.3 lib/astrails/safe/tmp_file.rb
bostonlogic-safe-0.3.0 lib/astrails/safe/tmp_file.rb
akupchanko-astrails-safe-0.3.1 lib/astrails/safe/tmp_file.rb
astrails-safe-0.3.1 lib/astrails/safe/tmp_file.rb
astrails-safe-0.3.0 lib/astrails/safe/tmp_file.rb
netguru-safe-0.2.11 lib/astrails/safe/tmp_file.rb
netguru-safe-0.2.10 lib/astrails/safe/tmp_file.rb
netguru-safe-0.2.9 lib/astrails/safe/tmp_file.rb
darkofabijan-astrails-safe-0.2.9 lib/astrails/safe/tmp_file.rb
darkofabijan-astrails-safe-0.2.8 lib/astrails/safe/tmp_file.rb
astrails-safe-0.2.7 lib/astrails/safe/tmp_file.rb
astrails-safe-0.2.6 lib/astrails/safe/tmp_file.rb
astrails-safe-0.2.5 lib/astrails/safe/tmp_file.rb
webbynode-safe-0.2.5 lib/astrails/safe/tmp_file.rb
astrails-safe-0.2.4 lib/astrails/safe/tmp_file.rb