Skip to content

Commit

Permalink
Revert "Added install state for better update of plugins (#1058)"
Browse files Browse the repository at this point in the history
This reverts commit 9cb0012.
  • Loading branch information
bajrangCoder authored Oct 28, 2024
1 parent 179ad65 commit 778da27
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 141 deletions.
43 changes: 1 addition & 42 deletions src/lib/installPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fsOperation from "fileSystem";
import JSZip from "jszip";
import Url from "utils/Url";
import constants from "./constants";
import InstallState from "./installState";
import loadPlugin from "./loadPlugin";

/**
Expand Down Expand Up @@ -71,8 +70,6 @@ export default async function installPlugin(id, name, purchaseToken) {
pluginDir = Url.join(PLUGIN_DIR, id);
}

const state = await InstallState.new(id);

if (!(await fsOperation(pluginDir).exists())) {
await fsOperation(PLUGIN_DIR).createDirectory(id);
}
Expand All @@ -84,7 +81,7 @@ export default async function installPlugin(id, name, purchaseToken) {
}

const fileUrl = Url.join(pluginDir, correctFile);
if (!state.exists(correctFile)) {
if (!(await fsOperation(fileUrl).exists())) {
await createFileRecursive(pluginDir, correctFile);
}

Expand All @@ -96,18 +93,11 @@ export default async function installPlugin(id, name, purchaseToken) {
data = JSON.stringify(pluginJson);
}

if (!(await state.isUpdated(correctFile, data))) {
return;
}

await fsOperation(fileUrl).writeFile(data);
return;
});

await Promise.all(promises);
await loadPlugin(id, true);
await state.save();
deleteRedundantFiles(pluginDir, state);
}
} catch (err) {
try {
Expand Down Expand Up @@ -149,34 +139,3 @@ async function createFileRecursive(parent, dir) {
await createFileRecursive(newParent, dir);
}
}
/**
*
* @param {string} dir
* @param {Array<string>} files
*/
async function listFileRecursive(dir, files) {
for (const child of await fsOperation(dir).lsDir()) {
const fileUrl = Url.join(dir, child.name);
if (child.isDirectory) {
await listFileRecursive(fileUrl, files);
} else {
files.push(fileUrl);
}
}
}

/**
*
* @param {Record<string, boolean>} files
*/
async function deleteRedundantFiles(pluginDir, state) {
/** @type string[] */
let files = [];
await listFileRecursive(pluginDir, files);

for (const file of files) {
if (!state.exists(file.replace(`${pluginDir}/`, ""))) {
fsOperation(file).delete();
}
}
}
99 changes: 0 additions & 99 deletions src/lib/installState.js

This file was deleted.

0 comments on commit 778da27

Please sign in to comment.