Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Revert "Adds a move method which won't actually work until that featu…
Browse files Browse the repository at this point in the history
…re is added to browsers whatwg/fs#10"

This reverts commit 53510cc.
  • Loading branch information
Isaiah Becker-Mayer committed Aug 1, 2022
1 parent 53510cc commit 5b9d7dd
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions packages/teleport/src/lib/tdp/sharedDirectoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class SharedDirectoryManager {
/**
* Gets the FileOrDirInfo for all the children of the directory at path.
* @throws Will throw an error if a directory has not already been initialized via add().
* @throws {PathDoesNotExistError} if the path isn't a valid path in the shared directory
* @throws {PathDoesNotExistError} if the pathstr isn't a valid path in the shared directory
*/
async listContents(path: string): Promise<FileOrDirInfo[]> {
this.checkReady();
Expand Down Expand Up @@ -119,7 +119,7 @@ export class SharedDirectoryManager {
/**
* Writes the bytes in writeData to the file at path starting at offset.
* @throws Will throw an error if a directory has not already been initialized via add().
* @throws {PathDoesNotExistError} if the path isn't a valid path in the shared directory
* @throws {PathDoesNotExistError} if the pathstr isn't a valid path in the shared directory
*/
async writeFile(
path: string,
Expand All @@ -143,29 +143,6 @@ export class SharedDirectoryManager {
return writeData.length;
}

/**
* Moves the file or directory at originalPath to newPath. It's designed to work similar to
* the Linux mv utility with no options: https://linux.die.net/man/1/mv.
* @throws Will throw an error if a directory has not already been initialized via add().
* @throws {PathDoesNotExistError} if the path isn't a valid path in the shared directory
*/
async move(originalPath: string, newPath: string): Promise<void> {
// See https://web.dev/file-system-access/#renaming-and-moving-files-and-folders
this.checkReady();

const originalFileOrDir = await this.walkPath(originalPath);

let split = newPath.split('/');
const newName = split.pop();
const newDirPath = split.join('/');
const newDir = await this.walkPath(newDirPath);
if (newDir.kind !== 'directory') {
throw new Error('cannot move a file into another file');
}

await originalFileOrDir.move(newDir, newName);
}

/**
* walkPath walks a pathstr (assumed to be in the qualified Unix format specified
* in the TDP spec), returning the FileSystemDirectoryHandle | FileSystemFileHandle
Expand Down

0 comments on commit 5b9d7dd

Please sign in to comment.