Sha256: 777542f6b70a9c9f0caff6f36788e04398103aab0a823a464fdf793b036cc614

Contents?: true

Size: 560 Bytes

Versions: 2

Compression:

Stored size: 560 Bytes

Contents

require 'zlib'

require "massive_sitemap/writer/file"
# Create Lock before writing to file

module MassiveSitemap
  module Writer

    class LockingFile < File
      OPTS = File::OPTS

      LOCK_FILE = 'generator.lock'

      def open_stream
        ::File.open(LOCK_FILE, 'w', ::File::EXCL) #lock!
        super
      end

      def close_stream(stream)
        super
        FileUtils.rm(LOCK_FILE) #unlock!
      end

      def init?
        if ::File.exists?(LOCK_FILE)
          raise Errno::EACCES
        end
        super
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
massive_sitemap-2.0.0.rc3 lib/massive_sitemap/writer/locking_file.rb
massive_sitemap-2.0.0.rc2 lib/massive_sitemap/writer/locking_file.rb