From 76958001907f3e4ae581cc701fbd21b909d09010 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Fri, 29 Sep 2023 01:05:25 -0700 Subject: [PATCH] FSA: Fail to create a writable if the file does not exist DO NOT MERGE (yet) https://github.com/whatwg/fs/issues/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 --- .../FileSystemDirectoryHandle-removeEntry.js | 12 ------------ fs/script-tests/FileSystemWritableFileStream.js | 13 +++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/script-tests/FileSystemDirectoryHandle-removeEntry.js b/fs/script-tests/FileSystemDirectoryHandle-removeEntry.js index 83d8eef7900247..93b03ef6ade2b4 100644 --- a/fs/script-tests/FileSystemDirectoryHandle-removeEntry.js +++ b/fs/script-tests/FileSystemDirectoryHandle-removeEntry.js @@ -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'); diff --git a/fs/script-tests/FileSystemWritableFileStream.js b/fs/script-tests/FileSystemWritableFileStream.js index 53e4fc1f28e4ae..ad91d0dcd494fc 100644 --- a/fs/script-tests/FileSystemWritableFileStream.js +++ b/fs/script-tests/FileSystemWritableFileStream.js @@ -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);