未验证 提交 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 {
// 2.) resolve
return this.resolve(target).then(result => {
// Events
this._onAfterOperation.fire(new FileOperationEvent(source, keepCopy ? FileOperation.COPY : FileOperation.MOVE, result));
// Events (unless it was a no-op because paths are identical)
if (sourcePath !== targetPath) {
this._onAfterOperation.fire(new FileOperationEvent(source, keepCopy ? FileOperation.COPY : FileOperation.MOVE, 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
if (isParent(targetPath, sourcePath, !isLinux)) {
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
return pfs.exists(targetPath).then(exists => {
const isCaseRename = sourcePath.toLowerCase() === targetPath.toLowerCase();
const isSameFile = sourcePath === targetPath;
// Return early with conflict if target exists and we are not told to overwrite
if (exists && !isCaseRename && !overwrite) {
......@@ -897,14 +900,12 @@ export class FileService extends Disposable implements IFileService {
return pfs.mkdirp(paths.dirname(targetPath)).then(() => {
// 4.) copy/move
if (isSameFile) {
return null;
} else if (keepCopy) {
if (keepCopy) {
return nfcall(extfs.copy, sourcePath, targetPath);
} else {
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.
先完成此消息的编辑!
想要评论请 注册