Sha256: 87cee2c34df0d10388e556c86d4315388d73097638fcbdf1ec6c48d7408e7a54

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

require 'tmpdir'
module WebTranslateIt
  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

3 entries across 3 versions & 1 rubygems

Version Path
webtranslateit-safe-0.4.3 lib/webtranslateit/safe/tmp_file.rb
webtranslateit-safe-0.4.2 lib/webtranslateit/safe/tmp_file.rb
webtranslateit-safe-0.4.1 lib/webtranslateit/safe/tmp_file.rb