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 73
73:     def self.move(from, to, mode = 0666 - ::File.umask)
74:       FileUtils.mv(from, to)
75:       FileUtils.chmod(mode, to)
76:     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 45
45:     def self.move_safely(from, to, mode = 0666 - ::File.umask)
46:       raise ArgumentError.new("no block given") unless block_given?
47: 
48:       FileUtils.mkdir_p(::File.dirname(to))
49:       FileUtils.cp(from, to)
50:       FileUtils.chmod(mode, to)
51:       begin
52:         yield
53:         FileUtils.rm(from)
54:       rescue
55:         FileUtils.rm(to)
56:         rmdir_p(::File.dirname(to))
57:         raise $!
58:       end
59:     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 65
65:     def self.rmdir_p(directory)
66:       `rmdir -p #{Shellwords.escape(directory)} &> /dev/null`
67:     end

Public Instance Methods

checksum(algorithm = :pkzip)

      # File lib/harbor/file.rb, line 36
36:     def checksum(algorithm = :pkzip)
37:       Harbor::File::Checksum.new(:pkzip, self)
38:     end

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