From 6646ceda76565b0f133b90e30fc0ff0e92f76915 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 23 Dec 2021 12:52:10 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20preloaded=20site=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Domain/Integrations/Valet/Valet.swift | 35 ++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/phpmon/Domain/Integrations/Valet/Valet.swift b/phpmon/Domain/Integrations/Valet/Valet.swift index f0c1a82..d8b88c8 100644 --- a/phpmon/Domain/Integrations/Valet/Valet.swift +++ b/phpmon/Domain/Integrations/Valet/Valet.swift @@ -37,10 +37,14 @@ class Valet { } public func startPreloadingSites() { - if self.sites.count <= 10 { + let maximumPreload = 10 + let foundSites = self.countPaths() + if foundSites <= maximumPreload { // Preload the sites and their drivers - print("Fewer than or 11 sites found, preloading list of sites...") + print("Fewer than or \(maximumPreload) sites found, preloading list of sites...") self.reloadSites() + } else { + print("\(foundSites) sites found, exceeds \(maximumPreload) for preload at launch!") } } @@ -64,6 +68,19 @@ class Valet { } } + private func countPaths() -> Int { + var count = 0 + for path in config.paths { + let entries = try! FileManager.default.contentsOfDirectory(atPath: path) + for entry in entries { + if resolveSite(entry, forPath: path) { + count += 1 + } + } + } + return count + } + private func resolvePaths(tld: String) { sites = [] @@ -75,6 +92,20 @@ class Valet { } } + private func resolveSite(_ entry: String, forPath path: String) -> Bool { + let siteDir = path + "/" + entry + + let attrs = try! FileManager.default.attributesOfItem(atPath: siteDir) + + let type = attrs[FileAttributeKey.type] as! FileAttributeType + + if type == FileAttributeType.typeSymbolicLink || type == FileAttributeType.typeDirectory { + return true + } + + return false + } + private func resolvePath(_ entry: String, forPath path: String, tld: String) { let siteDir = path + "/" + entry