Skip to content

Commit f05f511

Browse files
committed
btrfs: cleanup util
1 parent 832e124 commit f05f511

File tree

5 files changed

+9
-40
lines changed

5 files changed

+9
-40
lines changed

src/packages/file-server/btrfs/filesystem.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export class Filesystem {
6565
await mkdirp([this.opts.mount]);
6666
await this.initDevice();
6767
await this.mountFilesystem();
68-
await sudo({ command: "chmod", args: ["a+rx", this.opts.mount] });
6968
await btrfs({
7069
args: ["quota", "enable", "--simple", this.opts.mount],
7170
});

src/packages/file-server/btrfs/subvolume.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ A subvolume
44

55
import { type Filesystem, DEFAULT_SUBVOLUME_SIZE } from "./filesystem";
66
import refCache from "@cocalc/util/refcache";
7-
import { exists, sudo } from "./util";
7+
import { sudo } from "./util";
88
import { join, normalize } from "path";
99
import { SubvolumeFilesystem } from "./subvolume-fs";
1010
import { SubvolumeBup } from "./subvolume-bup";
1111
import { SubvolumeSnapshots } from "./subvolume-snapshots";
1212
import { SubvolumeQuota } from "./subvolume-quota";
13+
import { exists } from "@cocalc/backend/misc/async-utils-node";
14+
1315
import getLogger from "@cocalc/backend/logger";
1416

1517
const logger = getLogger("file-server:btrfs:subvolume");

src/packages/file-server/btrfs/subvolumes.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import getLogger from "@cocalc/backend/logger";
44
import { SNAPSHOTS } from "./subvolume-snapshots";
55
import { exists } from "@cocalc/backend/misc/async-utils-node";
66
import { join, normalize } from "path";
7-
import { btrfs } from "./util";
8-
import { chmod, rename, readdir, rm, stat } from "fs/promises";
7+
import { btrfs, isdir } from "./util";
8+
import { chmod, rename, rm } from "node:fs/promises";
99
import { executeCode } from "@cocalc/backend/execute-code";
1010

1111
const RESERVED = new Set(["bup", SNAPSHOTS]);
@@ -113,7 +113,3 @@ export class Subvolumes {
113113
});
114114
};
115115
}
116-
117-
async function isdir(path: string) {
118-
return (await stat(path)).isDirectory();
119-
}

src/packages/file-server/btrfs/test/filesystem-stress.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { before, after, fs } from "./setup";
22

33
beforeAll(before);
44

5-
//const log = console.log;
6-
const log = (..._args) => {};
5+
const DEBUG = false;
6+
const log = DEBUG ? console.log : (..._args) => {};
77

88
describe("stress operations with subvolumes", () => {
99
const count1 = 10;

src/packages/file-server/btrfs/util.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,17 @@ import {
44
} from "@cocalc/util/types/execute-code";
55
import { executeCode } from "@cocalc/backend/execute-code";
66
import getLogger from "@cocalc/backend/logger";
7+
import { stat } from "node:fs/promises";
78

89
const logger = getLogger("file-server:storage:util");
910

1011
const DEFAULT_EXEC_TIMEOUT_MS = 60 * 1000;
1112

12-
export async function exists(path: string) {
13-
try {
14-
await sudo({ command: "ls", args: [path], verbose: false });
15-
return true;
16-
} catch {
17-
return false;
18-
}
19-
}
20-
2113
export async function mkdirp(paths: string[]) {
2214
if (paths.length == 0) return;
2315
await sudo({ command: "mkdir", args: ["-p", ...paths] });
2416
}
2517

26-
export async function chmod(args: string[]) {
27-
await sudo({ command: "chmod", args: args });
28-
}
29-
3018
export async function sudo(
3119
opts: ExecuteCodeOptions & { desc?: string },
3220
): Promise<ExecuteCodeOutput> {
@@ -56,24 +44,8 @@ export async function btrfs(
5644
return await sudo({ ...opts, command: "btrfs" });
5745
}
5846

59-
export async function rm(paths: string[]) {
60-
if (paths.length == 0) return;
61-
await sudo({ command: "rm", args: paths });
62-
}
63-
64-
export async function rmdir(paths: string[]) {
65-
if (paths.length == 0) return;
66-
await sudo({ command: "rmdir", args: paths });
67-
}
68-
69-
export async function listdir(path: string) {
70-
const { stdout } = await sudo({ command: "ls", args: ["-1", path] });
71-
return stdout.split("\n").filter((x) => x);
72-
}
73-
7447
export async function isdir(path: string) {
75-
const { stdout } = await sudo({ command: "stat", args: ["-c", "%F", path] });
76-
return stdout.trim() == "directory";
48+
return (await stat(path)).isDirectory();
7749
}
7850

7951
export function parseBupTime(s: string): Date {

0 commit comments

Comments
 (0)