Harbor::File
Attributes
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
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
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