From 1d4ef125461ddae4458c64f79941130893f735e3 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sun, 23 Jul 2023 17:17:27 -0400 Subject: [PATCH] Fix #475. (#476) --- .../Sources/SecretKit/PublicKeyStandinFileController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift b/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift index e30627a..87fe352 100644 --- a/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift +++ b/Sources/Packages/Sources/SecretKit/PublicKeyStandinFileController.swift @@ -20,8 +20,10 @@ public class PublicKeyFileStoreController { logger.log("Writing public keys to disk") if clear { let validPaths = Set(secrets.map { publicKeyPath(for: $0) }).union(Set(secrets.map { sshCertificatePath(for: $0) })) - let untracked = Set(try FileManager.default.contentsOfDirectory(atPath: directory) - .map { "\(directory)/\($0)" }) + let contentsOfDirectory = (try? FileManager.default.contentsOfDirectory(atPath: directory)) ?? [] + let fullPathContents = contentsOfDirectory.map { "\(directory)/\($0)" } + + let untracked = Set(fullPathContents) .subtracting(validPaths) for path in untracked { try? FileManager.default.removeItem(at: URL(fileURLWithPath: path))