提交 6aec1e72 编写于 作者: D Daniel Imms

Merge remove workspace funcs to removeBackupPathSync

上级 8ba5d115
......@@ -71,28 +71,16 @@ export class BackupMainService implements IBackupMainService {
}
}
protected removeWorkspaceBackupPathSync(workspace: Uri): void {
if (!this.backups.folderWorkspaces) {
return;
}
const index = this.backups.folderWorkspaces.indexOf(workspace.fsPath);
if (index === -1) {
return;
}
this.backups.folderWorkspaces.splice(index, 1);
this.saveSync();
}
// TODO: Test
private removeEmptyWorkspaceBackupFolder(backupFolder: string): void {
if (!this.backups.emptyWorkspaces) {
protected removeBackupPathSync(workspaceIdentifier: string, isEmptyWorkspace: boolean): void {
const array = isEmptyWorkspace ? this.backups.emptyWorkspaces : this.backups.folderWorkspaces;
if (!array) {
return;
}
const index = this.backups.emptyWorkspaces.indexOf(backupFolder);
const index = array.indexOf(workspaceIdentifier);
if (index === -1) {
return;
}
this.backups.emptyWorkspaces.splice(index, 1);
array.splice(index, 1);
this.saveSync();
}
......@@ -135,10 +123,9 @@ export class BackupMainService implements IBackupMainService {
backups.folderWorkspaces.forEach(workspacePath => {
const backupPath = path.join(this.backupHome, this.getWorkspaceHash(workspacePath));
console.log('this.hasBackupsSync(backupPath) for ' + workspacePath + ' : ' + this.hasBackupsSync(backupPath));
if (!this.hasBackupsSync(backupPath)) {
const backupWorkspace = this.sanitizePath(workspacePath);
staleBackupWorkspaces.push({ workspaceIdentifier: backupWorkspace, backupPath, isEmptyWorkspace: false });
staleBackupWorkspaces.push({ workspaceIdentifier: Uri.file(backupWorkspace).fsPath, backupPath, isEmptyWorkspace: false });
}
});
......@@ -152,11 +139,7 @@ export class BackupMainService implements IBackupMainService {
staleBackupWorkspaces.forEach(staleBackupWorkspace => {
const {backupPath, workspaceIdentifier, isEmptyWorkspace} = staleBackupWorkspace;
extfs.delSync(backupPath);
if (isEmptyWorkspace) {
this.removeEmptyWorkspaceBackupFolder(workspaceIdentifier);
} else {
this.removeWorkspaceBackupPathSync(Uri.file(workspaceIdentifier));
}
this.removeBackupPathSync(workspaceIdentifier, isEmptyWorkspace);
});
}
......
......@@ -28,8 +28,8 @@ class TestBackupMainService extends BackupMainService {
this.loadSync();
}
public removeWorkspaceBackupPathSync(workspace: Uri): void {
return super.removeWorkspaceBackupPathSync(workspace);
public removeBackupPathSync(workspaceIdenfitier: string, isEmptyWorkspace: boolean): void {
return super.removeBackupPathSync(workspaceIdenfitier, isEmptyWorkspace);
}
public loadSync(): void {
......@@ -204,15 +204,15 @@ suite('BackupMainService', () => {
});
});
suite('removeWorkspaceBackupPathSync', () => {
test('removeWorkspaceBackupPathSync should remove workspaces from workspaces.json', done => {
suite('removeBackupPathSync', () => {
test('should remove workspaces from workspaces.json', done => {
service.registerWindowForBackups(1, false, null, fooFile.fsPath);
service.registerWindowForBackups(2, false, null, barFile.fsPath);
service.removeWorkspaceBackupPathSync(fooFile);
service.removeBackupPathSync(fooFile.fsPath, false);
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
assert.deepEqual(json.folderWorkspaces, [barFile.fsPath]);
service.removeWorkspaceBackupPathSync(barFile);
service.removeBackupPathSync(barFile.fsPath, false);
pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
const json2 = <IBackupWorkspacesFormat>JSON.parse(content);
assert.deepEqual(json2.folderWorkspaces, []);
......@@ -221,10 +221,10 @@ suite('BackupMainService', () => {
});
});
test('removeWorkspaceBackupPathSync should fail gracefully when removing a path that doesn\'t exist', done => {
test('should fail gracefully when removing a path that doesn\'t exist', done => {
const workspacesJson: IBackupWorkspacesFormat = { folderWorkspaces: [fooFile.fsPath], emptyWorkspaces: [] };
pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson)).then(() => {
service.removeWorkspaceBackupPathSync(barFile);
service.removeBackupPathSync(barFile.fsPath, false);
pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
const json = <IBackupWorkspacesFormat>JSON.parse(content);
assert.deepEqual(json.folderWorkspaces, [fooFile.fsPath]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册