From f1897bfb2c424f1495aecce559a0fe22643111b2 Mon Sep 17 00:00:00 2001 From: 0x00 Date: Wed, 28 Feb 2018 14:46:20 +0800 Subject: [PATCH] Update Dir.swift fix empty path bug. example: print(Dir("").exists) // true fix: print(Dir("").exists) // false --- Sources/PerfectLib/Dir.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/PerfectLib/Dir.swift b/Sources/PerfectLib/Dir.swift index e359b16e..e01f2e40 100644 --- a/Sources/PerfectLib/Dir.swift +++ b/Sources/PerfectLib/Dir.swift @@ -33,12 +33,15 @@ public struct Dir { /// Create a new Dir object with the given path public init(_ path: String) { - let pth = path.ends(with: "/") ? path : path + "/" + var pth = String() + if !path.isEmpty { + pth = path.ends(with: "/") ? path : path + "/" + } self.internalPath = File.resolveTilde(inPath: pth) } /// Returns true if the directory exists - public var exists: Bool { + public var exists: Bool { return exists(realPath) }