Harbor Documentation

Attributes

  • path [RW] (Not documented)
  • name [RW] (Not documented)

Public Class Methods

move(from, to, mode = 0666 - ::File.umask)

Moves a file and gives it the default file permissions minus the declared umask unless another mode is specified.

      # File lib/harbor/file.rb, line 69
69:     def self.move(from, to, mode = 0666 - ::File.umask)
70:       FileUtils.mv(from, to)
71:       FileUtils.chmod(mode, to)
72:     end

move_safely(from, to, mode = 0666 - ::File.umask)

The file is first copied, and then the provided block is run. If no errors occur, the source file is deleted. If an error occurs, the copied file is removed and the directory cleaned.

      # File lib/harbor/file.rb, line 41
41:     def self.move_safely(from, to, mode = 0666 - ::File.umask)
42:       raise ArgumentError.new("no block given") unless block_given?
43: 
44:       FileUtils.mkdir_p(::File.dirname(to))
45:       FileUtils.cp(from, to)
46:       FileUtils.chmod(mode, to)
47:       begin
48:         yield
49:         FileUtils.rm(from)
50:       rescue
51:         FileUtils.rm(to)
52:         rmdir_p(::File.dirname(to))
53:         raise $!
54:       end
55:     end

new(path, name = nil)

      # File lib/harbor/file.rb, line 9
 9:     def initialize(path, name = nil)
10:       @path = path
11:       @name = name || ::File.basename(@path)
12:     end

rmdir_p(directory)

Recursively delete empty directories as mkdir -p recursively creates directories.

      # File lib/harbor/file.rb, line 61
61:     def self.rmdir_p(directory)
62:       `rmdir -p #{Shellwords.escape(directory)} &> /dev/null`
63:     end

Public Instance Methods

close()

      # File lib/harbor/file.rb, line 14
14:     def close
15:       @io.close
16:     end

closed?()

      # File lib/harbor/file.rb, line 18
18:     def closed?
19:       @io.closed?
20:     end

read(block_size)

      # File lib/harbor/file.rb, line 22
22:     def read(block_size)
23:       @io ||= ::File.open(@path, "rb")
24:       @io.read(block_size)
25:     end

rewind()

      # File lib/harbor/file.rb, line 27
27:     def rewind
28:       @io ||= ::File.open(@path, "rb")
29:       @io.rewind
30:     end

size()

      # File lib/harbor/file.rb, line 32
32:     def size
33:       ::File.size(@path)
34:     end