Sha256: 18d6b4bc50cd4d09b9221669bdd882a224a9079b4c8f63be9b82ec3438bb2326

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

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
          raise unless e.message.include?('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
          raise
        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

6 entries across 6 versions & 1 rubygems

Version Path
webtranslateit-safe-0.4.11 lib/web_translate_it/safe/tmp_file.rb
webtranslateit-safe-0.4.10 lib/web_translate_it/safe/tmp_file.rb
webtranslateit-safe-0.4.9 lib/web_translate_it/safe/tmp_file.rb
webtranslateit-safe-0.4.8 lib/web_translate_it/safe/tmp_file.rb
webtranslateit-safe-0.4.7 lib/web_translate_it/safe/tmp_file.rb
webtranslateit-safe-0.4.6 lib/web_translate_it/safe/tmp_file.rb