Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignored extensions can be accidentally deleted if removeExtensions is enabled. #604

Merged
merged 4 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/service/pluginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ExtensionMetadata {
}

export class PluginService {
public static GetMissingExtensions(remoteExt: string) {
public static GetMissingExtensions(remoteExt: string, ignoredExtensions: Array<string>) {
const hashset = {};
const remoteList = ExtensionInformation.fromJSONList(remoteExt);
const localList = this.CreateExtensionList();
Expand All @@ -94,14 +94,14 @@ export class PluginService {
}

for (const ext of remoteList) {
if (hashset[ext.name] == null) {
if (hashset[ext.name] == null && ignoredExtensions.includes(ext.name) === false) {
missingList.push(ext);
}
}
return missingList;
}

public static GetDeletedExtensions(remoteList: ExtensionInformation[]) {
public static GetDeletedExtensions(remoteList: ExtensionInformation[], ignoredExtensions: Array<string>) {
const localList = this.CreateExtensionList();
const deletedList: ExtensionInformation[] = [];

Expand All @@ -127,7 +127,7 @@ export class PluginService {
let found: boolean = false;
if (ext.name !== "code-settings-sync") {
for (const localExt of remoteList) {
if (ext.name === localExt.name) {
if (ext.name == localExt.name || ignoredExtensions.includes(ext.name)) {
found = true;
break;
}
Expand Down Expand Up @@ -194,10 +194,11 @@ export class PluginService {

public static async DeleteExtensions(
extensionsJson: string,
extensionFolder: string
extensionFolder: string,
ignoredExtensions: Array<string>
): Promise<ExtensionInformation[]> {
const remoteList = ExtensionInformation.fromJSONList(extensionsJson);
const deletedList = PluginService.GetDeletedExtensions(remoteList);
const deletedList = PluginService.GetDeletedExtensions(remoteList, ignoredExtensions);
const deletedExt: ExtensionInformation[] = [];

if (deletedList.length === 0) {
Expand Down Expand Up @@ -225,11 +226,12 @@ export class PluginService {
extensions: string,
extFolder: string,
useCli: boolean,
ignoredExtensions: Array<string>,
notificationCallBack: (...data: any[]) => void
): Promise<ExtensionInformation[]> {
let actionList: Array<Promise<void>> = [];
let addedExtensions: ExtensionInformation[] = [];
const missingList = PluginService.GetMissingExtensions(extensions);
const missingList = PluginService.GetMissingExtensions(extensions, ignoredExtensions);
if (missingList.length === 0) {
notificationCallBack("Sync : No Extensions needs to be installed.");
return [];
Expand Down Expand Up @@ -297,6 +299,7 @@ export class PluginService {
console.log(err);
}
}

return addedExtensions;
}

Expand Down
17 changes: 4 additions & 13 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export class Sync {

let addedExtensions: ExtensionInformation[] = [];
let deletedExtensions: ExtensionInformation[] = [];
let ignoredExtensions: Array<string> = customSettings.ignoreExtensions || new Array<string>();
const updatedFiles: File[] = [];
const actionList: Array<Promise<void | boolean>> = [];

Expand Down Expand Up @@ -463,23 +464,12 @@ export class Sync {
if (content !== "") {
if (file.gistName === env.FILE_EXTENSION_NAME) {
if (syncSetting.syncExtensions) {
if (
customSettings.ignoreExtensions &&
customSettings.ignoreExtensions.length
) {
const extList = ExtensionInformation.fromJSONList(content);
const newExtList = extList.filter(
extension =>
!customSettings.ignoreExtensions.includes(extension.name)
);
content = JSON.stringify(newExtList);
}

if (syncSetting.removeExtensions) {
try {
deletedExtensions = await PluginService.DeleteExtensions(
content,
env.ExtensionFolder
env.ExtensionFolder,
ignoredExtensions
);
} catch (uncompletedExtensions) {
vscode.window.showErrorMessage(
Expand All @@ -504,6 +494,7 @@ export class Sync {
content,
env.ExtensionFolder,
useCli,
ignoredExtensions,
(message: string, dispose: boolean) => {
if (dispose) {
vscode.window.setStatusBarMessage(message, 2000);
Expand Down