Skip to content

Commit 7969141

Browse files
committed
Fallback for removePackage
1 parent 8532462 commit 7969141

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/dappmanager/src/calls/packageRemove.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import * as getPath from "../utils/getPath";
1010
import shell from "../utils/shell";
1111
import { listPackage } from "../modules/docker/listContainers";
12+
import { logs } from "../logs";
1213

1314
/**
1415
* Remove package data: docker down + disk files
@@ -33,20 +34,30 @@ export async function packageRemove({
3334
throw Error("Core packages cannot be cannot be removed");
3435
}
3536

36-
// Only no-cores will
37+
// Only no-cores reach this block
3738
const composePath = getPath.dockerCompose(dnp.dnpName, false);
3839
const packageRepoDir = getPath.packageRepoDir(dnp.dnpName, false);
3940

4041
// [NOTE] Not necessary to close the ports since they will just
4142
// not be renewed in the next interval
4243

44+
// If there is no docker-compose, do a docker rm directly
45+
// Otherwise, try to do a docker-compose down and if it fails,
46+
// log to console and do docker-rm
47+
let hasRemoved = false;
4348
if (fs.existsSync(composePath)) {
44-
await dockerComposeDown(composePath, {
45-
volumes: deleteVolumes,
46-
timeout
47-
});
48-
} else {
49-
// Still try to delete the package if there is not compose
49+
try {
50+
await dockerComposeDown(composePath, {
51+
volumes: deleteVolumes,
52+
timeout
53+
});
54+
hasRemoved = true; // To mimic an early return
55+
} catch (e) {
56+
logs.error(`Error on dockerComposeDown of ${dnp.dnpName}`, e);
57+
}
58+
}
59+
60+
if (!hasRemoved) {
5061
const containerNames = dnp.containers.map(c => c.containerName);
5162
await dockerStop(containerNames, { time: timeout });
5263
await dockerRm(containerNames, { volumes: deleteVolumes });

0 commit comments

Comments
 (0)