Skip to content

Commit cd877d4

Browse files
committed
Update delete code to move the extracted pkgs instead of removing them 1 by 1
1 parent 5c84a31 commit cd877d4

File tree

2 files changed

+79
-55
lines changed

2 files changed

+79
-55
lines changed

dist/delete/index.js

Lines changed: 43 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/delete.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,59 @@
11
import * as fs from "fs";
2-
import * as os from "os";
32
import * as path from "path";
43

54
import * as core from "@actions/core";
6-
import * as io from "@actions/io";
75

86
import * as input from "./input";
97
import * as utils from "./utils";
108

119
/**
12-
* Clean up the conda cache directory
10+
* Clean up extracted packages from the conda packages directory, keeping only
11+
* the compressed archive cache and loose archive files.
12+
*
13+
* Instead of recursively deleting each extracted folder (extremely slow on
14+
* Windows due to filesystem overhead), we rename them to a sibling directory
15+
* on the same filesystem. The renamed directory is left for the ephemeral
16+
* runner VM to discard.
1317
*/
1418
async function run(): Promise<void> {
1519
try {
1620
const inputs = await core.group("Gathering Inputs...", input.parseInputs);
17-
let pkgsDirs = utils.parsePkgsDirs(inputs.condaConfig.pkgs_dirs);
21+
const pkgsDirs = utils.parsePkgsDirs(inputs.condaConfig.pkgs_dirs);
1822
if (!pkgsDirs.length) return;
1923
core.startGroup(
2024
"Removing uncompressed packages to trim down packages directory...",
2125
);
2226
for (const pkgsDir of pkgsDirs) {
23-
if (fs.existsSync(pkgsDir) && fs.lstatSync(pkgsDir).isDirectory()) {
24-
let fullPath: string;
25-
for (let folder_or_file of fs.readdirSync(pkgsDir)) {
26-
fullPath = path.join(pkgsDir, folder_or_file);
27-
if (
28-
fs.existsSync(fullPath) &&
29-
fs.lstatSync(fullPath).isDirectory() &&
30-
folder_or_file != "cache"
31-
) {
32-
core.info(`Removing "${fullPath}"`);
33-
try {
34-
await io.rmRF(fullPath);
35-
} catch (err) {
36-
// If file could not be deleted, move to a temp folder
37-
core.info(`Remove failed, moving "${fullPath}" to temp folder`);
38-
await io.mv(fullPath, path.join(os.tmpdir(), folder_or_file));
39-
}
40-
}
27+
if (!fs.existsSync(pkgsDir) || !fs.lstatSync(pkgsDir).isDirectory()) {
28+
continue;
29+
}
30+
31+
// Stash directory is a sibling to pkgsDir so rename stays on the
32+
// same filesystem and never fails with EXDEV
33+
const stashDir = `${pkgsDir}_stash_${Date.now()}`;
34+
fs.mkdirSync(stashDir, { recursive: true });
35+
36+
for (const entry of fs.readdirSync(pkgsDir)) {
37+
if (entry === "cache") continue;
38+
39+
const fullPath = path.join(pkgsDir, entry);
40+
if (!fs.existsSync(fullPath) || !fs.lstatSync(fullPath).isDirectory()) {
41+
continue;
42+
}
43+
44+
const dest = path.join(stashDir, entry);
45+
core.info(`Stashing "${fullPath}"`);
46+
try {
47+
fs.renameSync(fullPath, dest);
48+
} catch (err) {
49+
core.warning(`Could not stash "${fullPath}": ${err}. Skipping.`);
4150
}
4251
}
52+
53+
core.info(
54+
`Stashed extracted packages to "${stashDir}", ` +
55+
"will be discarded with the runner VM.",
56+
);
4357
}
4458
core.endGroup();
4559
} catch (err) {

0 commit comments

Comments
 (0)