Skip to content

Commit

Permalink
fix(helm): Handle EXDEV error
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Jun 5, 2024
1 parent fab7c3e commit 7a17dec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
27 changes: 27 additions & 0 deletions packages/helm/src/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getErrorCode } from "@kosko/common-utils";
import { cp, rename, rm, stat } from "node:fs/promises";

export async function move(src: string, dest: string): Promise<void> {
try {
await rename(src, dest);
} catch (err) {
if (getErrorCode(err) !== "EXDEV") throw err;

await cp(src, dest, {

Check warning on line 10 in packages/helm/src/fs.ts

View check run for this annotation

Codecov / codecov/patch

packages/helm/src/fs.ts#L10

Added line #L10 was not covered by tests
recursive: true,
errorOnExist: true,
preserveTimestamps: true
});
await rm(src, { recursive: true, force: true });

Check warning on line 15 in packages/helm/src/fs.ts

View check run for this annotation

Codecov / codecov/patch

packages/helm/src/fs.ts#L15

Added line #L15 was not covered by tests
}
}

export async function fileExists(path: string): Promise<boolean> {
try {
const stats = await stat(path);
return stats.isFile();
} catch (err) {
if (getErrorCode(err) !== "ENOENT") throw err;
return false;
}
}
16 changes: 3 additions & 13 deletions packages/helm/src/load.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoadOptions, loadString, Manifest } from "@kosko/yaml";
import tmp from "tmp-promise";
import { writeFile, stat, rename, readFile, mkdir } from "node:fs/promises";
import { writeFile, readFile, mkdir } from "node:fs/promises";
import {
spawn,
booleanArg,
Expand All @@ -14,6 +14,7 @@ import { createHash } from "node:crypto";
import { dirname, join } from "node:path";
import { env } from "node:process";
import yaml from "js-yaml";
import { fileExists, move } from "./fs";

const FILE_EXIST_ERROR_CODES = new Set(["EEXIST", "ENOTEMPTY"]);
const OCI_PREFIX = "oci://";
Expand Down Expand Up @@ -253,17 +254,6 @@ function chartManifestExists(path: string) {
return fileExists(getChartManifestPath(path));
}

async function fileExists(path: string): Promise<boolean> {
try {
// Check if `Chart.yaml` exists
const stats = await stat(path);
return stats.isFile();
} catch (err) {
if (getErrorCode(err) !== "ENOENT") throw err;
return false;
}
}

async function isLocalChart(
options: Pick<PullOptions, "repo" | "chart">
): Promise<boolean> {
Expand Down Expand Up @@ -320,7 +310,7 @@ async function moveChartToCacheDir(src: string, dest: string): Promise<void> {
await mkdir(dirname(dest), { recursive: true });

try {
await rename(src, dest);
await move(src, dest);
} catch (err) {
const code = getErrorCode(err);

Check warning on line 315 in packages/helm/src/load.ts

View check run for this annotation

Codecov / codecov/patch

packages/helm/src/load.ts#L315

Added line #L315 was not covered by tests

Expand Down

0 comments on commit 7a17dec

Please sign in to comment.