Skip to content

Commit a46a1e4

Browse files
a-sullychromium-wpt-export-bot
authored andcommittedJun 7, 2023
FSA: Fail to create a writable if the file does not exist
DO NOT MERGE (yet) whatwg/fs#125 Currently, the createWritable() algorithm specifies that we must throw a NotFoundError if the file corresponding to the FileSystemHandle does not exist. See https://fs.spec.whatwg.org/#dom-filesystemfilehandle-createwritable Unfortunately, this does not match the behavior that has been implemented in Chrome for a very long time; specifically that - createWritable({ keepExistingData: true }) fails if the file does not exist, since there is no existing data to copy to the swap file - createWritable({ keepExistingData: false }) succeeds if the file does not exist, since there is no existing data to copy. It still fails if the parent directory does not exist, however Bug: 1405851 Change-Id: I788c5b177c188862d4b08b5dd876404522fa32d5
1 parent 97c2623 commit a46a1e4

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed
 

‎fs/script-tests/FileSystemDirectoryHandle-removeEntry.js

-12
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,3 @@ directory_test(async (t, root) => {
121121
await dir.removeEntry('file-to-remove');
122122
assert_array_equals(await getSortedDirectoryEntries(dir), ['file-to-keep']);
123123
}, 'removeEntry() of a directory while a containing file has an open writable fails');
124-
125-
directory_test(async (t, root) => {
126-
const handle =
127-
await createFileWithContents(t, 'file-to-remove', '12345', root);
128-
await root.removeEntry('file-to-remove');
129-
130-
await promise_rejects_dom(t, 'NotFoundError', cleanup_writable(t, handle.createWritable({keepExistingData: true})));
131-
132-
assert_array_equals(
133-
await getSortedDirectoryEntries(root),
134-
[]);
135-
}, 'createWritable after removeEntry succeeds but doesnt recreate the file');

‎fs/script-tests/FileSystemWritableFileStream.js

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ directory_test(async (t, root) => {
3333
await promise_rejects_dom(t, 'NotFoundError', handle.createWritable());
3434
}, 'createWritable() fails when parent directory is removed');
3535

36+
directory_test(async (t, root) => {
37+
const handle =
38+
await createFileWithContents(t, 'file_to_remove.txt', '12345', root);
39+
await root.removeEntry('file_to_remove.txt');
40+
41+
await promise_rejects_dom(
42+
t, 'NotFoundError', handle.createWritable({keepExistingData: true}));
43+
await promise_rejects_dom(
44+
t, 'NotFoundError', handle.createWritable({keepExistingData: false}));
45+
46+
assert_array_equals(await getSortedDirectoryEntries(root), []);
47+
}, 'createWritable() fails if the file does not exist');
48+
3649
directory_test(async (t, root) => {
3750
const handle = await createFileWithContents(
3851
t, 'atomic_file_is_copied.txt', 'fooks', root);

0 commit comments

Comments
 (0)
Please sign in to comment.