Commit 7491daac authored by Roy Marmelstein's avatar Roy Marmelstein

Easier/safer access to filePath in processed file struct

parent 065b28c2
...@@ -207,23 +207,20 @@ public class Zip { ...@@ -207,23 +207,20 @@ public class Zip {
// Get totalSize for progress handler // Get totalSize for progress handler
for path in processedPaths { for path in processedPaths {
do { do {
if let filePath = path.filePathURL.path { let filePath = path.filePath()
let fileAttributes = try fileManager.attributesOfItemAtPath(filePath) let fileAttributes = try fileManager.attributesOfItemAtPath(filePath)
let fileSize = fileAttributes[NSFileSize] as? Double let fileSize = fileAttributes[NSFileSize] as? Double
if let fileSize = fileSize { if let fileSize = fileSize {
totalSize += fileSize totalSize += fileSize
} }
} }
}
catch {} catch {}
} }
// Begin Zipping // Begin Zipping
let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE) let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE)
for path in processedPaths { for path in processedPaths {
guard let filePath = path.filePathURL.path else { let filePath = path.filePath()
throw ZipError.ZipFail
}
var isDirectory: ObjCBool = false var isDirectory: ObjCBool = false
fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory) fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory)
if !isDirectory { if !isDirectory {
......
...@@ -19,6 +19,15 @@ internal class ZipUtilities { ...@@ -19,6 +19,15 @@ internal class ZipUtilities {
internal struct ProcessedFilePath { internal struct ProcessedFilePath {
let filePathURL: NSURL let filePathURL: NSURL
let fileName: String? let fileName: String?
func filePath() -> String {
if let filePath = filePathURL.path {
return filePath
}
else {
return String()
}
}
} }
//MARK: Path processing //MARK: Path processing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment