mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove previous package folder
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
6a10d9a379
commit
0769af0fbc
@ -14,12 +14,16 @@ const mockOpts = {
|
||||
},
|
||||
"extension-updates": {
|
||||
"file.txt": "text",
|
||||
"node-menu-0.0.1": {
|
||||
"package.json": "manifest",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe("BundledExtensionUpdater", () => {
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
it("Should download file from server", async () => {
|
||||
@ -42,4 +46,56 @@ describe("BundledExtensionUpdater", () => {
|
||||
|
||||
expect(exist).toBeTruthy();
|
||||
});
|
||||
|
||||
it.only("Should skip download if no file found on server", () => {
|
||||
mockFs(mockOpts);
|
||||
|
||||
nock("http://my-example-url.com")
|
||||
.get("/node-menu-0.0.1.tgz")
|
||||
.reply(404, { notfound: "not found" });
|
||||
|
||||
const exist = fs.existsSync("./extension-updates/node-menu-0.0.1.tgz");
|
||||
|
||||
expect(exist).toBeFalsy();
|
||||
});
|
||||
|
||||
it("Should remove previous package folder", async () => {
|
||||
mockFs(mockOpts);
|
||||
|
||||
nock("http://my-example-url.com")
|
||||
.get("/node-menu-0.0.1.tgz")
|
||||
.replyWithFile(200, `./some-user-data-directory/some-file.tgz`, {
|
||||
"Content-Type": "application/tar",
|
||||
});
|
||||
|
||||
await new BundledExtensionUpdater({
|
||||
name: "node-menu",
|
||||
version: "0.0.1",
|
||||
downloadUrl: "http://my-example-url.com/node-menu-0.0.1.tgz",
|
||||
}, "./extension-updates").update();
|
||||
|
||||
const exist = fs.existsSync("./extension-updates/node-menu-0.0.1");
|
||||
|
||||
expect(exist).toBeFalsy();
|
||||
});
|
||||
|
||||
it("Should not remove any other folders", async () => {
|
||||
mockFs(mockOpts);
|
||||
|
||||
nock("http://my-example-url.com")
|
||||
.get("/survey-0.0.1.tgz")
|
||||
.replyWithFile(200, `./some-user-data-directory/some-file.tgz`, {
|
||||
"Content-Type": "application/tar",
|
||||
});
|
||||
|
||||
await new BundledExtensionUpdater({
|
||||
name: "survey",
|
||||
version: "0.0.1",
|
||||
downloadUrl: "http://my-example-url.com/survey-0.0.1.tgz",
|
||||
}, "./extension-updates").update();
|
||||
|
||||
const exist = fs.existsSync("./extension-updates/node-menu-0.0.1");
|
||||
|
||||
expect(exist).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -27,12 +27,17 @@ export class BundledExtensionUpdater {
|
||||
|
||||
public async update() {
|
||||
await this.download();
|
||||
await this.removePreviousUpdateFolder();
|
||||
}
|
||||
|
||||
private get filePath() {
|
||||
return `${this.updateFolderPath}/${this.extension.name}-${this.extension.version}.tgz`;
|
||||
}
|
||||
|
||||
private get folderPath() {
|
||||
return `${this.updateFolderPath}/${this.extension.name}-${this.extension.version}`;
|
||||
}
|
||||
|
||||
private async download() {
|
||||
const { downloadUrl, name } = this.extension;
|
||||
|
||||
@ -69,4 +74,15 @@ export class BundledExtensionUpdater {
|
||||
stream.pipe(file);
|
||||
});
|
||||
}
|
||||
|
||||
private async removePreviousUpdateFolder() {
|
||||
if (fs.existsSync(this.folderPath)) {
|
||||
return fs.rm(this.folderPath, { recursive: true, force: true }, (err) => {
|
||||
if (err) {
|
||||
throw new Error(err.message);
|
||||
}
|
||||
logger.info(`[EXTENSION-UPDATER]: Previous update folder '${this.folderPath}' deleted.`);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user