| Summary: | Data written via FileSystemSyncAccessHandle disappears after creating new FileSystemFileHandle | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Alex Titarenko <03_placid_daft> |
| Component: | Website Storage | Assignee: | Sihui Liu <sihui_liu> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | karlcow, sihui_liu, webkit-bug-importer |
| Priority: | P2 | Keywords: | BrowserCompat, InRadar |
| Version: | Safari 16 | ||
| Hardware: | All | ||
| OS: | Unspecified | ||
|
Description
Alex Titarenko
2023-01-11 19:57:04 PST
More clear information on how to reproduce: In file: https://github.com/WebKit/WebKit/blob/main/LayoutTests/storage/filesystemaccess/resources/file-handle-getfile.js replace test function with: ``` async function test() { try { var rootHandle = await navigator.storage.getDirectory(); // Create a new file for this test. await rootHandle.removeEntry("file-handle-getfile.txt").then(() => { }, () => { }); fileHandle = await rootHandle.getFileHandle("file-handle-getfile.txt", { "create" : true }); fileContent = ""; // Write file content in worker. if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { console.log('hello from WebWorker') accessHandle = await fileHandle.createSyncAccessHandle(); const encoder = new TextEncoder(); fileContent = "This is a test."; writeBuffer = encoder.encode(fileContent); writeSize = accessHandle.write(writeBuffer, { "at" : 0 }); shouldBe("writeSize", "writeBuffer.byteLength"); accessHandle.flush(); // This is a new line accessHandle.close(); } fileHandle = await rootHandle.getFileHandle("file-handle-getfile.txt"); // This is a new line fileObject = await fileHandle.getFile(); readText = await read(fileObject); shouldBe("readText", "fileContent"); finishTest(); } catch (error) { finishTest(error.toString()); } } ``` Then run LayoutTest: https://github.com/WebKit/WebKit/blob/main/LayoutTests/storage/filesystemaccess/file-handle-getfile-worker.html (In reply to Alex Titarenko from comment #1) > More clear information on how to reproduce: > > In file: > https://github.com/WebKit/WebKit/blob/main/LayoutTests/storage/ > filesystemaccess/resources/file-handle-getfile.js > > replace test function with: > > ``` > async function test() > { > try { > var rootHandle = await navigator.storage.getDirectory(); > // Create a new file for this test. > await rootHandle.removeEntry("file-handle-getfile.txt").then(() => { > }, () => { }); > fileHandle = await > rootHandle.getFileHandle("file-handle-getfile.txt", { "create" : true }); > fileContent = ""; > > // Write file content in worker. > if (typeof WorkerGlobalScope !== 'undefined' && self instanceof > WorkerGlobalScope) { > console.log('hello from WebWorker') > accessHandle = await fileHandle.createSyncAccessHandle(); > const encoder = new TextEncoder(); > fileContent = "This is a test."; > writeBuffer = encoder.encode(fileContent); > writeSize = accessHandle.write(writeBuffer, { "at" : 0 }); > shouldBe("writeSize", "writeBuffer.byteLength"); > accessHandle.flush(); // This is a new line > accessHandle.close(); > } > > fileHandle = await > rootHandle.getFileHandle("file-handle-getfile.txt"); // This is a new line > fileObject = await fileHandle.getFile(); > readText = await read(fileObject); > shouldBe("readText", "fileContent"); > > finishTest(); > } catch (error) { > finishTest(error.toString()); > } > } > ``` > > Then run LayoutTest: > https://github.com/WebKit/WebKit/blob/main/LayoutTests/storage/ > filesystemaccess/file-handle-getfile-worker.html (In reply to Alex Titarenko from comment #1) > More clear information on how to reproduce: > > In file: > https://github.com/WebKit/WebKit/blob/main/LayoutTests/storage/ > filesystemaccess/resources/file-handle-getfile.js > > replace test function with: > > ``` > async function test() > { > try { > var rootHandle = await navigator.storage.getDirectory(); > // Create a new file for this test. > await rootHandle.removeEntry("file-handle-getfile.txt").then(() => { > }, () => { }); > fileHandle = await > rootHandle.getFileHandle("file-handle-getfile.txt", { "create" : true }); > fileContent = ""; > > // Write file content in worker. > if (typeof WorkerGlobalScope !== 'undefined' && self instanceof > WorkerGlobalScope) { > console.log('hello from WebWorker') > accessHandle = await fileHandle.createSyncAccessHandle(); > const encoder = new TextEncoder(); > fileContent = "This is a test."; > writeBuffer = encoder.encode(fileContent); > writeSize = accessHandle.write(writeBuffer, { "at" : 0 }); > shouldBe("writeSize", "writeBuffer.byteLength"); > accessHandle.flush(); // This is a new line > accessHandle.close(); > } > > fileHandle = await > rootHandle.getFileHandle("file-handle-getfile.txt"); // This is a new line > fileObject = await fileHandle.getFile(); > readText = await read(fileObject); > shouldBe("readText", "fileContent"); > > finishTest(); > } catch (error) { > finishTest(error.toString()); > } > } > ``` > > Then run LayoutTest: > https://github.com/WebKit/WebKit/blob/main/LayoutTests/storage/ > filesystemaccess/file-handle-getfile-worker.html Thanks for the report. I think it's caused by file being truncated unexpectedly on FileSystemHandle creation. Will make a fix. Pull request: https://github.com/WebKit/WebKit/pull/8586 Committed 258876@main (60a6090b4106): <https://commits.webkit.org/258876@main> Reviewed commits have been landed. Closing PR #8586 and removing active labels. |