whatwg / fs

File System Standard
https://fs.spec.whatwg.org/
Other
224 stars 19 forks source link

Add a `FileSystemHandle.create()` method to create self #126

Open a-sully opened 1 year ago

a-sully commented 1 year ago

This idea has been discussed previously by both myself (https://github.com/whatwg/fs/issues/39#issuecomment-1377694349) and @szewai (https://github.com/whatwg/fs/issues/59#issuecomment-1404676261)

96 clarified that a FileSystemHandle maps to a file path - and therefore if the underlying file is removed, the FileSystemHandle itself is not changed (clarifying #39). Given the recent (though #9 is still blocked) addition of a remove() method (to remove self), it seems reasonable to allow "create self"

Currently, "create self" is possible on Chromium browsers via the createWritable() method due to an implementation quirk. See #125 for more details. An explicit create() method would allow for more common-sense behavior of the createWritable() method without removing a capability (i.e. "create self" - specifically when the parent directory is not accessible) that some use cases may rely on.

The specific shape of this API still needs more thought (e.g. it would be nice if this could play nicely with an exists() method, as proposed in #80, such that the "create if not exists" use case is less vulnerable to TOCTOU errors) but putting this out there in case anyone has comments or wants to put forward a proposal :)