提交 66d811f8 编写于 作者: J Joao Moreno

darwin cli: delete symlink as admin

上级 82549ec7
......@@ -29,12 +29,13 @@ let _source: string = null;
function getSource(): string {
if (!_source) {
const root = URI.parse(require.toUrl('')).fsPath;
_source = path.resolve(root, '..', 'bin', 'code');
_source = path.resolve(root, '..', 'resources', 'darwin', 'bin', 'code.sh');
}
return _source;
}
function isAvailable(): TPromise<boolean> {
console.log(getSource());
return pfs.exists(getSource());
}
......@@ -70,19 +71,16 @@ class InstallAction extends Action {
if (!isAvailable || isInstalled) {
return TPromise.as(null);
} else {
const createSymlink = () => {
return pfs.unlink(this.target)
.then(null, ignore('ENOENT'))
.then(() => pfs.symlink(getSource(), this.target));
};
return createSymlink().then(null, err => {
if (err.code === 'EACCES' || err.code === 'ENOENT') {
return this.createBinFolderAndSymlink();
}
return TPromise.wrapError(err);
});
return pfs.unlink(this.target)
.then(null, ignore('ENOENT'))
.then(() => pfs.symlink(getSource(), this.target))
.then(null, err => {
if (err.code === 'EACCES' || err.code === 'ENOENT') {
return this.createBinFolderAndSymlinkAsAdmin();
}
return TPromise.wrapError(err);
});
}
})
.then(() => {
......@@ -100,7 +98,7 @@ class InstallAction extends Action {
.then(null, ignore('ENOENT', false));
}
private createBinFolderAndSymlink(): TPromise<void> {
private createBinFolderAndSymlinkAsAdmin(): TPromise<void> {
return new TPromise<void>((c, e) => {
const buttons = [nls.localize('ok', "OK"), nls.localize('cancel2', "Cancel")];
......@@ -131,7 +129,8 @@ class UninstallAction extends Action {
id: string,
label: string,
@INotificationService private notificationService: INotificationService,
@ILogService private logService: ILogService
@ILogService private logService: ILogService,
@IDialogService private dialogService: IDialogService
) {
super(id, label);
}
......@@ -148,12 +147,42 @@ class UninstallAction extends Action {
return undefined;
}
return pfs.unlink(this.target)
.then(null, ignore('ENOENT'))
.then(() => {
this.logService.trace('cli#uninstall', this.target);
this.notificationService.info(nls.localize('successFrom', "Shell command '{0}' successfully uninstalled from PATH.", product.applicationName));
});
const uninstall = () => {
return pfs.unlink(this.target)
.then(null, ignore('ENOENT'));
};
return uninstall().then(null, err => {
if (err.code === 'EACCES') {
return this.deleteSymlinkAsAdmin();
}
return TPromise.wrapError(err);
}).then(() => {
this.logService.trace('cli#uninstall', this.target);
this.notificationService.info(nls.localize('successFrom', "Shell command '{0}' successfully uninstalled from PATH.", product.applicationName));
});
});
}
private deleteSymlinkAsAdmin(): TPromise<void> {
return new TPromise<void>((c, e) => {
const buttons = [nls.localize('ok', "OK"), nls.localize('cancel2', "Cancel")];
this.dialogService.show(Severity.Info, nls.localize('warnEscalationUninstall', "Code will now prompt with 'osascript' for Administrator privileges to uninstall the shell command."), buttons, { cancelId: 1 }).then(choice => {
switch (choice) {
case 0 /* OK */:
const command = 'osascript -e "do shell script \\"rm \'' + this.target + '\'\\" with administrator privileges"';
nfcall(cp.exec, command, {})
.then(null, _ => TPromise.wrapError(new Error(nls.localize('cantUninstall', "Unable to uninstall the shell command '{0}'.", this.target))))
.done(c, e);
break;
case 1 /* Cancel */:
e(new Error(nls.localize('aborted', "Aborted")));
break;
}
});
});
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册