Fix prefix removal for folder paths with symlinks when copying a folder to S3 #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
(May be related to open issue: #20)
The folder argument passed to
copy(from folder: String, to s3Folder: S3Folder...
orsync(from folder: String, to s3Folder: S3Folder,...
may be non-standardized and contain symlinks. In this casetargetFiles(files: [FileDescriptor], from srcFolder: String, to destFolder: S3Folder)
may not remove the folder prefix in all cases. It's becausefileEnumerator = FileManager.default.enumerator(
inlistFiles(in folder: String)
may return file paths that are standardized and with different use of symlinks (e.g. /private/var instead of /var).Example illustrating problem:
Output:
Solution
Run the same path standardization methods on both the user supplied folder argument and the enumerated file paths. This way remove prefix will work in
targetFiles(
Side-Note
Working with file paths is difficult. Apple recommends to use URL instead of String for file paths. You should switch the API from using String to URL. In your code only convert to a path string (URL.path) when a framework method requires it. https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Articles/StandardDirectories.html