-
Notifications
You must be signed in to change notification settings - Fork 166
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
FileManager.copyItem() throws a permission error after having copied files (Ubuntu) #1125
Comments
When including resources in the package and packaging on Ubuntu, `FileManager` throws a FilePermission error. The docker daemon runs as root and files to be copied are owned by `root` while the archiver runs as the current user (`ubuntu` on EC2 Ubuntu). The `FileManager` manages to copy the files but throws an error after the copy. We suspect the `FileManager` to perform some kind of operation after the copy and it fails because of the `root` permission of the files. See #449 (comment) for a description of the problem. This PR contains code to reproduce the problem, a very simple workaround, and an integration test. The workaround consists of - trapping all errors - verify if the error is the permission error (Code = 513) - verify if the files have been copied or not - if the two above conditions are met, ignore the error, otherwise re-throw it I would rather prefer a solution that solves the root cause rather than just ignoring the error. We're still investigating the root cause (see [this thread](https://forums.swift.org/t/filemanager-copyitem-on-linux-fails-after-copying-the-files/77282) on the Swift Forum and this issue on Swift Foundation swiftlang/swift-foundation#1125
copyItem eventually calls a method that invokes fchown which tries to set ownership back to root which is not permitted. Main: swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift Lines 991 to 994 in 5ed6c72
Older: swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift Lines 968 to 973 in b0abbb4
relates to swiftlang/swift-docc#1136 and swiftlang/swift-docc-plugin#102 |
Thanks @yretenai yeah that makes sense - the reason we don't hit this on Darwin is because on Darwin we use |
When copying an entire directory where files are owned by root,
FileManager.copyItem()
throws aCocoaError.fileWriteNoPermission
after having copied the files.It works on macOS and it is reproductible on Ubuntu.
Version : Swift 6.0.3 on Ubuntu 24.04
Minimal code to reproduce
and this shell script
#!/bin/bash sudo mkdir src sudo touch src/toto ls -al src swift main.swift ls -al dst
This produces
Note that the source files have perm 0o644, they are readable by non-root users. Copying them must succeed and the target files must be owned by the user running the swift script. This is the case here, but
FileManager.copyItem()
throws an error after the copy operation.The text was updated successfully, but these errors were encountered: