提交 54108a54 编写于 作者: D Daniel Imms

Use unique backup path for file and untitled schemes

上级 08fad0bb
......@@ -453,24 +453,20 @@ export class FileService implements IFileService {
}
public backupFile(resource: uri, content: string): TPromise<IFileStat> {
// TODO: Implement properly
const backupName = paths.basename(resource.fsPath);
const backupPath = paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID, backupName);
const backupResource = uri.file(backupPath);
if (resource.scheme === 'file') {
// TODO: Persist hash -> file map on disk (json file?)
}
const backupResource = this.getBackupPath(resource);
console.log(`Backing up to ${backupResource.fsPath}`);
return this.updateContent(backupResource, content);
}
public discardBackup(resource: uri): TPromise<void> {
const backupName = paths.basename(resource.fsPath);
const backupPath = paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID, backupName);
const backupResource = uri.file(backupPath);
return this.del(backupResource);
return this.del(this.getBackupPath(resource));
}
public discardBackups(): TPromise<void> {
return this.del(uri.file(paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID)));
return this.del(uri.file(this.getBackupRoot()));
}
public isHotExitEnabled(): boolean {
......@@ -479,6 +475,16 @@ export class FileService implements IFileService {
// Helpers
private getBackupPath(resource: uri): uri {
const backupName = crypto.createHash('md5').update(resource.fsPath).digest('hex');
const backupPath = paths.join(this.getBackupRoot(), resource.scheme, backupName);
return uri.file(backupPath);
}
private getBackupRoot(): string {
return paths.join(this.environmentService.userDataPath, 'Backups', FileService.SESSION_BACKUP_ID);
}
private toAbsolutePath(arg1: uri | IFileStat): string {
let resource: uri;
if (arg1 instanceof uri) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册