Skip to content

Commit

Permalink
FSA: Fail to create a writable if the file does not exist
Browse files Browse the repository at this point in the history
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
  • Loading branch information
a-sully authored and chromium-wpt-export-bot committed Sep 29, 2023
1 parent 5e8910c commit 7695800
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 0 additions & 12 deletions fs/script-tests/FileSystemDirectoryHandle-removeEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,3 @@ directory_test(async (t, root) => {
await dir.removeEntry('file-to-remove');
assert_array_equals(await getSortedDirectoryEntries(dir), ['file-to-keep']);
}, 'removeEntry() of a directory while a containing file has an open writable fails');

directory_test(async (t, root) => {
const handle =
await createFileWithContents(t, 'file-to-remove', '12345', root);
await root.removeEntry('file-to-remove');

await promise_rejects_dom(t, 'NotFoundError', cleanup_writable(t, handle.createWritable({keepExistingData: true})));

assert_array_equals(
await getSortedDirectoryEntries(root),
[]);
}, 'createWritable after removeEntry succeeds but doesnt recreate the file');
13 changes: 13 additions & 0 deletions fs/script-tests/FileSystemWritableFileStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ directory_test(async (t, root) => {
await promise_rejects_dom(t, 'NotFoundError', handle.createWritable());
}, 'createWritable() fails when parent directory is removed');

directory_test(async (t, root) => {
const handle =
await createFileWithContents(t, 'file_to_remove.txt', '12345', root);
await root.removeEntry('file_to_remove.txt');

await promise_rejects_dom(
t, 'NotFoundError', handle.createWritable({keepExistingData: true}));
await promise_rejects_dom(
t, 'NotFoundError', handle.createWritable({keepExistingData: false}));

assert_array_equals(await getSortedDirectoryEntries(root), []);
}, 'createWritable() fails if the file does not exist');

directory_test(async (t, root) => {
const handle = await createFileWithContents(
t, 'atomic_file_is_copied.txt', 'fooks', root);
Expand Down

0 comments on commit 7695800

Please sign in to comment.