Method: Pathname#copy_into
- Defined in:
- lib/pleasant_path/pathname.rb
#copy_into(directory) ⇒ Pathname #copy_into(directory) {|source, destination| ... } ⇒ Pathname
Copies the file or directory indicated by the Pathname into directory
, replacing any existing file or directory of the same basename.
If a block is given and a file or directory does exist at the resultant destination, the block is called with the source and destination Pathnames, and the return value of the block is used as the new destination. If the block returns the source Pathname or nil, the copy is aborted.
Creates any necessary parent directories of the destination. Returns the destination as a Pathname (or the source Pathname in the case that the copy is aborted).
WARNING: Due to system API limitations, the copy is performed in two steps, non-atomically. First, any file or directory existing at the destination is deleted. Next, the source is copied to the destination. The second step can fail independently of the first, e.g. due to insufficient disk space, leaving the file or directory previously at the destination deleted without replacement.
782 783 784 |
# File 'lib/pleasant_path/pathname.rb', line 782 def copy_into(directory, &block) self.copy_as(directory / self.basename, &block) end |