Skip to content

Commit 8216d56

Browse files
a-sullychromium-wpt-export-bot
authored andcommitted
FSA: Make removeEntry() take an exclusive lock
removeEntry() currently takes a shared lock to allow for removal of a file with an open writable. Taking an exclusive lock makes the behavior consistent with move() and remove(), the other file-altering operations. Discussed in whatwg/fs#39 TODO: link blink-dev PSA Fixed: 1254078 Change-Id: I5d471405d65f4d1920e7f0dfe9c783a4038e63e3
1 parent 5efa523 commit 8216d56

File tree

3 files changed

+29
-56
lines changed

3 files changed

+29
-56
lines changed

fs/script-tests/FileSystemDirectoryHandle-removeEntry.js

+27-3
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,35 @@ directory_test(async (t, root) => {
9393
await createFileWithContents(t, 'file-to-keep', 'abc', root);
9494

9595
const writable = await handle.createWritable();
96-
await root.removeEntry('file-to-remove');
97-
await promise_rejects_dom(t, 'NotFoundError', getFileContents(handle));
96+
await promise_rejects_dom(
97+
t, 'NoModificationAllowedError', root.removeEntry('file-to-remove'));
9898

9999
await writable.close();
100100
assert_array_equals(
101101
await getSortedDirectoryEntries(root),
102102
['file-to-keep', 'file-to-remove']);
103-
}, 'removeEntry() while the file has an open writable succeeds');
103+
104+
await root.removeEntry('file-to-remove');
105+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']);
106+
}, 'removeEntry() while the file has an open writable fails');
107+
108+
directory_test(async (t, root) => {
109+
const dir_name = 'dir-name';
110+
const dir = await createDirectory(t, dir_name, root);
111+
112+
const handle =
113+
await createFileWithContents(t, 'file-to-remove', '12345', dir);
114+
await createFileWithContents(t, 'file-to-keep', 'abc', dir);
115+
116+
const writable = await handle.createWritable();
117+
await promise_rejects_dom(
118+
t, 'NoModificationAllowedError', root.removeEntry(dir_name));
119+
120+
await writable.close();
121+
assert_array_equals(
122+
await getSortedDirectoryEntries(dir_name),
123+
['file-to-keep', 'file-to-remove']);
124+
125+
await dir.removeEntry('file-to-remove');
126+
assert_array_equals(await getSortedDirectoryEntries(dir), ['file-to-keep']);
127+
}, 'removeEntry() of a directory while a containing file has an open writable fails');

fs/script-tests/FileSystemWritableFileStream-write.js

+2-33
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,6 @@ directory_test(async (t, root) => {
192192
assert_equals(await getFileSize(handle), 3);
193193
}, 'write() with a valid typed array buffer');
194194

195-
directory_test(async (t, root) => {
196-
const dir = await createDirectory(t, 'parent_dir', root);
197-
const file_name = 'close_fails_when_dir_removed.txt';
198-
const handle = await createEmptyFile(t, file_name, dir);
199-
const stream = await handle.createWritable();
200-
await stream.write('foo');
201-
202-
await root.removeEntry('parent_dir', {recursive: true});
203-
await promise_rejects_dom(t, 'NotFoundError', stream.close());
204-
}, 'atomic writes: close() fails when parent directory is removed');
205-
206195
directory_test(async (t, root) => {
207196
const handle = await createEmptyFile(t, 'atomic_writes.txt', root);
208197
const stream = await handle.createWritable();
@@ -274,22 +263,6 @@ directory_test(async (t, root) => {
274263
assert_equals(success_count, 1);
275264
}, 'atomic writes: only one close() operation may succeed');
276265

277-
directory_test(async (t, root) => {
278-
const dir = await createDirectory(t, 'parent_dir', root);
279-
const file_name = 'atomic_writable_file_stream_persists_removed.txt';
280-
const handle = await createFileWithContents(t, file_name, 'foo', dir);
281-
282-
const stream = await handle.createWritable();
283-
await stream.write('bar');
284-
285-
await dir.removeEntry(file_name);
286-
await promise_rejects_dom(t, 'NotFoundError', getFileContents(handle));
287-
288-
await stream.close();
289-
assert_equals(await getFileContents(handle), 'bar');
290-
assert_equals(await getFileSize(handle), 3);
291-
}, 'atomic writes: writable file stream persists file on close, even if file is removed');
292-
293266
directory_test(async (t, root) => {
294267
const handle = await createEmptyFile(t, 'writer_written', root);
295268
const stream = await handle.createWritable();
@@ -314,7 +287,6 @@ directory_test(async (t, root) => {
314287

315288
await promise_rejects_dom(
316289
t, "SyntaxError", stream.write({type: 'truncate'}), 'truncate without size');
317-
318290
}, 'WriteParams: truncate missing size param');
319291

320292
directory_test(async (t, root) => {
@@ -323,7 +295,6 @@ directory_test(async (t, root) => {
323295

324296
await promise_rejects_dom(
325297
t, "SyntaxError", stream.write({type: 'write'}), 'write without data');
326-
327298
}, 'WriteParams: write missing data param');
328299

329300
directory_test(async (t, root) => {
@@ -332,17 +303,15 @@ directory_test(async (t, root) => {
332303

333304
await promise_rejects_js(
334305
t, TypeError, stream.write({type: 'write', data: null}), 'write with null data');
335-
336306
}, 'WriteParams: write null data param');
337307

338308
directory_test(async (t, root) => {
339-
const handle = await createFileWithContents(
340-
t, 'content.txt', 'seekable', root);
309+
const handle =
310+
await createFileWithContents(t, 'content.txt', 'seekable', root);
341311
const stream = await handle.createWritable();
342312

343313
await promise_rejects_dom(
344314
t, "SyntaxError", stream.write({type: 'seek'}), 'seek without position');
345-
346315
}, 'WriteParams: seek missing position param');
347316

348317
directory_test(async (t, root) => {

fs/script-tests/FileSystemWritableFileStream.js

-20
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,6 @@ directory_test(async (t, root) => {
3131
await promise_rejects_dom(t, 'NotFoundError', handle.createWritable());
3232
}, 'createWritable() fails when parent directory is removed');
3333

34-
directory_test(async (t, root) => {
35-
const dir = await createDirectory(t, 'parent_dir', root);
36-
const file_name = 'write_fails_when_dir_removed.txt';
37-
const handle = await createEmptyFile(t, file_name, dir);
38-
const stream = await handle.createWritable();
39-
40-
await root.removeEntry('parent_dir', {recursive: true});
41-
await promise_rejects_dom(t, 'NotFoundError', stream.write('foo'));
42-
}, 'write() fails when parent directory is removed');
43-
44-
directory_test(async (t, root) => {
45-
const dir = await createDirectory(t, 'parent_dir', root);
46-
const file_name = 'truncate_fails_when_dir_removed.txt';
47-
const handle = await createEmptyFile(t, file_name, dir);
48-
const stream = await handle.createWritable();
49-
50-
await root.removeEntry('parent_dir', {recursive: true});
51-
await promise_rejects_dom(t, 'NotFoundError', stream.truncate(0));
52-
}, 'truncate() fails when parent directory is removed');
53-
5434
directory_test(async (t, root) => {
5535
const handle = await createFileWithContents(
5636
t, 'atomic_file_is_copied.txt', 'fooks', root);

0 commit comments

Comments
 (0)