Skip to content

Commit cfbf79c

Browse files
fix(file-safety): make the DACL steps best-effort as #2016 states
The tracking issue's acceptance line says the Windows DACL is saved and restored best-effort and reported through onWarning when it cannot be done; the unit refused instead, which is what keeps review thread 4402625496 open. The save and inspect refusals and the post-commit restore throw become warnings that name the target and the failure, the dump is still kept for a manual icacls /restore, and the two DACL error classes leave with the throws that carried them. The specs follow the contract rather than the classes, and the real-filesystem case now tolerates the kept dump instead of failing on a machine where icacls /restore cannot write into a temp directory.
1 parent f0a80ce commit cfbf79c

3 files changed

Lines changed: 158 additions & 199 deletions

File tree

‎src/services/file-safety/__tests__/safeWriteText.integration.spec.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ describe("safeWriteText against a real filesystem", () => {
2626
const targetPath = path.join(dir, "target.txt")
2727
await fs.writeFile(targetPath, "old bytes")
2828

29-
// No platform override: the real platform's own durability and ACL steps run, and this
30-
// case is the successful restore. A failed restore now throws DaclRestoreError after the
31-
// commit rename has already happened (the focused unit test "win32 DACL: a failed restore
32-
// is an error and the dump is still unlinked" covers that path), so on a machine where
33-
// icacls cannot put a saved ACL back into a throwaway temp directory this publish
34-
// reports that error instead of resolving, and the residue assertions below are reached
35-
// only where the restore worked.
29+
// No platform override: the real platform's own durability and ACL steps run, and this case
30+
// is the publish that needs no repair afterwards. The DACL steps are best-effort (issue
31+
// #2016): on a machine where icacls cannot put a saved ACL back into a throwaway temp
32+
// directory the restore is a notice and the dump stays beside the target, so the only
33+
// residue this case can legitimately produce is that one dump.
3634
await safeWriteText(targetPath, "new bytes", { backup: true })
3735

3836
expect(await fs.readFile(targetPath, "utf8")).toBe("new bytes")
39-
expect(await fs.readdir(dir)).toEqual(["target.txt"])
37+
const entries = await fs.readdir(dir)
38+
const extras = entries.filter((name) => name !== "target.txt")
39+
expect(extras.every((name) => name.startsWith(".safeWriteText.acl_"))).toBe(true)
40+
expect(extras.length).toBeLessThanOrEqual(1)
4041
})
4142

4243
it("leaves the target bytes untouched when the backup copy cannot be made", async () => {

0 commit comments

Comments
 (0)