提交 e41a9f25 编写于 作者: B Benjamin Pasero

Copying a file from Windows explorer into same directory in VS Code removes all code (fixes #4531)

上级 70a533c0
......@@ -893,11 +893,13 @@ export class ImportFileAction extends BaseFileAction {
multiFileProgressTracker = this.progressService.show(filesArray.length);
}
// Run import in sequence to not consume too many connections
// Run import in sequence
let importPromisesFactory: ITask<TPromise<void>>[] = [];
filesArray.forEach((file) => {
importPromisesFactory.push(() => {
return this.fileService.importFile(URI.file((<any>file).path), targetElement.resource).then((result: IImportResult) => {
let sourceFile = URI.file((<any>file).path);
return this.fileService.importFile(sourceFile, targetElement.resource).then((result: IImportResult) => {
// Progress
if (multiFileProgressTracker) {
......@@ -906,9 +908,9 @@ export class ImportFileAction extends BaseFileAction {
if (result.stat) {
// Emit Deleted Event if file gets replaced
// Emit Deleted Event if file gets replaced unless it is the same file
let oldFile = targetNames[isLinux ? file.name : file.name.toLowerCase()];
if (oldFile) {
if (oldFile && oldFile.resource.fsPath !== result.stat.resource.fsPath) {
this.eventService.emit('files.internal:fileChanged', new Files.LocalFileChangeEvent(oldFile, null));
}
......
......@@ -328,6 +328,7 @@ export class FileService implements files.IFileService {
// 1.) check if target exists
return pfs.exists(targetPath).then((exists) => {
let isCaseRename = sourcePath.toLowerCase() === targetPath.toLowerCase();
let isSameFile = sourcePath === targetPath;
// Return early with conflict if target exists and we are not told to overwrite
if (exists && !isCaseRename && !overwrite) {
......@@ -350,8 +351,11 @@ export class FileService implements files.IFileService {
// 3.) make sure parents exists
return pfs.mkdirp(paths.dirname(targetPath)).then(() => {
// 4.) copy/move
if (keepCopy) {
if (isSameFile) {
return TPromise.as(null);
} else if (keepCopy) {
return nfcall(extfs.copy, sourcePath, targetPath);
} else {
return nfcall(extfs.mv, sourcePath, targetPath);
......
......@@ -181,7 +181,6 @@ suite('FileService', () => {
});
});
test('importFile', function(done: () => void) {
service.resolveFile(uri.file(path.join(testDir, 'deep'))).done(target => {
return service.importFile(uri.file(require.toUrl('./fixtures/service/index.html')), target.resource).then(res => {
......@@ -225,6 +224,16 @@ suite('FileService', () => {
});
});
test('importFile - same file', function(done: () => void) {
service.resolveFile(uri.file(path.join(testDir, 'index.html'))).done(source => {
return service.importFile(source.resource, uri.file(path.dirname(source.resource.fsPath))).then(imported => {
assert.equal(imported.stat.size, source.size);
done();
});
});
});
test('deleteFile', function(done: () => void) {
service.resolveFile(uri.file(path.join(testDir, 'deep', 'conway.js'))).done(source => {
return service.del(source.resource).then(() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册