aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/ZipArchive/ZipImporter.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/ZipImporter.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/ZipImporter.swift')
-rw-r--r--WireGuard/WireGuard/ZipArchive/ZipImporter.swift14
1 files changed, 7 insertions, 7 deletions
diff --git a/WireGuard/WireGuard/ZipArchive/ZipImporter.swift b/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
index d281fb68..6c1e3de2 100644
--- a/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
+++ b/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
@@ -17,14 +17,14 @@ enum ZipImporterError: WireGuardAppError {
class ZipImporter {
static func importConfigFiles(from url: URL, completion: @escaping (WireGuardResult<[TunnelConfiguration?]>) -> Void) {
DispatchQueue.global(qos: .userInitiated).async {
- var unarchivedFiles: [(fileName: String, contents: Data)]
+ var unarchivedFiles: [(fileBaseName: String, contents: Data)]
do {
unarchivedFiles = try ZipArchive.unarchive(url: url, requiredFileExtensions: ["conf"])
-
for (i, unarchivedFile) in unarchivedFiles.enumerated().reversed() {
- let fileBaseName = URL(string: unarchivedFile.fileName)?.deletingPathExtension().lastPathComponent
- if let trimmedName = fileBaseName?.trimmingCharacters(in: .whitespacesAndNewlines), !trimmedName.isEmpty {
- unarchivedFiles[i].fileName = trimmedName
+ let fileBaseName = unarchivedFile.fileBaseName
+ let trimmedName = fileBaseName.trimmingCharacters(in: .whitespacesAndNewlines)
+ if (!trimmedName.isEmpty) {
+ unarchivedFiles[i].fileBaseName = trimmedName
} else {
unarchivedFiles.remove(at: i)
}
@@ -40,7 +40,7 @@ class ZipImporter {
fatalError()
}
- unarchivedFiles.sort { $0.fileName < $1.fileName }
+ unarchivedFiles.sort { $0.fileBaseName < $1.fileBaseName }
var configs = Array<TunnelConfiguration?>(repeating: nil, count: unarchivedFiles.count)
for (i, file) in unarchivedFiles.enumerated() {
if (i > 0 && file == unarchivedFiles[i - 1]) {
@@ -49,7 +49,7 @@ class ZipImporter {
guard let fileContents = String(data: file.contents, encoding: .utf8) else {
continue
}
- guard let tunnelConfig = try? WgQuickConfigFileParser.parse(fileContents, name: file.fileName) else {
+ guard let tunnelConfig = try? WgQuickConfigFileParser.parse(fileContents, name: file.fileBaseName) else {
continue
}
configs[i] = tunnelConfig