From 764c04e182dc867980aec46a3af1eb5807d8c05e Mon Sep 17 00:00:00 2001 From: Martin Molinero Date: Thu, 23 Jul 2026 15:58:13 -0300 Subject: [PATCH] Skip object store folder creation when no storage access LocalObjectStore.Initialize created the storage root directory unconditionally, before Controls were even assigned. On environments where the process lacks permission to the target path this threw an UnauthorizedAccessException even for jobs with no storage access at all. Now Controls are assigned first and the root directory is only created when StorageAccess is null or grants at least one of read/write/delete, matching the permission checks already guarding every disk operation. When access is fully denied the path is still normalized via Path.GetFullPath so later comparisons remain consistent. Co-Authored-By: Claude Opus 4.8 (1M context) --- Engine/Storage/LocalObjectStore.cs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Engine/Storage/LocalObjectStore.cs b/Engine/Storage/LocalObjectStore.cs index dafd688d0826..80690b8a7531 100644 --- a/Engine/Storage/LocalObjectStore.cs +++ b/Engine/Storage/LocalObjectStore.cs @@ -141,23 +141,33 @@ private bool IsDirty /// The algorithm mode public virtual void Initialize(int userId, int projectId, string userToken, Controls controls, AlgorithmMode algorithmMode) { - AlgorithmStorageRoot = StorageRoot(); - - // create the root path if it does not exist - var directoryInfo = FileHandler.CreateDirectory(AlgorithmStorageRoot); - // full name will return a normalized path which is later easier to compare - AlgorithmStorageRoot = directoryInfo.FullName; - Controls = controls; _algorithmMode = algorithmMode; + AlgorithmStorageRoot = StorageRoot(); + + // if the user has no storage access at all there's no point in creating the folder, which might even fail due to missing permissions + var storageAccess = Controls.StorageAccess; + if (storageAccess == null || storageAccess.Read || storageAccess.Write || storageAccess.Delete) + { + // create the root path if it does not exist + var directoryInfo = FileHandler.CreateDirectory(AlgorithmStorageRoot); + // full name will return a normalized path which is later easier to compare + AlgorithmStorageRoot = directoryInfo.FullName; + } + else + { + // no storage access so we don't create the folder, but still normalize the path so it's consistent for later comparisons + AlgorithmStorageRoot = Path.GetFullPath(AlgorithmStorageRoot); + } + // if <= 0 we disable periodic persistence and make it synchronous if (Controls.PersistenceIntervalSeconds > 0) { _persistenceTimer = new Timer(_ => Persist(), null, Controls.PersistenceIntervalSeconds * 1000, Timeout.Infinite); } - Log.Trace($"LocalObjectStore.Initialize(): Storage Root: {directoryInfo.FullName}. StorageFileCount {controls.StorageFileCount}. StorageLimit {BytesToMb(controls.StorageLimit)}MB. StoragePermissions {Controls.StorageAccess}"); + Log.Trace($"LocalObjectStore.Initialize(): Storage Root: {AlgorithmStorageRoot}. StorageFileCount {controls.StorageFileCount}. StorageLimit {BytesToMb(controls.StorageLimit)}MB. StoragePermissions {Controls.StorageAccess}"); } ///