File: util.rb

package info (click to toggle)
ruby-raemon 0.3.0%2Bgit.2012.05.18.b78eaae57c-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 220 kB
  • ctags: 104
  • sloc: ruby: 901; makefile: 4
file content (20 lines) | stat: -rw-r--r-- 523 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Raemon
  class Util
    # Creates and returns a new File object. The File is unlinked
    # immediately, switched to binary mode, and userspace output
    # buffering is disabled. Method pulled from Unicorn library.
    def self.tmpio
      begin
        fp = File.open(File.join(Dir.tmpdir, rand.to_s),
                       File::RDWR | File::CREAT | File::EXCL, 0600)
      rescue Errno::EEXIST
        retry
      end

      File.unlink(fp.path)
      fp.binmode
      fp.sync = true
      fp
    end
  end
end