From f953005503cf36d8a14d8ae49fde6209aa06d04f Mon Sep 17 00:00:00 2001 From: Bart Reardon Date: Wed, 27 Mar 2024 17:41:53 +1100 Subject: [PATCH] fixes an issue where cleanup trigger was potentially being run in a context that didn't have permissions to clean up the files. --- Outset/Outset.swift | 9 ++------- Outset/Utils/FileUtils.swift | 4 ++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Outset/Outset.swift b/Outset/Outset.swift index 7522b26..dcdefc4 100644 --- a/Outset/Outset.swift +++ b/Outset/Outset.swift @@ -207,7 +207,7 @@ struct Outset: ParsableCommand { processItems(loginEveryDir) } if !folderContents(path: loginOncePrivilegedDir).isEmpty || !folderContents(path: loginEveryPrivilegedDir).isEmpty { - FileManager.default.createFile(atPath: loginPrivilegedTrigger, contents: nil) + createTrigger(loginPrivilegedTrigger) } } @@ -237,18 +237,13 @@ struct Outset: ParsableCommand { let currentUser = NSUserName() if consoleUser == currentUser { processItems(onDemandDir) + createTrigger(cleanupTrigger) } else { writeLog("User \(currentUser) is not the current console user. Skipping on-demand run.") } } else { writeLog("No current user session. Skipping on-demand run.") } - FileManager.default.createFile(atPath: cleanupTrigger, contents: nil) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - if checkFileExists(path: cleanupTrigger) { - pathCleanup(pathname: cleanupTrigger) - } - } } } diff --git a/Outset/Utils/FileUtils.swift b/Outset/Utils/FileUtils.swift index 275c391..0bd33fc 100644 --- a/Outset/Utils/FileUtils.swift +++ b/Outset/Utils/FileUtils.swift @@ -169,6 +169,10 @@ func deletePath(_ path: String) { } } +func createTrigger(_ path: String) { + FileManager.default.createFile(atPath: path, contents: nil) +} + func mountDmg(dmg: String) -> String { // Attaches dmg and returns the path let cmd = "/usr/bin/hdiutil attach -nobrowse -noverify -noautoopen \(dmg)"