@@ -52,6 +52,7 @@ module System.Directory.OsPath
5252 , copyFile
5353 , copyFileWithMetadata
5454 , getFileSize
55+ , replaceFile
5556
5657 , canonicalizePath
5758 , makeAbsolute
@@ -709,6 +710,69 @@ renamePath opath npath =
709710 (`ioeAddLocation` " renamePath" ) `modifyIOError` do
710711 renamePathInternal opath npath
711712
713+ -- | 'replaceFile' replaces one file with another file. The replacement file
714+ -- assumes the name of the replaced file and its identity.
715+ --
716+ -- This operation is atomic.
717+ --
718+ -- On the unix same as renamePath, on the Windows platform this is ReplaceFileW.
719+ --
720+ -- The operation on unix may fail with:
721+ --
722+ -- * @HardwareFault@
723+ -- A physical I\/O error has occurred.
724+ -- @[EIO]@
725+ --
726+ -- * @InvalidArgument@
727+ -- Either operand is not a valid file name.
728+ -- @[ENAMETOOLONG, ELOOP]@
729+ --
730+ -- * 'isDoesNotExistError'
731+ -- The original file does not exist, or there is no path to the target.
732+ -- @[ENOENT, ENOTDIR]@
733+ --
734+ -- * 'isPermissionError'
735+ -- The process has insufficient privileges to perform the operation.
736+ -- @[EROFS, EACCES, EPERM]@
737+ --
738+ -- * 'System.IO.isFullError'
739+ -- Insufficient resources are available to perform the operation.
740+ -- @[EDQUOT, ENOSPC, ENOMEM, EMLINK]@
741+ --
742+ -- * @UnsatisfiedConstraints@
743+ -- Implementation-dependent constraints are not satisfied.
744+ -- @[EBUSY]@
745+ --
746+ -- * @UnsupportedOperation@
747+ -- The implementation does not support renaming in this situation.
748+ -- @[EXDEV]@
749+ --
750+ -- * @InappropriateType@
751+ -- Either the destination path refers to an existing directory, or one of the
752+ -- parent segments in the destination path is not a directory.
753+ -- @[ENOTDIR, EISDIR, EINVAL, EEXIST, ENOTEMPTY]@
754+ --
755+ -- The operation on Windows may fail with:
756+ --
757+ -- ERROR_UNABLE_TO_MOVE_REPLACEMENT 1176 (0x498)
758+ -- The replacement file could not be renamed. The replaced file no longer exists
759+ -- and the replacement file exists under its original name.
760+ --
761+ -- ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 1177 (0x499)
762+ --
763+ -- The replacement file could not be moved. The replacement file still exists
764+ -- under its original name; however, it has inherited the file streams and
765+ -- attributes from the file it is replacing. The file to be replaced still
766+ -- exists with a different name.
767+ --
768+ -- ERROR_UNABLE_TO_REMOVE_REPLACED 1175 (0x497)
769+ -- The replaced file could not be deleted. The replaced and replacement files
770+ -- retain their original file names.
771+ replaceFile :: OsPath -> OsPath -> IO ()
772+ replaceFile opath npath =
773+ (`ioeAddLocation` " replaceFile" ) `modifyIOError` do
774+ replaceFileInternal opath npath Nothing
775+
712776-- | Copy a file with its permissions. If the destination file already exists,
713777-- it is replaced atomically. Neither path may refer to an existing
714778-- directory. No exceptions are thrown if the permissions could not be
0 commit comments