Skip to content

Commit

Permalink
switch to adm-zip and use rimraf to delete old serve-d installation
Browse files Browse the repository at this point in the history
fix #175
  • Loading branch information
WebFreak001 committed Apr 10, 2018
1 parent a43c766 commit 9117dc1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 133 deletions.
122 changes: 14 additions & 108 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,15 @@
"request": "^2.85.0",
"request-progress": "^3.0.0",
"jsonc-parser": "^1.0.3",
"unzip": "^0.1.11",
"adm-zip": "^0.4.7",
"async": "^2.6.0",
"ncp": "^2.0.0",
"rmdir": "^1.2.0",
"line-by-line": "^0.1.6",
"vscode-languageclient": "^4.1.3",
"mkdirp": "^0.5.1",
"opn": "^5.3.0"
"opn": "^5.3.0",
"rimraf": "^2.6.2"
},
"devDependencies": {
"typescript": "^2.8.1",
Expand Down
45 changes: 22 additions & 23 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import * as fs from "fs"
import { req } from "./util"
import { config } from "./extension"
import { platform } from "os";
var unzip = require("unzip");
var rimraf = require("rimraf");
var AdmZip = require("adm-zip");
var progress = require("request-progress");
var async = require("async");
var rmdir = require("rmdir");
Expand Down Expand Up @@ -95,15 +96,14 @@ export function downloadDub(env: any, done: Function) {
}).pipe(fs.createWriteStream(outputPath)).on("finish", () => {
installationLog.appendLine("Extracting dub");
if (ext == ".zip") {
fs.createReadStream(outputPath).pipe(unzip.Extract({ path: outputFolder })).on("finish", () => {
config().update("dubPath", finalDestination, true);
installationLog.appendLine("Deleting " + outputPath);
fs.unlink(outputPath, (err) => {
if (err)
installationLog.appendLine("Failed to delete " + outputPath);
});
done(true);
new AdmZip(outputPath).extractAllTo(outputFolder);
config().update("dubPath", finalDestination, true);
installationLog.appendLine("Deleting " + outputPath);
fs.unlink(outputPath, (err) => {
if (err)
installationLog.appendLine("Failed to delete " + outputPath);
});
done(true);
}
else if (ext == ".tar.gz") {
installationLog.appendLine("> tar -zxvf dub" + ext);
Expand Down Expand Up @@ -157,7 +157,7 @@ export function installServeD(env: any, done: Function) {
if (!exists)
fs.mkdirSync(outputFolder);
if (fs.existsSync(finalDestination))
fs.unlinkSync(finalDestination);
rimraf.sync(finalDestination);
async.each(urls, function (url: string, cb: Function) {
output.appendLine("Downloading from " + url + " into " + outputFolder);
var fileName = path.basename(url, ext);
Expand All @@ -168,19 +168,18 @@ export function installServeD(env: any, done: Function) {
output.appendLine("Extracting " + fileName);
if (ext == ".zip") {
try {
fs.createReadStream(outputPath).pipe(unzip.Extract({ path: outputFolder })).on("finish", () => {
try {
output.appendLine("Deleting " + outputPath);
fs.unlink(outputPath, (err) => {
if (err)
output.appendLine("Failed to delete " + outputPath);
});
}
catch (e) {
vscode.window.showErrorMessage("Failed to delete temporary file: " + outputPath);
}
cb();
});
new AdmZip(outputPath).extractAllTo(outputFolder);
try {
output.appendLine("Deleting " + outputPath);
fs.unlink(outputPath, (err) => {
if (err)
output.appendLine("Failed to delete " + outputPath);
});
}
catch (e) {
vscode.window.showErrorMessage("Failed to delete temporary file: " + outputPath);
}
cb();
}
catch (e) {
return cb(e);
Expand Down

0 comments on commit 9117dc1

Please sign in to comment.