Skip to content

Commit cd52034

Browse files
Skip object store folder creation when no storage access (#9634)
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) <noreply@anthropic.com>
1 parent 0136529 commit cd52034

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

Engine/Storage/LocalObjectStore.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,33 @@ private bool IsDirty
141141
/// <param name="algorithmMode">The algorithm mode</param>
142142
public virtual void Initialize(int userId, int projectId, string userToken, Controls controls, AlgorithmMode algorithmMode)
143143
{
144-
AlgorithmStorageRoot = StorageRoot();
145-
146-
// create the root path if it does not exist
147-
var directoryInfo = FileHandler.CreateDirectory(AlgorithmStorageRoot);
148-
// full name will return a normalized path which is later easier to compare
149-
AlgorithmStorageRoot = directoryInfo.FullName;
150-
151144
Controls = controls;
152145
_algorithmMode = algorithmMode;
153146

147+
AlgorithmStorageRoot = StorageRoot();
148+
149+
// 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
150+
var storageAccess = Controls.StorageAccess;
151+
if (storageAccess == null || storageAccess.Read || storageAccess.Write || storageAccess.Delete)
152+
{
153+
// create the root path if it does not exist
154+
var directoryInfo = FileHandler.CreateDirectory(AlgorithmStorageRoot);
155+
// full name will return a normalized path which is later easier to compare
156+
AlgorithmStorageRoot = directoryInfo.FullName;
157+
}
158+
else
159+
{
160+
// no storage access so we don't create the folder, but still normalize the path so it's consistent for later comparisons
161+
AlgorithmStorageRoot = Path.GetFullPath(AlgorithmStorageRoot);
162+
}
163+
154164
// if <= 0 we disable periodic persistence and make it synchronous
155165
if (Controls.PersistenceIntervalSeconds > 0)
156166
{
157167
_persistenceTimer = new Timer(_ => Persist(), null, Controls.PersistenceIntervalSeconds * 1000, Timeout.Infinite);
158168
}
159169

160-
Log.Trace($"LocalObjectStore.Initialize(): Storage Root: {directoryInfo.FullName}. StorageFileCount {controls.StorageFileCount}. StorageLimit {BytesToMb(controls.StorageLimit)}MB. StoragePermissions {Controls.StorageAccess}");
170+
Log.Trace($"LocalObjectStore.Initialize(): Storage Root: {AlgorithmStorageRoot}. StorageFileCount {controls.StorageFileCount}. StorageLimit {BytesToMb(controls.StorageLimit)}MB. StoragePermissions {Controls.StorageAccess}");
161171
}
162172

163173
/// <summary>

0 commit comments

Comments
 (0)