-
-
Notifications
You must be signed in to change notification settings - Fork 333
Description
Summary
If I try to unzip a file (using the FileManager extension) to a URL which was created with a relative path, the extraction fails with an error. Using the relative URL's absoluteURL does work.
Steps to Reproduce
- Create a "relative" URL, such as:
URL(fileURLWithPath: "../../Resources", isDirectory: true). - Pass that URL as the
toparameter ofFileManager.unzipItem(along with a URL to a valid zip file).
Expected Results
The contents of the zip file is successfully extracted to the target location.
Actual Results
An error is thrown. For example, if the zip file contains a compressed directory called "media", the error is:
The item couldn’t be opened because the file name “media” is invalid.
If I get the absoluteURL of the target URL first, it does work.
Regression & Version
Tested with 0.9.12.
Findings
I think this is caused because the implementation of URL.isContained(in:) (defined in FileManager+ZIP.swift) calls standardized on the URLs first, which outputs the wrong URL when it is created with a relative path. For example:
fileManager.changeCurrentDirectoryPath("/Users/Robert/Documents")
let relativePath = "../../David/Documents"
let relativeURL = URL(fileURLWithPath: relativePath)
relativeURL.absoluteString
// file:///Users/David/Documents
relativeURL.standardized.absoluteString
// file:///Users/Robert/Documents/David/Documents