docs: annotate safe delete and truncate operations with SAFETY comments

This commit is contained in:
yyc12345 committed 2026-10-04 10:11:48 +08:00
1 parent 8a7c6fe8d6
commit 9ea551b600
2 files changed
+8

No files matched your search

@@ -25,6 +25,9 @@ public sealed class TempDirectory : IDisposable
{ {
try try
{ {
// SAFETY: Recursive directory delete is safe: FullPath is the
// read-only, GUID-named directory this instance created under the
// OS temp folder, so it can never target user data or the temp root.
Directory.Delete(FullPath, recursive: true); Directory.Delete(FullPath, recursive: true);
} }
catch (IOException) catch (IOException)
@@ -32,6 +35,8 @@ public sealed class TempDirectory : IDisposable
Thread.Sleep(100); Thread.Sleep(100);
try try
{ {
// SAFETY: Retry of the same recursive delete, still confined to
// this instance's own temp directory.
Directory.Delete(FullPath, recursive: true); Directory.Delete(FullPath, recursive: true);
} }
catch (IOException) catch (IOException)
@@ -39,6 +39,9 @@ public sealed class WorkspaceLock : IDisposable
try try
{ {
// FileShare.None gives the exclusive semantics; FileMode.Create empties any stale file. // FileShare.None gives the exclusive semantics; FileMode.Create empties any stale file.
// SAFETY: FileMode.Create truncates a pre-existing file, but the lock
// file is empty by design and the path always comes from
// WorkspacePaths.LockFile, so no user data is ever affected.
stream = new FileStream(lockFilePath, FileMode.Create, FileAccess.Write, FileShare.None); stream = new FileStream(lockFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
} }
catch (DirectoryNotFoundException) catch (DirectoryNotFoundException)