Skip to content

Conversation

@stepan-ulyanin
Copy link
Contributor

@stepan-ulyanin stepan-ulyanin commented Dec 30, 2025

Adds a new parameter to the NIOFS FileSystem's copyItem that allows to atomically overwrite regular files and symbolic links.

Note that I opted in to not implement the overwrite for directories in this PR as it seems that there is no atomic way to overwrite directory trees on Posix systems - do we want to do it non-atomically?

Motivation:

Per #3403 it is not uncommon to want to copy an item and not care if the copied item overwrites an existing one.

Modifications:

  1. Adds a new overwriting: Bool parameter to NIOFS FileSystem's copyItem.
  2. Implements atomic overwrite for both regular files and symbolic links.
    1. On Darwin a COPYFILE_UNLINK flag is added to copyfile(2)
    2. On Linux platforms an atomic rename is used: the source is copied to a temporary destination first and then atomically renamed, using rename(2) which overwrites an existing file or symbolic link.
  3. Adds test cases to the integration test suite.
  4. Updates the _NIOFileSystem FileSystem's copyItem for backward compatibility.

Tests

  • testCopyFileOverwritingExistingFile
  • testCopyFileOverwritingNonExistingFile
  • testCopyFileOverwritingCleansUpTempFile
  • testCopySymlinkOverwritingExistingSymlink
  • testCopySymlinkOverwritingNonExistingSymlink
  • testCopyFileOverwritingExistingSymlink
  • testCopySymlinkOverwritingExistingFile

Result:

Users will be able to copy a regular file or a symbolic link, overwriting an existing regular file or existing symbolic link.

@stepan-ulyanin stepan-ulyanin marked this pull request as ready for review December 30, 2025 06:51
@stepan-ulyanin stepan-ulyanin marked this pull request as draft December 30, 2025 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant