forked from conda-incubator/setup-miniconda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.ts
45 lines (39 loc) · 1.29 KB
/
delete.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as core from "@actions/core";
import * as io from "@actions/io";
import * as utils from "./utils";
async function run(): Promise<void> {
try {
let cacheFolder: string = "~/conda_pkgs_dir";
cacheFolder = cacheFolder.replace("~", os.homedir().replace("\\", "/"));
if (fs.existsSync(cacheFolder) && fs.lstatSync(cacheFolder).isDirectory()) {
utils.consoleLog(
"Removing uncompressed packages to trim down cache folder..."
);
let fullPath: string;
for (let folder_or_file of fs.readdirSync(cacheFolder)) {
fullPath = path.join(cacheFolder, folder_or_file);
if (
fs.existsSync(fullPath) &&
fs.lstatSync(fullPath).isDirectory() &&
folder_or_file != "cache"
) {
core.info(`Removing "${fullPath}"`);
try {
await io.rmRF(fullPath);
} catch (err) {
// If file could not be deleted, move to a temp folder
core.info(`Remove failed, moving "${fullPath}" to temp folder`);
await io.mv(fullPath, path.join(os.tmpdir(), folder_or_file));
}
}
}
}
} catch (err) {
core.setFailed(err.message);
}
}
void run();
export default run;