未验证 提交 555727f1 编写于 作者: I Isidor Nikolic 提交者: GitHub

Merge pull request #67738 from Microsoft/fix-67734

files - let copy/move of same file path be a no-op
...@@ -856,25 +856,28 @@ export class FileService extends Disposable implements IFileService { ...@@ -856,25 +856,28 @@ export class FileService extends Disposable implements IFileService {
// 2.) resolve // 2.) resolve
return this.resolve(target).then(result => { return this.resolve(target).then(result => {
// Events // Events (unless it was a no-op because paths are identical)
this._onAfterOperation.fire(new FileOperationEvent(source, keepCopy ? FileOperation.COPY : FileOperation.MOVE, result)); if (sourcePath !== targetPath) {
this._onAfterOperation.fire(new FileOperationEvent(source, keepCopy ? FileOperation.COPY : FileOperation.MOVE, result));
}
return result; return result;
}); });
}); });
} }
private doMoveOrCopyFile(sourcePath: string, targetPath: string, keepCopy: boolean, overwrite: boolean): Promise<boolean /* exists */> { private doMoveOrCopyFile(sourcePath: string, targetPath: string, keepCopy: boolean, overwrite: boolean): Promise<void> {
// 1.) validate operation // 1.) validate operation
if (isParent(targetPath, sourcePath, !isLinux)) { if (isParent(targetPath, sourcePath, !isLinux)) {
return Promise.reject(new Error('Unable to move/copy when source path is parent of target path')); return Promise.reject(new Error('Unable to move/copy when source path is parent of target path'));
} else if (sourcePath === targetPath) {
return Promise.resolve(); // no-op but not an error
} }
// 2.) check if target exists // 2.) check if target exists
return pfs.exists(targetPath).then(exists => { return pfs.exists(targetPath).then(exists => {
const isCaseRename = sourcePath.toLowerCase() === targetPath.toLowerCase(); const isCaseRename = sourcePath.toLowerCase() === targetPath.toLowerCase();
const isSameFile = sourcePath === targetPath;
// Return early with conflict if target exists and we are not told to overwrite // Return early with conflict if target exists and we are not told to overwrite
if (exists && !isCaseRename && !overwrite) { if (exists && !isCaseRename && !overwrite) {
...@@ -897,14 +900,12 @@ export class FileService extends Disposable implements IFileService { ...@@ -897,14 +900,12 @@ export class FileService extends Disposable implements IFileService {
return pfs.mkdirp(paths.dirname(targetPath)).then(() => { return pfs.mkdirp(paths.dirname(targetPath)).then(() => {
// 4.) copy/move // 4.) copy/move
if (isSameFile) { if (keepCopy) {
return null;
} else if (keepCopy) {
return nfcall(extfs.copy, sourcePath, targetPath); return nfcall(extfs.copy, sourcePath, targetPath);
} else { } else {
return nfcall(extfs.mv, sourcePath, targetPath); return nfcall(extfs.mv, sourcePath, targetPath);
} }
}).then(() => exists); });
}); });
}); });
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册