提交 732f6661 编写于 作者: B Benjamin Pasero

fix #71160

上级 9120aceb
......@@ -12,11 +12,12 @@ import { URI } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { isLinux, isWindows } from 'vs/base/common/platform';
import { statLink, readdir, unlink, del, move, copy, readFile, writeFile, fileExists, truncate } from 'vs/base/node/pfs';
import { normalize } from 'vs/base/common/path';
import { normalize, basename, dirname } from 'vs/base/common/path';
import { joinPath } from 'vs/base/common/resources';
import { isEqual } from 'vs/base/common/extpath';
import { retry } from 'vs/base/common/async';
import { ILogService } from 'vs/platform/log/common/log';
import { localize } from 'vs/nls';
export class DiskFileSystemProvider extends Disposable implements IFileSystemProvider {
......@@ -113,9 +114,9 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
// Validate target
const exists = await fileExists(filePath);
if (exists && !opts.overwrite) {
throw createFileSystemProviderError(new Error('File already exists'), FileSystemProviderErrorCode.FileExists);
throw createFileSystemProviderError(new Error(localize('fileExists', "File already exists")), FileSystemProviderErrorCode.FileExists);
} else if (!exists && !opts.create) {
throw createFileSystemProviderError(new Error('File does not exist'), FileSystemProviderErrorCode.FileNotFound);
throw createFileSystemProviderError(new Error(localize('fileNotExists', "File does not exist")), FileSystemProviderErrorCode.FileNotFound);
}
if (exists && isWindows) {
......@@ -241,9 +242,10 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
}
async rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> {
const fromFilePath = this.toFilePath(from);
const toFilePath = this.toFilePath(to);
try {
const fromFilePath = this.toFilePath(from);
const toFilePath = this.toFilePath(to);
// Ensure target does not exist
await this.validateTargetDeleted(from, to, opts && opts.overwrite);
......@@ -251,14 +253,22 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
// Move
await move(fromFilePath, toFilePath);
} catch (error) {
// rewrite some typical errors that can happen especially around symlinks
// to something the user can better understand
if (error.code === 'EINVAL' || error.code === 'EBUSY' || error.code === 'ENAMETOOLONG') {
error = new Error(localize('moveError', "Unable to move '{0}' into '{1}' ({2}).", basename(fromFilePath), basename(dirname(toFilePath)), error.toString()));
}
throw this.toFileSystemProviderError(error);
}
}
async copy(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> {
const fromFilePath = this.toFilePath(from);
const toFilePath = this.toFilePath(to);
try {
const fromFilePath = this.toFilePath(from);
const toFilePath = this.toFilePath(to);
// Ensure target does not exist
await this.validateTargetDeleted(from, to, opts && opts.overwrite);
......@@ -266,6 +276,13 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
// Copy
await copy(fromFilePath, toFilePath);
} catch (error) {
// rewrite some typical errors that can happen especially around symlinks
// to something the user can better understand
if (error.code === 'EINVAL' || error.code === 'EBUSY' || error.code === 'ENAMETOOLONG') {
error = new Error(localize('copyError', "Unable to copy '{0}' into '{1}' ({2}).", basename(fromFilePath), basename(dirname(toFilePath)), error.toString()));
}
throw this.toFileSystemProviderError(error);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册