Skip to content

Commit 4aa9612

Browse files
committed
test(desktop): replace the granted folder before the open, which Windows allows
1 parent 66bda4c commit 4aa9612

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎apps/desktop/src/main/win32-native-files.test.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,22 @@ describe('the Windows native file backend', () => {
135135
)
136136
})
137137

138-
it('refuses a path opened while its granted folder was replaced', async () => {
138+
it('refuses a path opened after its granted folder was replaced', async () => {
139139
await mkdir(join(root, 'docs'))
140-
const openThenReplaceRoot: Win32NativeFileSystem = {
140+
// Windows refuses to rename a folder holding an open handle, so the root is swapped before the
141+
// open; moving `docs` keeps its identity, leaving the root check as the only one that differs.
142+
const replaceRootThenOpen: Win32NativeFileSystem = {
141143
open: async (path) => {
142-
const handle = await open(path, 'r')
144+
await rename(join(root, 'docs'), join(base, 'docs-moving'))
143145
await rename(root, join(base, 'Root-before'))
144-
await mkdir(join(root, 'docs'), { recursive: true })
145-
return handle
146+
await mkdir(root)
147+
await rename(join(base, 'docs-moving'), join(root, 'docs'))
148+
return open(path, 'r')
146149
},
147150
opendir,
148151
}
149152

150-
await expect(openBeneath('docs', true, openThenReplaceRoot)).rejects.toThrow(
153+
await expect(openBeneath('docs', true, replaceRootThenOpen)).rejects.toThrow(
151154
'The approved folder changed. Request access again.'
152155
)
153156
})

0 commit comments

Comments
 (0)