You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FS Journal: Handle renaming OPFS files via delete + create (instead of file.move()) (#64)
## Rationale
With this commit, objects pulled from a Git repo are correctly stored in
OPFS. Before, each object was correctly stored in MEMFS, but in OPFS it
was reflected as a 0 bytes file.
## Technical details
This commit ditches the OPFS file.move() method for renaming files.
Why?
Each object pulled from a Git repository is first buffered in a file
called ".tmp" and then renamed to its final name. However, the WRITE
operation does not store the written bytes, only the path.
By the time the filesystem journal is flushed, we cannot assume that the
"rename from" path still contains the same bytes as it did when the
WRITE operation was executed. Therefore, it's safer to delete the old
file and create a new one.
It is still possible that the new file was already deleted or renamed to
another location. That's fine. A later stage of replaying the journal
will take care of that.
Ideally, PHP.wasm would not use journaling at all, but a native WASMFS
layer for handling OPFS.
See #1878 for more
details.
## Testing instructions
Unfortunately, we don't have a unit test suite for the MEMFS<->OPFS
journaling.
Here's a manual test you can perform:
Create a new OPFS site and run this in devtools:
```php
playground.run({ code: `<?php
file_put_contents('/wordpress/test.txt', 'abc');
rename('/wordpress/test.txt', '/wordpress/test2.txt');
var_dump(file_get_contents('/wordpress/test2.txt'));
?>`}).then(t => console.log(t.text), console.log)
```
Now refresh the page and confirm the test2.txt file is not empty:
```ts
await playground.readFileAsText("/wordpress/test2.txt");
```
0 commit comments