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 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