From c3e5db3e0b607e3033d8dafb7bc30bc88729981e Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Tue, 26 Jan 2021 05:10:08 -0800 Subject: [PATCH] [FSA] Allow seeking past the end of a file Currently, we reject all attempts to write past the end of a file. This change makes the API more consistent with the behavior of POSIX. If writing at an offset past the end of a file, the null bytes between the old end of the file and the offset will count towards the file's quota. Adds Quota tests to the SandboxFSW. Bug: 1153385 Change-Id: Iec54acbccecb728f9375931825525ba2fbafd1ca --- .../FileSystemWritableFileStream-write.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/native-file-system/script-tests/FileSystemWritableFileStream-write.js b/native-file-system/script-tests/FileSystemWritableFileStream-write.js index 141a9771d2a932..ea4915a1410549 100644 --- a/native-file-system/script-tests/FileSystemWritableFileStream-write.js +++ b/native-file-system/script-tests/FileSystemWritableFileStream-write.js @@ -117,14 +117,12 @@ directory_test(async (t, root) => { const handle = await createEmptyFile(t, 'bad_offset', root); const stream = await handle.createWritable(); - await promise_rejects_dom( - t, 'InvalidStateError', stream.write({type: 'write', position: 4, data: new Blob(['abc'])})); - await promise_rejects_js( - t, TypeError, stream.close(), 'stream is already closed'); + await stream.write({type: 'write', position: 4, data: new Blob(['abc'])}); + await stream.close(); - assert_equals(await getFileContents(handle), ''); - assert_equals(await getFileSize(handle), 0); -}, 'write() called with an invalid offset'); + assert_equals(await getFileContents(handle), '\0\0\0\0abc'); + assert_equals(await getFileSize(handle), 7); +}, 'write() called with an offset beyond the end of the file'); directory_test(async (t, root) => { const handle = await createEmptyFile(t, 'empty_string', root);