-
Notifications
You must be signed in to change notification settings - Fork 49
Add replaceFile #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add replaceFile #200
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ module System.Directory.OsPath | |
, copyFile | ||
, copyFileWithMetadata | ||
, getFileSize | ||
, replaceFile | ||
|
||
, canonicalizePath | ||
, makeAbsolute | ||
|
@@ -709,6 +710,69 @@ renamePath opath npath = | |
(`ioeAddLocation` "renamePath") `modifyIOError` do | ||
renamePathInternal opath npath | ||
|
||
-- | 'replaceFile' replaces one file with another file. The replacement file | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to elaborate explicitly how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added more description There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the documentation would help me much more if you add something like: "In constrast to In other words, the current explanation raises these questions with me:
|
||
-- assumes the name of the replaced file and its identity. | ||
-- | ||
-- This operation is atomic. | ||
-- | ||
-- On the unix same as renamePath, on the Windows platform this is ReplaceFileW. | ||
-- | ||
-- The operation on unix may fail with: | ||
-- | ||
-- * @HardwareFault@ | ||
-- A physical I\/O error has occurred. | ||
-- @[EIO]@ | ||
-- | ||
-- * @InvalidArgument@ | ||
-- Either operand is not a valid file name. | ||
-- @[ENAMETOOLONG, ELOOP]@ | ||
-- | ||
-- * 'isDoesNotExistError' | ||
-- The original file does not exist, or there is no path to the target. | ||
-- @[ENOENT, ENOTDIR]@ | ||
-- | ||
-- * 'isPermissionError' | ||
-- The process has insufficient privileges to perform the operation. | ||
-- @[EROFS, EACCES, EPERM]@ | ||
-- | ||
-- * 'System.IO.isFullError' | ||
-- Insufficient resources are available to perform the operation. | ||
-- @[EDQUOT, ENOSPC, ENOMEM, EMLINK]@ | ||
-- | ||
-- * @UnsatisfiedConstraints@ | ||
-- Implementation-dependent constraints are not satisfied. | ||
-- @[EBUSY]@ | ||
-- | ||
-- * @UnsupportedOperation@ | ||
-- The implementation does not support renaming in this situation. | ||
-- @[EXDEV]@ | ||
-- | ||
-- * @InappropriateType@ | ||
-- Either the destination path refers to an existing directory, or one of the | ||
-- parent segments in the destination path is not a directory. | ||
-- @[ENOTDIR, EISDIR, EINVAL, EEXIST, ENOTEMPTY]@ | ||
-- | ||
-- The operation on Windows may fail with: | ||
-- | ||
-- ERROR_UNABLE_TO_MOVE_REPLACEMENT 1176 (0x498) | ||
-- The replacement file could not be renamed. The replaced file no longer exists | ||
-- and the replacement file exists under its original name. | ||
-- | ||
-- ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 1177 (0x499) | ||
-- | ||
-- The replacement file could not be moved. The replacement file still exists | ||
-- under its original name; however, it has inherited the file streams and | ||
-- attributes from the file it is replacing. The file to be replaced still | ||
-- exists with a different name. | ||
-- | ||
-- ERROR_UNABLE_TO_REMOVE_REPLACED 1175 (0x497) | ||
-- The replaced file could not be deleted. The replaced and replacement files | ||
-- retain their original file names. | ||
replaceFile :: OsPath -> OsPath -> IO () | ||
replaceFile opath npath = | ||
(`ioeAddLocation` "replaceFile") `modifyIOError` do | ||
replaceFileInternal opath npath Nothing | ||
|
||
-- | Copy a file with its permissions. If the destination file already exists, | ||
-- it is replaced atomically. Neither path may refer to an existing | ||
-- directory. No exceptions are thrown if the permissions could not be | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the convention is to provide the same set of functions both from
System.Directory
and fromSystem.Directory.OsPath
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done