From ce50ddaff6caa552e362ed66f2a89be7e7b296fa Mon Sep 17 00:00:00 2001 From: Khoa Pham Date: Tue, 12 Sep 2017 15:46:55 +0200 Subject: [PATCH] Always create sub folder based on name --- Source/Shared/Storage/DiskStorage.swift | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Source/Shared/Storage/DiskStorage.swift b/Source/Shared/Storage/DiskStorage.swift index e183b85..0f0e227 100644 --- a/Source/Shared/Storage/DiskStorage.swift +++ b/Source/Shared/Storage/DiskStorage.swift @@ -22,16 +22,17 @@ final class DiskStorage { self.config = config self.fileManager = fileManager + let url: URL if let directory = config.directory { - self.path = directory.absoluteString + url = directory } else { - let url = try fileManager.url( + url = try fileManager.url( for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true ) - - path = url.appendingPathComponent(config.name, isDirectory: true).path - try createDirectory() } + + path = url.appendingPathComponent(config.name, isDirectory: true).path + try createDirectory() } } @@ -172,9 +173,12 @@ extension DiskStorage { } func createDirectory() throws { - if !fileManager.fileExists(atPath: path) { - try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil) + guard !fileManager.fileExists(atPath: path) else { + return } + + try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, + attributes: nil) } /**