From 7491daac068f54d7368ca199066bb453316ae706 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Wed, 27 Jan 2016 06:33:36 +0100 Subject: [PATCH] Easier/safer access to filePath in processed file struct --- Zip/Zip.swift | 15 ++++++--------- Zip/ZipUtilities.swift | 9 +++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Zip/Zip.swift b/Zip/Zip.swift index c2a13e0..a74d325 100644 --- a/Zip/Zip.swift +++ b/Zip/Zip.swift @@ -207,12 +207,11 @@ public class Zip { // Get totalSize for progress handler for path in processedPaths { do { - if let filePath = path.filePathURL.path { - let fileAttributes = try fileManager.attributesOfItemAtPath(filePath) - let fileSize = fileAttributes[NSFileSize] as? Double - if let fileSize = fileSize { - totalSize += fileSize - } + let filePath = path.filePath() + let fileAttributes = try fileManager.attributesOfItemAtPath(filePath) + let fileSize = fileAttributes[NSFileSize] as? Double + if let fileSize = fileSize { + totalSize += fileSize } } catch {} @@ -221,9 +220,7 @@ public class Zip { // Begin Zipping let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE) for path in processedPaths { - guard let filePath = path.filePathURL.path else { - throw ZipError.ZipFail - } + let filePath = path.filePath() var isDirectory: ObjCBool = false fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory) if !isDirectory { diff --git a/Zip/ZipUtilities.swift b/Zip/ZipUtilities.swift index fcb7f72..dd9b0d9 100644 --- a/Zip/ZipUtilities.swift +++ b/Zip/ZipUtilities.swift @@ -19,6 +19,15 @@ internal class ZipUtilities { internal struct ProcessedFilePath { let filePathURL: NSURL let fileName: String? + + func filePath() -> String { + if let filePath = filePathURL.path { + return filePath + } + else { + return String() + } + } } //MARK: Path processing -- 2.26.2