vscode#FileSystemError TypeScript Examples
The following examples show how to use
vscode#FileSystemError.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: path.ts From vscode-file-browser with GNU Lesser General Public License v3.0 | 6 votes |
/**
* Given a list of file names, try to find one of them in the provided path,
* then step up one folder at a time and repeat the search until we find something
* or run out of parents.
*
* If no file is found, we return [[FileSystemError.FileNotFound]].
*
* If `uri` points to a file, we immediately return [[FileSystemError.FileNotADirectory]].
*
* Returns either the [[Uri]] of the first file found, or [[None]].
*/
export async function lookUpwards(
uri: Uri,
files: string[]
): Promise<Result<Uri, FileSystemError>> {
const path = new Path(uri);
if (!(await path.isDir())) {
return Err(FileSystemError.FileNotADirectory(uri));
}
while (true) {
for (const file of files) {
let filePath = path.append(file);
if (await filePath.isFile()) {
return Ok(filePath.uri);
}
}
if (path.pop().isNone()) {
return Err(FileSystemError.FileNotFound());
}
}
}
Example #2
Source File: utopia-fs.ts From utopia with MIT License | 6 votes |
async writeFile(
uri: Uri,
content: Uint8Array,
options: { create: boolean; overwrite: boolean },
): Promise<void> {
const path = fromUtopiaURI(uri)
if (!options.create || !options.overwrite) {
const fileExists = await exists(path)
if (!fileExists && !options.create) {
throw FileSystemError.FileNotFound(uri)
} else if (fileExists && !options.overwrite) {
throw FileSystemError.FileExists(uri)
}
}
await writeFileSavedContent(path, content)
}
Example #3
Source File: utopia-fs.ts From utopia with MIT License | 6 votes |
async rename(oldUri: Uri, newUri: Uri, options: { overwrite: boolean }): Promise<void> {
const oldPath = fromUtopiaURI(oldUri)
const newPath = fromUtopiaURI(newUri)
if (!options.overwrite) {
const fileExists = await exists(newPath)
if (fileExists) {
throw FileSystemError.FileExists(newUri)
}
}
await rename(oldPath, newPath)
}
Example #4
Source File: utopia-fs.ts From utopia with MIT License | 6 votes |
async copy(source: Uri, destination: Uri, options: { overwrite: boolean }): Promise<void> {
// It's not clear where this will ever be called from, but it seems to be from the side bar
// that isn't available in Utopia, so this implementation is "just in case"
const sourcePath = fromUtopiaURI(source)
const destinationPath = fromUtopiaURI(destination)
const destinationParentDir = dirname(destinationPath)
const destinationParentDirExists = await exists(destinationParentDir)
if (!destinationParentDirExists) {
throw FileSystemError.FileNotFound(toUtopiaURI(this.projectID, destinationParentDir))
}
if (!options.overwrite) {
const destinationExists = await exists(destinationPath)
if (destinationExists && !options.overwrite) {
throw FileSystemError.FileExists(destination)
}
}
const { content, unsavedContent } = await readFile(sourcePath)
await writeFile(destinationPath, content, unsavedContent)
}
Example #5
Source File: dafnyInstallation.ts From ide-vscode with MIT License | 6 votes |
private async cleanInstallDir(): Promise<void> {
const installPath = this.getInstallationPath();
this.writeStatus(`deleting previous Dafny installation at ${installPath.fsPath}`);
try {
await workspace.fs.delete(
installPath,
{
recursive: true,
useTrash: false
}
);
} catch(error: unknown) {
if(!(error instanceof FileSystemError) || error.code !== 'FileNotFound') {
throw error;
}
}
}
Example #6
Source File: FileItem.ts From dendron with GNU Affero General Public License v3.0 | 6 votes |
public async remove(useTrash = false): Promise<FileItem> {
try {
await workspace.fs.delete(this.path, { recursive: true, useTrash });
} catch (err) {
if (useTrash === true && err instanceof FileSystemError) {
return this.remove(false);
}
throw err;
}
return this;
}