aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-12 16:01:24 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-12 16:57:17 +0530
commit8259145f85e136592efeac2cc8eaa6486c3f809e (patch)
tree52ca0a5fccc862f4c8ac09d51ee9c56db1bfffbf /WireGuard/WireGuard/ZipArchive/ZipArchive.swift
parentSupply missing pieces of path change (diff)
downloadwireguard-apple-8259145f85e136592efeac2cc8eaa6486c3f809e.tar.xz
wireguard-apple-8259145f85e136592efeac2cc8eaa6486c3f809e.zip
Zip importing: Handle spaces in filenames correctly
Previously, if a filename of a .conf file inside the zip file contained spaces, it was not imported. Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/ZipArchive/ZipArchive.swift')
-rw-r--r--WireGuard/WireGuard/ZipArchive/ZipArchive.swift13
1 files changed, 7 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
index a849daa3..900341ec 100644
--- a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
+++ b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
@@ -39,9 +39,9 @@ class ZipArchive {
zipClose(zipFile, nil)
}
- static func unarchive(url: URL, requiredFileExtensions: [String]) throws -> [(fileName: String, contents: Data)] {
+ static func unarchive(url: URL, requiredFileExtensions: [String]) throws -> [(fileBaseName: String, contents: Data)] {
- var results: [(fileName: String, contents: Data)] = []
+ var results: [(fileBaseName: String, contents: Data)] = []
guard let zipFile = unzOpen64(url.path) else {
throw ZipArchiveError.cantOpenInputZipFile
@@ -72,10 +72,11 @@ class ZipArchive {
throw ZipArchiveError.badArchive
}
- if let fileURL = URL(string: String(cString: fileNameBuffer)),
- !fileURL.hasDirectoryPath,
- requiredFileExtensions.contains(fileURL.pathExtension) {
+ let lastChar = String(cString: fileNameBuffer).suffix(1)
+ let isDirectory = (lastChar == "/" || lastChar == "\\")
+ let fileURL = URL(fileURLWithFileSystemRepresentation: fileNameBuffer, isDirectory: isDirectory, relativeTo: nil)
+ if (!isDirectory && requiredFileExtensions.contains(fileURL.pathExtension)) {
var unzippedData = Data()
var bytesRead: Int32 = 0
repeat {
@@ -88,7 +89,7 @@ class ZipArchive {
unzippedData.append(dataRead)
}
} while (bytesRead > 0)
- results.append((fileName: fileURL.lastPathComponent, contents: unzippedData))
+ results.append((fileBaseName: fileURL.deletingPathExtension().lastPathComponent, contents: unzippedData))
}
guard (unzCloseCurrentFile(zipFile) == UNZ_OK) else {