Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileSystemHandle::move() method #317

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions EXPLAINER.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,10 @@ const file_ref = await dir_ref.getFile('foo.js');
// Get a subdirectory.
const subdir = await dir_ref.getDirectory('bla', {create: true});

// No special API to create copies, but still possible to do so by using
// available read and write APIs.
const new_file = await dir_ref.getFile('new_name', {create: true});
const new_file_writer = await new_file.createWritable();
await new_file_writer.write(await file_ref.getFile());
await new_file_writer.close();
// Rename a file and/or move it to another directory
await file_ref.rename('new_name');
await file_ref.move(other_dir_ref);
await file_ref.move(dir_ref, 'newer_name');

// Or using streams:
a-sully marked this conversation as resolved.
Show resolved Hide resolved
const copy2 = await dir_ref.getFile('new_name', {create: true});
Expand Down
61 changes: 61 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ interface FileSystemHandle {
readonly attribute FileSystemHandleKind kind;
readonly attribute USVString name;

Promise<void> rename(USVString name);
Promise<void> move(FileSystemDirectoryHandle parent);
Promise<void> move(FileSystemDirectoryHandle parent, USVString name);
Promise<void> remove(optional FileSystemRemoveOptions options = {});

Promise<boolean> isSameEntry(FileSystemHandle other);
Expand Down Expand Up @@ -317,6 +320,64 @@ and return {{FileSystemHandleKind/"directory"}} otherwise.
The <dfn attribute for=FileSystemHandle>name</dfn> attribute must return the [=entry/name=] of the
associated [=FileSystemHandle/entry=].

### The {{FileSystemHandle/rename()}} method ### {#api-filesystemhandle-rename}

<div class="note domintro">
: await |handle| . {{FileSystemHandle/rename()|rename}}({|new_entry_name|})
:: Attempts to atomically rename the entry represented by |handle| to
|new_entry_name| in the underlying file system.

For files or directories with multiple hardlinks or symlinks, the entry
which is renamed is the entry corresponding to the path which was used
to obtain the handle.

Attempting to rename a file or directory that does not exist or passing an
invalid name will result in a promise rejection.

</div>

<div algorithm>
The <dfn method for=FileSystemHandle>rename(|new_entry_name|)</dfn> method,
when invoked, must run these steps:

1. TODO

</div>


### The {{FileSystemHandle/move()}} method ### {#api-filesystemhandle-move}

<div class="note domintro">
: await |handle| . {{FileSystemHandle/move()|move}}({|destination_directory|})
:: Attempts to move the entry represented by |handle| to |destination_directory|,
while keeping its existing name.

: await |handle| . {{FileSystemHandle/move()|move}}({|destination_directory|, |new_entry_name|})
:: Attempts to move the entry represented by |handle| to |destination_directory|,
as well as renaming to |new_entry_name|.

If |destination_directory| is on the same underlying filesystem, this move
will be atomic. Moves to non-local file systems will are not guaranteed to
be atomic and will involve duplicating data.

For files or directories with multiple hardlinks or
symlinks, the entry which is renamed is the entry corresponding to the path
which was used to obtain the handle.

Attempting to move a file or directory that does not exist or passing an
invalid name will result in a promise rejection.

</div>

<div algorithm>
The <dfn method for=FileSystemHandle>move(|destination_directory|, |new_entry_name|)</dfn> method,
when invoked, must run these steps:

1. TODO

</div>


### The {{FileSystemHandle/remove()}} method ### {#api-filesystemhandle-remove}

<div class="note domintro">
Expand Down