@photostructure/fs-metadata 0.3.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/C++_REVIEW_TODO.md +291 -0
- package/CHANGELOG.md +33 -1
- package/CLAUDE.md +169 -0
- package/CONTRIBUTING.md +25 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +131 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/array.ts.html +217 -0
- package/coverage/lcov-report/src/async.ts.html +547 -0
- package/coverage/lcov-report/src/debuglog.ts.html +187 -0
- package/coverage/lcov-report/src/defer.ts.html +175 -0
- package/coverage/lcov-report/src/dirname.ts.html +124 -0
- package/coverage/lcov-report/src/error.ts.html +322 -0
- package/coverage/lcov-report/src/fs.ts.html +316 -0
- package/coverage/lcov-report/src/glob.ts.html +472 -0
- package/coverage/lcov-report/src/hidden.ts.html +724 -0
- package/coverage/lcov-report/src/index.html +521 -0
- package/coverage/lcov-report/src/index.ts.html +676 -0
- package/coverage/lcov-report/src/linux/dev_disk.ts.html +316 -0
- package/coverage/lcov-report/src/linux/index.html +146 -0
- package/coverage/lcov-report/src/linux/mount_points.ts.html +364 -0
- package/coverage/lcov-report/src/linux/mtab.ts.html +493 -0
- package/coverage/lcov-report/src/mount_point.ts.html +106 -0
- package/coverage/lcov-report/src/number.ts.html +148 -0
- package/coverage/lcov-report/src/object.ts.html +265 -0
- package/coverage/lcov-report/src/options.ts.html +475 -0
- package/coverage/lcov-report/src/path.ts.html +268 -0
- package/coverage/lcov-report/src/platform.ts.html +112 -0
- package/coverage/lcov-report/src/random.ts.html +205 -0
- package/coverage/lcov-report/src/remote_info.ts.html +553 -0
- package/coverage/lcov-report/src/stack_path.ts.html +298 -0
- package/coverage/lcov-report/src/string.ts.html +382 -0
- package/coverage/lcov-report/src/string_enum.ts.html +208 -0
- package/coverage/lcov-report/src/system_volume.ts.html +301 -0
- package/coverage/lcov-report/src/unc.ts.html +274 -0
- package/coverage/lcov-report/src/units.ts.html +274 -0
- package/coverage/lcov-report/src/uuid.ts.html +157 -0
- package/coverage/lcov-report/src/volume_health_status.ts.html +259 -0
- package/coverage/lcov-report/src/volume_metadata.ts.html +787 -0
- package/coverage/lcov-report/src/volume_mount_points.ts.html +388 -0
- package/coverage/lcov.info +3581 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/coverage/src/array.ts.html +217 -0
- package/coverage/src/async.ts.html +547 -0
- package/coverage/src/debuglog.ts.html +187 -0
- package/coverage/src/defer.ts.html +175 -0
- package/coverage/src/dirname.ts.html +124 -0
- package/coverage/src/error.ts.html +322 -0
- package/coverage/src/fs.ts.html +316 -0
- package/coverage/src/glob.ts.html +472 -0
- package/coverage/src/hidden.ts.html +724 -0
- package/coverage/src/index.html +521 -0
- package/coverage/src/index.ts.html +676 -0
- package/coverage/src/linux/dev_disk.ts.html +316 -0
- package/coverage/src/linux/index.html +146 -0
- package/coverage/src/linux/mount_points.ts.html +364 -0
- package/coverage/src/linux/mtab.ts.html +493 -0
- package/coverage/src/mount_point.ts.html +106 -0
- package/coverage/src/number.ts.html +148 -0
- package/coverage/src/object.ts.html +265 -0
- package/coverage/src/options.ts.html +475 -0
- package/coverage/src/path.ts.html +268 -0
- package/coverage/src/platform.ts.html +112 -0
- package/coverage/src/random.ts.html +205 -0
- package/coverage/src/remote_info.ts.html +553 -0
- package/coverage/src/stack_path.ts.html +298 -0
- package/coverage/src/string.ts.html +382 -0
- package/coverage/src/string_enum.ts.html +208 -0
- package/coverage/src/system_volume.ts.html +301 -0
- package/coverage/src/unc.ts.html +274 -0
- package/coverage/src/units.ts.html +274 -0
- package/coverage/src/uuid.ts.html +157 -0
- package/coverage/src/volume_health_status.ts.html +259 -0
- package/coverage/src/volume_metadata.ts.html +787 -0
- package/coverage/src/volume_mount_points.ts.html +388 -0
- package/jest.config.cjs +67 -6
- package/package.json +51 -40
- package/prebuilds/linux-x64/@photostructure+fs-metadata.glibc.node +0 -0
- package/scripts/check-memory.mjs +243 -0
- package/scripts/clang-tidy.mjs +73 -0
- package/scripts/is-platform.mjs +12 -0
- package/scripts/post-build.mjs +21 -0
- package/scripts/run-asan.sh +92 -0
- package/scripts/valgrind-test.mjs +83 -0
- package/scripts/valgrind.sh +70 -0
- package/src/async.ts +3 -3
- package/src/binding.cpp +3 -3
- package/src/darwin/hidden.cpp +14 -0
- package/src/darwin/raii_utils.h +85 -0
- package/src/darwin/volume_metadata.cpp +35 -60
- package/src/darwin/volume_mount_points.cpp +31 -22
- package/src/error.ts +3 -3
- package/src/fs.ts +1 -1
- package/src/glob.ts +2 -2
- package/src/hidden.ts +6 -6
- package/src/index.ts +19 -23
- package/src/linux/blkid_cache.cpp +15 -12
- package/src/linux/dev_disk.ts +2 -2
- package/src/linux/gio_mount_points.cpp +7 -7
- package/src/linux/gio_utils.cpp +19 -8
- package/src/linux/gio_volume_metadata.cpp +15 -15
- package/src/linux/mount_points.ts +9 -9
- package/src/linux/mtab.ts +7 -7
- package/src/linux/volume_metadata.cpp +6 -1
- package/src/object.ts +9 -4
- package/src/options.ts +4 -4
- package/src/path.ts +4 -4
- package/src/remote_info.ts +5 -5
- package/src/system_volume.ts +8 -8
- package/src/test-utils/assert.ts +2 -2
- package/src/test-utils/debuglog-child.ts +1 -3
- package/src/test-utils/debuglog-enabled-child.ts +10 -0
- package/src/test-utils/hidden-tests.ts +1 -1
- package/src/test-utils/platform.ts +3 -3
- package/src/types/native_bindings.ts +3 -3
- package/src/types/volume_metadata.ts +2 -2
- package/src/unc.ts +2 -2
- package/src/uuid.ts +1 -1
- package/src/volume_health_status.ts +6 -6
- package/src/volume_metadata.ts +20 -23
- package/src/volume_mount_points.ts +12 -17
- package/src/windows/drive_status.h +30 -13
- package/src/windows/hidden.cpp +12 -0
- package/src/windows/volume_metadata.cpp +17 -7
- package/tsup.config.ts +8 -2
- package/dist/index.cjs +0 -1439
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs +0 -1396
- package/dist/index.mjs.map +0 -1
- package/dist/types/array.d.ts +0 -25
- package/dist/types/async.d.ts +0 -42
- package/dist/types/debuglog.d.ts +0 -3
- package/dist/types/defer.d.ts +0 -10
- package/dist/types/dirname.d.ts +0 -1
- package/dist/types/error.d.ts +0 -17
- package/dist/types/fs.d.ts +0 -22
- package/dist/types/glob.d.ts +0 -17
- package/dist/types/hidden.d.ts +0 -29
- package/dist/types/index.d.ts +0 -91
- package/dist/types/linux/dev_disk.d.ts +0 -13
- package/dist/types/linux/mount_points.d.ts +0 -6
- package/dist/types/linux/mtab.d.ts +0 -47
- package/dist/types/mount_point.d.ts +0 -2
- package/dist/types/number.d.ts +0 -3
- package/dist/types/object.d.ts +0 -13
- package/dist/types/options.d.ts +0 -33
- package/dist/types/path.d.ts +0 -17
- package/dist/types/platform.d.ts +0 -4
- package/dist/types/random.d.ts +0 -12
- package/dist/types/remote_info.d.ts +0 -6
- package/dist/types/stack_path.d.ts +0 -2
- package/dist/types/string.d.ts +0 -37
- package/dist/types/string_enum.d.ts +0 -19
- package/dist/types/system_volume.d.ts +0 -14
- package/dist/types/types/hidden_metadata.d.ts +0 -32
- package/dist/types/types/mount_point.d.ts +0 -46
- package/dist/types/types/native_bindings.d.ts +0 -51
- package/dist/types/types/options.d.ts +0 -47
- package/dist/types/types/remote_info.d.ts +0 -33
- package/dist/types/types/volume_metadata.d.ts +0 -46
- package/dist/types/unc.d.ts +0 -11
- package/dist/types/units.d.ts +0 -38
- package/dist/types/uuid.d.ts +0 -16
- package/dist/types/volume_health_status.d.ts +0 -24
- package/dist/types/volume_metadata.d.ts +0 -8
- package/dist/types/volume_mount_points.d.ts +0 -6
- package/jest.config.base.cjs +0 -63
- package/prebuilds/darwin-arm64/@photostructure+fs-metadata.glibc.node +0 -0
- package/prebuilds/linux-arm64/@photostructure+fs-metadata.musl.node +0 -0
- package/prebuilds/linux-x64/@photostructure+fs-metadata.musl.node +0 -0
- package/prebuilds/win32-x64/@photostructure+fs-metadata.glibc.node +0 -0
package/dist/index.cjs
DELETED
|
@@ -1,1439 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
IncludeSystemVolumesDefault: () => IncludeSystemVolumesDefault,
|
|
34
|
-
LinuxMountTablePathsDefault: () => LinuxMountTablePathsDefault,
|
|
35
|
-
OptionsDefault: () => OptionsDefault,
|
|
36
|
-
SystemFsTypesDefault: () => SystemFsTypesDefault,
|
|
37
|
-
SystemPathPatternsDefault: () => SystemPathPatternsDefault,
|
|
38
|
-
TimeoutMsDefault: () => TimeoutMsDefault,
|
|
39
|
-
VolumeHealthStatuses: () => VolumeHealthStatuses,
|
|
40
|
-
getAllVolumeMetadata: () => getAllVolumeMetadata,
|
|
41
|
-
getHiddenMetadata: () => getHiddenMetadata,
|
|
42
|
-
getVolumeMetadata: () => getVolumeMetadata,
|
|
43
|
-
getVolumeMountPoints: () => getVolumeMountPoints,
|
|
44
|
-
isHidden: () => isHidden,
|
|
45
|
-
isHiddenRecursive: () => isHiddenRecursive,
|
|
46
|
-
optionsWithDefaults: () => optionsWithDefaults,
|
|
47
|
-
setHidden: () => setHidden
|
|
48
|
-
});
|
|
49
|
-
module.exports = __toCommonJS(index_exports);
|
|
50
|
-
var import_node_gyp_build = __toESM(require("node-gyp-build"));
|
|
51
|
-
|
|
52
|
-
// src/debuglog.ts
|
|
53
|
-
var import_node_util = require("util");
|
|
54
|
-
function defer(thunk) {
|
|
55
|
-
let t;
|
|
56
|
-
return () => t ??= thunk();
|
|
57
|
-
}
|
|
58
|
-
var debugLogContext = defer(() => {
|
|
59
|
-
for (const ea of ["fs-metadata", "fs-meta"]) {
|
|
60
|
-
if ((0, import_node_util.debuglog)(ea).enabled) {
|
|
61
|
-
return ea;
|
|
62
|
-
}
|
|
63
|
-
if ((0, import_node_util.debuglog)(ea.toUpperCase()).enabled) {
|
|
64
|
-
return ea;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return "photostructure:fs-metadata";
|
|
68
|
-
});
|
|
69
|
-
var isDebugEnabled = defer(() => {
|
|
70
|
-
return (0, import_node_util.debuglog)(debugLogContext()).enabled ?? false;
|
|
71
|
-
});
|
|
72
|
-
function debug(msg, ...args) {
|
|
73
|
-
if (!isDebugEnabled()) return;
|
|
74
|
-
const now = /* @__PURE__ */ new Date();
|
|
75
|
-
const timestamp = `[${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}.${now.getMilliseconds().toString().padStart(3, "0")}] ${debugLogContext()} `;
|
|
76
|
-
process.stderr.write(timestamp + (0, import_node_util.format)(msg, ...args) + "\n");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// src/defer.ts
|
|
80
|
-
function defer2(thunk) {
|
|
81
|
-
let computed = false;
|
|
82
|
-
let value;
|
|
83
|
-
const fn = () => {
|
|
84
|
-
if (!computed) {
|
|
85
|
-
computed = true;
|
|
86
|
-
value = thunk();
|
|
87
|
-
}
|
|
88
|
-
return value;
|
|
89
|
-
};
|
|
90
|
-
fn.reset = () => {
|
|
91
|
-
computed = false;
|
|
92
|
-
};
|
|
93
|
-
return fn;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// src/stack_path.ts
|
|
97
|
-
var import_node_path = require("path");
|
|
98
|
-
|
|
99
|
-
// src/platform.ts
|
|
100
|
-
var import_node_process = require("process");
|
|
101
|
-
var isLinux = import_node_process.platform === "linux";
|
|
102
|
-
var isWindows = import_node_process.platform === "win32";
|
|
103
|
-
var isMacOS = import_node_process.platform === "darwin";
|
|
104
|
-
var isArm = isLinux && import_node_process.arch.startsWith("arm");
|
|
105
|
-
|
|
106
|
-
// src/string.ts
|
|
107
|
-
function isString(input) {
|
|
108
|
-
return typeof input === "string";
|
|
109
|
-
}
|
|
110
|
-
function toS(input) {
|
|
111
|
-
return isString(input) ? input : input == null ? "" : String(input);
|
|
112
|
-
}
|
|
113
|
-
function isNotBlank(input) {
|
|
114
|
-
return typeof input === "string" && input.trim().length > 0;
|
|
115
|
-
}
|
|
116
|
-
function isBlank(input) {
|
|
117
|
-
return !isNotBlank(input);
|
|
118
|
-
}
|
|
119
|
-
function toNotBlank(input) {
|
|
120
|
-
return isNotBlank(input) ? input : void 0;
|
|
121
|
-
}
|
|
122
|
-
function decodeEscapeSequences(input) {
|
|
123
|
-
const escapeRegex = /\\(?:([0-7]{2,6})|x([0-9a-fA-F]{2,4}))/g;
|
|
124
|
-
return input.replace(escapeRegex, (match, octal, hex) => {
|
|
125
|
-
if (octal != null) {
|
|
126
|
-
return String.fromCharCode(parseInt(octal, 8));
|
|
127
|
-
}
|
|
128
|
-
if (hex != null) {
|
|
129
|
-
return String.fromCharCode(parseInt(hex, 16));
|
|
130
|
-
}
|
|
131
|
-
throw new Error(`Invalid escape sequence: ${match}`);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
function sortObjectsByLocale(arr, fn, locales, options) {
|
|
135
|
-
return arr.sort((a, b) => fn(a).localeCompare(fn(b), locales, options));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// src/stack_path.ts
|
|
139
|
-
function getCallerDirname() {
|
|
140
|
-
const e = new Error();
|
|
141
|
-
if (e.stack == null) {
|
|
142
|
-
Error.captureStackTrace(e);
|
|
143
|
-
}
|
|
144
|
-
return (0, import_node_path.dirname)(extractCallerPath(e.stack));
|
|
145
|
-
}
|
|
146
|
-
var patterns = isWindows ? [
|
|
147
|
-
// Standard: "at functionName (C:\path\file.js:1:1)"
|
|
148
|
-
/\bat\s.+?\((?<path>[A-Z]:\\.+):\d+:\d+\)$/,
|
|
149
|
-
// direct: "at C:\path\file.js:1:1"
|
|
150
|
-
/\bat\s(?<path>[A-Z]:\\.+):\d+:\d+$/,
|
|
151
|
-
// UNC: "at functionName (\\server\share\path\file.js:1:1)"
|
|
152
|
-
/\bat\s.+?\((?<path>\\\\.+):\d+:\d+\)$/,
|
|
153
|
-
// direct: "at \\server\share\path\file.js:1:1"
|
|
154
|
-
/\bat\s(?<path>\\\\.+):\d+:\d+$/
|
|
155
|
-
] : [
|
|
156
|
-
// Standard: "at functionName (/path/file.js:1:1)"
|
|
157
|
-
/\bat\s.+?\((?<path>\/.+?):\d+:\d+\)$/,
|
|
158
|
-
// Anonymous or direct: "at /path/file.js:1:1"
|
|
159
|
-
/\bat\s(.+[^/]\s)?(?<path>\/.+?):\d+:\d+$/
|
|
160
|
-
];
|
|
161
|
-
var MaybeUrlRE = /^[a-z]{2,5}:\/\//i;
|
|
162
|
-
function extractCallerPath(stack) {
|
|
163
|
-
const frames = stack.split("\n").filter(Boolean);
|
|
164
|
-
const callerFrame = frames.findIndex(
|
|
165
|
-
(frame) => frame.includes("getCallerDirname")
|
|
166
|
-
);
|
|
167
|
-
if (callerFrame === -1) {
|
|
168
|
-
throw new Error("Invalid stack trace format: missing caller frame");
|
|
169
|
-
}
|
|
170
|
-
for (let i = callerFrame + 1; i < frames.length; i++) {
|
|
171
|
-
const frame = frames[i];
|
|
172
|
-
for (const pattern of patterns) {
|
|
173
|
-
const g = toS(frame).trim().match(pattern)?.groups;
|
|
174
|
-
if (g != null && isNotBlank(g["path"])) {
|
|
175
|
-
const path = g["path"];
|
|
176
|
-
if (MaybeUrlRE.test(path)) {
|
|
177
|
-
try {
|
|
178
|
-
return new URL(path).pathname;
|
|
179
|
-
} catch {
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return path;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
throw new Error("Invalid stack trace format: no parsable frames");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// src/dirname.ts
|
|
190
|
-
function _dirname() {
|
|
191
|
-
try {
|
|
192
|
-
if (typeof __dirname !== "undefined") return __dirname;
|
|
193
|
-
} catch {
|
|
194
|
-
}
|
|
195
|
-
return getCallerDirname();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// src/fs.ts
|
|
199
|
-
var import_node_fs = require("fs");
|
|
200
|
-
var import_promises = require("fs/promises");
|
|
201
|
-
var import_node_path2 = require("path");
|
|
202
|
-
|
|
203
|
-
// src/async.ts
|
|
204
|
-
var import_node_os = require("os");
|
|
205
|
-
var import_node_process2 = require("process");
|
|
206
|
-
|
|
207
|
-
// src/number.ts
|
|
208
|
-
function isNumber(value) {
|
|
209
|
-
return typeof value === "number" && isFinite(value);
|
|
210
|
-
}
|
|
211
|
-
var INTEGER_REGEX = /^-?\d+$/;
|
|
212
|
-
function toInt(value) {
|
|
213
|
-
try {
|
|
214
|
-
if (value == null) return;
|
|
215
|
-
const s = String(value).trim();
|
|
216
|
-
return INTEGER_REGEX.test(s) ? parseInt(s) : void 0;
|
|
217
|
-
} catch {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function gt0(value) {
|
|
222
|
-
return isNumber(value) && value > 0;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// src/units.ts
|
|
226
|
-
var SecondMs = 1e3;
|
|
227
|
-
var MinuteMs = 60 * SecondMs;
|
|
228
|
-
var HourMs = 60 * MinuteMs;
|
|
229
|
-
var DayMs = 24 * HourMs;
|
|
230
|
-
var KiB = 1024;
|
|
231
|
-
var MiB = 1024 * KiB;
|
|
232
|
-
var GiB = 1024 * MiB;
|
|
233
|
-
var TiB = 1024 * GiB;
|
|
234
|
-
var f = 1023.995 / 1024;
|
|
235
|
-
|
|
236
|
-
// src/async.ts
|
|
237
|
-
var TimeoutError = class extends Error {
|
|
238
|
-
constructor(message, captureStackTrace = true) {
|
|
239
|
-
super(message);
|
|
240
|
-
this.name = "TimeoutError";
|
|
241
|
-
if (captureStackTrace && Error.captureStackTrace) {
|
|
242
|
-
Error.captureStackTrace(this, this.constructor);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
async function withTimeout(opts) {
|
|
247
|
-
const desc = isBlank(opts.desc) ? "thenOrTimeout()" : opts.desc;
|
|
248
|
-
if (!isNumber(opts.timeoutMs)) {
|
|
249
|
-
throw new TypeError(
|
|
250
|
-
desc + ": Expected timeoutMs to be numeric, but got " + JSON.stringify(opts.timeoutMs)
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
const timeoutMs = Math.floor(opts.timeoutMs);
|
|
254
|
-
if (timeoutMs < 0) {
|
|
255
|
-
throw new TypeError(
|
|
256
|
-
desc + ": Expected timeoutMs to be > 0, but got " + timeoutMs
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
if (timeoutMs > DayMs) {
|
|
260
|
-
throw new TypeError(
|
|
261
|
-
desc + ": Invalid timeoutMs is too large: must be less than one day, but got " + timeoutMs
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
if (timeoutMs === 0) {
|
|
265
|
-
return opts.promise;
|
|
266
|
-
}
|
|
267
|
-
const timeoutError = new TimeoutError(
|
|
268
|
-
`${desc}: timeout after ${timeoutMs}ms`
|
|
269
|
-
);
|
|
270
|
-
if (import_node_process2.env["NODE_ENV"] === "test" && timeoutMs === 1) {
|
|
271
|
-
timeoutError.message += "(timeout test)";
|
|
272
|
-
opts.promise.catch(() => {
|
|
273
|
-
});
|
|
274
|
-
throw timeoutError;
|
|
275
|
-
}
|
|
276
|
-
let timeoutId;
|
|
277
|
-
opts.promise.catch(() => {
|
|
278
|
-
}).finally(() => {
|
|
279
|
-
if (timeoutId != null) {
|
|
280
|
-
clearTimeout(timeoutId);
|
|
281
|
-
timeoutId = void 0;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
285
|
-
timeoutId = setTimeout(() => {
|
|
286
|
-
if (timeoutId != null) {
|
|
287
|
-
timeoutError.message += "(timeout callback)";
|
|
288
|
-
reject(timeoutError);
|
|
289
|
-
}
|
|
290
|
-
timeoutId = void 0;
|
|
291
|
-
}, timeoutMs);
|
|
292
|
-
});
|
|
293
|
-
return Promise.race([opts.promise, timeoutPromise]);
|
|
294
|
-
}
|
|
295
|
-
async function mapConcurrent({
|
|
296
|
-
items,
|
|
297
|
-
fn,
|
|
298
|
-
maxConcurrency = (0, import_node_os.availableParallelism)()
|
|
299
|
-
}) {
|
|
300
|
-
if (!gt0(maxConcurrency)) {
|
|
301
|
-
throw new Error(
|
|
302
|
-
`maxConcurrency must be a positive integer, got: ${maxConcurrency}`
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
if (typeof fn !== "function") {
|
|
306
|
-
throw new TypeError(`fn must be a function, got: ${typeof fn}`);
|
|
307
|
-
}
|
|
308
|
-
const results = [];
|
|
309
|
-
const executing = /* @__PURE__ */ new Set();
|
|
310
|
-
for (const [index, item] of items.entries()) {
|
|
311
|
-
while (executing.size >= maxConcurrency) {
|
|
312
|
-
await Promise.race(executing);
|
|
313
|
-
}
|
|
314
|
-
const p = results[index] = fn(item).catch((error) => error);
|
|
315
|
-
executing.add(p);
|
|
316
|
-
p.finally(() => executing.delete(p));
|
|
317
|
-
}
|
|
318
|
-
return Promise.all(results);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// src/fs.ts
|
|
322
|
-
async function statAsync(path, options) {
|
|
323
|
-
return (0, import_promises.stat)(path, options);
|
|
324
|
-
}
|
|
325
|
-
async function canStatAsync(path) {
|
|
326
|
-
try {
|
|
327
|
-
return null != await statAsync(path);
|
|
328
|
-
} catch {
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
async function findAncestorDir(dir, file) {
|
|
333
|
-
dir = (0, import_node_path2.resolve)(dir);
|
|
334
|
-
try {
|
|
335
|
-
const s = await statAsync((0, import_node_path2.join)(dir, file));
|
|
336
|
-
if (s.isFile()) return dir;
|
|
337
|
-
} catch {
|
|
338
|
-
}
|
|
339
|
-
const parent = (0, import_node_path2.resolve)(dir, "..");
|
|
340
|
-
return parent === dir ? void 0 : findAncestorDir(parent, file);
|
|
341
|
-
}
|
|
342
|
-
async function canReaddir(dir, timeoutMs) {
|
|
343
|
-
return withTimeout({
|
|
344
|
-
desc: "canReaddir()",
|
|
345
|
-
promise: _canReaddir(dir),
|
|
346
|
-
timeoutMs
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
async function _canReaddir(dir) {
|
|
350
|
-
await (await (0, import_promises.opendir)(dir)).close();
|
|
351
|
-
return true;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// src/hidden.ts
|
|
355
|
-
var import_promises2 = require("fs/promises");
|
|
356
|
-
var import_node_path4 = require("path");
|
|
357
|
-
|
|
358
|
-
// src/object.ts
|
|
359
|
-
function isObject(value) {
|
|
360
|
-
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
361
|
-
}
|
|
362
|
-
function map(obj, fn) {
|
|
363
|
-
return obj == null ? void 0 : fn(obj);
|
|
364
|
-
}
|
|
365
|
-
function omit(obj, ...keys) {
|
|
366
|
-
const result = {};
|
|
367
|
-
const keysSet = new Set(keys);
|
|
368
|
-
for (const key of Object.keys(obj)) {
|
|
369
|
-
if (!keysSet.has(key)) {
|
|
370
|
-
result[key] = obj[key];
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return result;
|
|
374
|
-
}
|
|
375
|
-
function compactValues(obj) {
|
|
376
|
-
const result = {};
|
|
377
|
-
if (obj == null || !isObject(obj)) return {};
|
|
378
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
379
|
-
if (value != null && (!isString(value) || isNotBlank(value))) {
|
|
380
|
-
result[key] = value;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
return result;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// src/error.ts
|
|
387
|
-
function toMessage(context, cause) {
|
|
388
|
-
const causeStr = cause instanceof Error ? cause.message : typeof cause === "string" ? cause : cause ? JSON.stringify(cause) : "";
|
|
389
|
-
return context + (isBlank(causeStr) ? "" : ": " + causeStr);
|
|
390
|
-
}
|
|
391
|
-
var WrappedError = class extends Error {
|
|
392
|
-
errno;
|
|
393
|
-
code;
|
|
394
|
-
syscall;
|
|
395
|
-
path;
|
|
396
|
-
constructor(context, options) {
|
|
397
|
-
super(toMessage(context, options?.cause));
|
|
398
|
-
const cause = map(options?.cause, toError);
|
|
399
|
-
const opts = { ...compactValues(cause), ...compactValues(options) };
|
|
400
|
-
if (isNotBlank(options?.name)) {
|
|
401
|
-
this.name = options.name;
|
|
402
|
-
}
|
|
403
|
-
if (cause != null) {
|
|
404
|
-
this.cause = cause;
|
|
405
|
-
if (cause instanceof Error) {
|
|
406
|
-
this.stack = `${this.stack}
|
|
407
|
-
Caused by: ${cause.stack}`;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (isNumber(opts.errno)) {
|
|
411
|
-
this.errno = opts.errno;
|
|
412
|
-
}
|
|
413
|
-
if (isNotBlank(opts.code)) {
|
|
414
|
-
this.code = opts.code;
|
|
415
|
-
}
|
|
416
|
-
if (isNotBlank(opts.syscall)) {
|
|
417
|
-
this.syscall = opts.syscall;
|
|
418
|
-
}
|
|
419
|
-
if (isNotBlank(options?.path)) {
|
|
420
|
-
this.path = options.path;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
get details() {
|
|
424
|
-
return compactValues(omit(this, "name", "message", "cause"));
|
|
425
|
-
}
|
|
426
|
-
toString() {
|
|
427
|
-
const details = this.details;
|
|
428
|
-
const detailsStr = Object.keys(details).length === 0 ? "" : " " + JSON.stringify(details);
|
|
429
|
-
return `${super.toString()}${detailsStr}`;
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
function toError(cause) {
|
|
433
|
-
return cause instanceof Error ? cause : new Error(String(cause));
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// src/path.ts
|
|
437
|
-
var import_node_path3 = require("path");
|
|
438
|
-
function normalizePath(mountPoint) {
|
|
439
|
-
if (isBlank(mountPoint)) return void 0;
|
|
440
|
-
const result = isWindows ? normalizeWindowsPath(mountPoint) : normalizePosixPath(mountPoint);
|
|
441
|
-
return result != null ? (0, import_node_path3.resolve)(result) : void 0;
|
|
442
|
-
}
|
|
443
|
-
function normalizePosixPath(mountPoint) {
|
|
444
|
-
if (isBlank(mountPoint)) return void 0;
|
|
445
|
-
if (mountPoint === "/") return mountPoint;
|
|
446
|
-
if (mountPoint[mountPoint.length - 1] !== "/") return mountPoint;
|
|
447
|
-
let end = mountPoint.length - 1;
|
|
448
|
-
while (end > 0 && mountPoint[end] === "/") {
|
|
449
|
-
end--;
|
|
450
|
-
}
|
|
451
|
-
return mountPoint.slice(0, end + 1);
|
|
452
|
-
}
|
|
453
|
-
function normalizeWindowsPath(mountPoint) {
|
|
454
|
-
return /^[a-z]:$/i.test(mountPoint) ? mountPoint.toUpperCase() + "\\" : mountPoint;
|
|
455
|
-
}
|
|
456
|
-
function isRootDirectory(path) {
|
|
457
|
-
const n = normalizePath(path);
|
|
458
|
-
return n == null ? false : isWindows ? (0, import_node_path3.dirname)(n) === n : n === "/";
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// src/hidden.ts
|
|
462
|
-
var HiddenSupportByPlatform = {
|
|
463
|
-
win32: {
|
|
464
|
-
supported: {
|
|
465
|
-
dotPrefix: false,
|
|
466
|
-
systemFlag: true
|
|
467
|
-
}
|
|
468
|
-
},
|
|
469
|
-
darwin: {
|
|
470
|
-
supported: {
|
|
471
|
-
dotPrefix: true,
|
|
472
|
-
systemFlag: true
|
|
473
|
-
}
|
|
474
|
-
},
|
|
475
|
-
linux: {
|
|
476
|
-
supported: {
|
|
477
|
-
dotPrefix: true,
|
|
478
|
-
systemFlag: false
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
var LocalSupport = HiddenSupportByPlatform[process.platform]?.supported ?? {
|
|
483
|
-
dotPrefix: false,
|
|
484
|
-
systemFlag: false
|
|
485
|
-
};
|
|
486
|
-
async function isHiddenImpl(pathname, nativeFn2) {
|
|
487
|
-
const norm = normalizePath(pathname);
|
|
488
|
-
if (norm == null) {
|
|
489
|
-
throw new Error("Invalid pathname: " + JSON.stringify(pathname));
|
|
490
|
-
}
|
|
491
|
-
return LocalSupport.dotPrefix && isPosixHidden(norm) || LocalSupport.systemFlag && isSystemHidden(norm, nativeFn2);
|
|
492
|
-
}
|
|
493
|
-
async function isHiddenRecursiveImpl(path, nativeFn2) {
|
|
494
|
-
let norm = normalizePath(path);
|
|
495
|
-
if (norm == null) {
|
|
496
|
-
throw new Error("Invalid path: " + JSON.stringify(path));
|
|
497
|
-
}
|
|
498
|
-
while (!isRootDirectory(norm)) {
|
|
499
|
-
if (await isHiddenImpl(norm, nativeFn2)) {
|
|
500
|
-
return true;
|
|
501
|
-
}
|
|
502
|
-
norm = (0, import_node_path4.dirname)(norm);
|
|
503
|
-
}
|
|
504
|
-
return false;
|
|
505
|
-
}
|
|
506
|
-
function createHiddenPosixPath(pathname, hidden) {
|
|
507
|
-
const norm = normalizePath(pathname);
|
|
508
|
-
if (norm == null) {
|
|
509
|
-
throw new Error("Invalid pathname: " + JSON.stringify(pathname));
|
|
510
|
-
}
|
|
511
|
-
const dir = (0, import_node_path4.dirname)(norm);
|
|
512
|
-
const srcBase = (0, import_node_path4.basename)(norm).replace(/^\./, "");
|
|
513
|
-
const dest = (0, import_node_path4.join)(dir, (hidden ? "." : "") + srcBase);
|
|
514
|
-
return dest;
|
|
515
|
-
}
|
|
516
|
-
async function setHiddenPosix(pathname, hidden) {
|
|
517
|
-
if (LocalSupport.dotPrefix) {
|
|
518
|
-
const dest = createHiddenPosixPath(pathname, hidden);
|
|
519
|
-
if (pathname !== dest) await (0, import_promises2.rename)(pathname, dest);
|
|
520
|
-
return dest;
|
|
521
|
-
}
|
|
522
|
-
throw new Error("Unsupported platform");
|
|
523
|
-
}
|
|
524
|
-
function isPosixHidden(pathname) {
|
|
525
|
-
if (!LocalSupport.dotPrefix) return false;
|
|
526
|
-
const b = (0, import_node_path4.basename)(pathname);
|
|
527
|
-
return b.startsWith(".") && b !== "." && b !== "..";
|
|
528
|
-
}
|
|
529
|
-
async function isSystemHidden(pathname, nativeFn2) {
|
|
530
|
-
if (!LocalSupport.systemFlag) {
|
|
531
|
-
return false;
|
|
532
|
-
}
|
|
533
|
-
if (isWindows && isRootDirectory(pathname)) {
|
|
534
|
-
return false;
|
|
535
|
-
}
|
|
536
|
-
return await canStatAsync(pathname) && await (await nativeFn2()).isHidden(pathname);
|
|
537
|
-
}
|
|
538
|
-
async function getHiddenMetadataImpl(pathname, nativeFn2) {
|
|
539
|
-
const norm = normalizePath(pathname);
|
|
540
|
-
if (norm == null) {
|
|
541
|
-
throw new Error("Invalid pathname: " + JSON.stringify(pathname));
|
|
542
|
-
}
|
|
543
|
-
const dotPrefix = isPosixHidden(norm);
|
|
544
|
-
const systemFlag = await isSystemHidden(norm, nativeFn2);
|
|
545
|
-
return {
|
|
546
|
-
hidden: dotPrefix || systemFlag,
|
|
547
|
-
dotPrefix,
|
|
548
|
-
systemFlag,
|
|
549
|
-
supported: LocalSupport
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
async function setHiddenImpl(pathname, hide, method, nativeFn2) {
|
|
553
|
-
let norm = normalizePath(pathname);
|
|
554
|
-
if (norm == null) {
|
|
555
|
-
throw new Error("Invalid pathname: " + JSON.stringify(pathname));
|
|
556
|
-
}
|
|
557
|
-
if (method === "dotPrefix" && !LocalSupport.dotPrefix) {
|
|
558
|
-
throw new Error("Dot prefix hiding is not supported on this platform");
|
|
559
|
-
}
|
|
560
|
-
if (method === "systemFlag" && !LocalSupport.systemFlag) {
|
|
561
|
-
throw new Error("System flag hiding is not supported on this platform");
|
|
562
|
-
}
|
|
563
|
-
try {
|
|
564
|
-
await statAsync(norm);
|
|
565
|
-
} catch (cause) {
|
|
566
|
-
throw new WrappedError("setHidden()", { cause });
|
|
567
|
-
}
|
|
568
|
-
if (isWindows && isRootDirectory(norm)) {
|
|
569
|
-
throw new Error("Cannot hide root directory on Windows");
|
|
570
|
-
}
|
|
571
|
-
const actions = {
|
|
572
|
-
dotPrefix: false,
|
|
573
|
-
systemFlag: false
|
|
574
|
-
};
|
|
575
|
-
let acted = false;
|
|
576
|
-
if (LocalSupport.dotPrefix && ["auto", "all", "dotPrefix"].includes(method)) {
|
|
577
|
-
if (isPosixHidden(norm) !== hide) {
|
|
578
|
-
norm = await setHiddenPosix(norm, hide);
|
|
579
|
-
actions.dotPrefix = true;
|
|
580
|
-
}
|
|
581
|
-
acted = true;
|
|
582
|
-
}
|
|
583
|
-
if (LocalSupport.systemFlag && (["all", "systemFlag"].includes(method) || !acted && method === "auto")) {
|
|
584
|
-
await (await nativeFn2()).setHidden(norm, hide);
|
|
585
|
-
actions.systemFlag = true;
|
|
586
|
-
}
|
|
587
|
-
return { pathname: norm, actions };
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
// src/options.ts
|
|
591
|
-
var import_node_os2 = require("os");
|
|
592
|
-
var TimeoutMsDefault = 5e3;
|
|
593
|
-
var SystemPathPatternsDefault = [
|
|
594
|
-
"/boot",
|
|
595
|
-
"/boot/efi",
|
|
596
|
-
"/dev",
|
|
597
|
-
"/dev/**",
|
|
598
|
-
"/proc/**",
|
|
599
|
-
"/run",
|
|
600
|
-
"/run/credentials/**",
|
|
601
|
-
"/run/lock",
|
|
602
|
-
"/run/snapd/**",
|
|
603
|
-
"/run/user/*/doc",
|
|
604
|
-
"/run/user/*/gvfs",
|
|
605
|
-
"/snap/**",
|
|
606
|
-
"/sys/**",
|
|
607
|
-
"/tmp",
|
|
608
|
-
"/var/tmp",
|
|
609
|
-
// we aren't including /tmp/**, as some people temporarily mount volumes there, like /tmp/project.
|
|
610
|
-
"**/#snapshot",
|
|
611
|
-
// Synology and Kubernetes volume snapshots
|
|
612
|
-
// windows for linux:
|
|
613
|
-
"/mnt/wslg/distro",
|
|
614
|
-
"/mnt/wslg/doc",
|
|
615
|
-
"/mnt/wslg/versions.txt",
|
|
616
|
-
"/usr/lib/wsl/drivers",
|
|
617
|
-
// MacOS stuff:
|
|
618
|
-
"/private/var/vm",
|
|
619
|
-
// macOS swap
|
|
620
|
-
"/System/Volumes/Hardware",
|
|
621
|
-
"/System/Volumes/iSCPreboot",
|
|
622
|
-
"/System/Volumes/Preboot",
|
|
623
|
-
"/System/Volumes/Recovery",
|
|
624
|
-
"/System/Volumes/Reserved",
|
|
625
|
-
"/System/Volumes/Update",
|
|
626
|
-
"/System/Volumes/VM",
|
|
627
|
-
"/System/Volumes/xarts"
|
|
628
|
-
];
|
|
629
|
-
var SystemFsTypesDefault = [
|
|
630
|
-
"autofs",
|
|
631
|
-
"binfmt_misc",
|
|
632
|
-
"cgroup",
|
|
633
|
-
"cgroup2",
|
|
634
|
-
"configfs",
|
|
635
|
-
"debugfs",
|
|
636
|
-
"devpts",
|
|
637
|
-
"devtmpfs",
|
|
638
|
-
"efivarfs",
|
|
639
|
-
"fusectl",
|
|
640
|
-
"fuse.snapfuse",
|
|
641
|
-
"hugetlbfs",
|
|
642
|
-
"mqueue",
|
|
643
|
-
"none",
|
|
644
|
-
"proc",
|
|
645
|
-
"pstore",
|
|
646
|
-
"rootfs",
|
|
647
|
-
"securityfs",
|
|
648
|
-
"snap*",
|
|
649
|
-
"squashfs",
|
|
650
|
-
"sysfs",
|
|
651
|
-
"tmpfs"
|
|
652
|
-
];
|
|
653
|
-
var LinuxMountTablePathsDefault = [
|
|
654
|
-
"/proc/self/mounts",
|
|
655
|
-
"/proc/mounts",
|
|
656
|
-
"/etc/mtab"
|
|
657
|
-
];
|
|
658
|
-
var IncludeSystemVolumesDefault = isWindows;
|
|
659
|
-
var OptionsDefault = {
|
|
660
|
-
timeoutMs: TimeoutMsDefault,
|
|
661
|
-
maxConcurrency: (0, import_node_os2.availableParallelism)(),
|
|
662
|
-
systemPathPatterns: [...SystemPathPatternsDefault],
|
|
663
|
-
systemFsTypes: [...SystemFsTypesDefault],
|
|
664
|
-
linuxMountTablePaths: [...LinuxMountTablePathsDefault],
|
|
665
|
-
includeSystemVolumes: IncludeSystemVolumesDefault
|
|
666
|
-
};
|
|
667
|
-
function optionsWithDefaults(overrides = {}) {
|
|
668
|
-
if (!isObject(overrides)) {
|
|
669
|
-
throw new TypeError(
|
|
670
|
-
"options(): expected an object, got " + typeof overrides + ": " + JSON.stringify(overrides)
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
return {
|
|
674
|
-
...OptionsDefault,
|
|
675
|
-
...compactValues(overrides)
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// src/string_enum.ts
|
|
680
|
-
function stringEnum(...o) {
|
|
681
|
-
const set = new Set(o);
|
|
682
|
-
const dict = {};
|
|
683
|
-
for (const key of o) {
|
|
684
|
-
dict[key] = key;
|
|
685
|
-
}
|
|
686
|
-
return {
|
|
687
|
-
...dict,
|
|
688
|
-
values: Object.freeze([...set]),
|
|
689
|
-
size: set.size,
|
|
690
|
-
get: (s) => s != null && set.has(s) ? s : void 0
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
// src/volume_health_status.ts
|
|
695
|
-
var VolumeHealthStatuses = stringEnum(
|
|
696
|
-
"healthy",
|
|
697
|
-
"timeout",
|
|
698
|
-
"inaccessible",
|
|
699
|
-
"disconnected",
|
|
700
|
-
"unknown"
|
|
701
|
-
);
|
|
702
|
-
async function directoryStatus(dir, timeoutMs, canReaddirImpl = canReaddir) {
|
|
703
|
-
try {
|
|
704
|
-
if (await canReaddirImpl(dir, timeoutMs)) {
|
|
705
|
-
return { status: VolumeHealthStatuses.healthy };
|
|
706
|
-
}
|
|
707
|
-
} catch (error) {
|
|
708
|
-
debug("[directoryStatus] %s: %s", dir, error);
|
|
709
|
-
let status = VolumeHealthStatuses.unknown;
|
|
710
|
-
if (error instanceof TimeoutError) {
|
|
711
|
-
status = VolumeHealthStatuses.timeout;
|
|
712
|
-
} else if (isObject(error) && error instanceof Error && "code" in error) {
|
|
713
|
-
if (error.code === "EPERM" || error.code === "EACCES") {
|
|
714
|
-
status = VolumeHealthStatuses.inaccessible;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
return { status, error: toError(error) };
|
|
718
|
-
}
|
|
719
|
-
return { status: VolumeHealthStatuses.unknown };
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// src/linux/dev_disk.ts
|
|
723
|
-
var import_promises3 = require("fs/promises");
|
|
724
|
-
var import_node_path5 = require("path");
|
|
725
|
-
async function getUuidFromDevDisk(devicePath) {
|
|
726
|
-
try {
|
|
727
|
-
const result = await getBasenameLinkedTo(
|
|
728
|
-
"/dev/disk/by-uuid",
|
|
729
|
-
(0, import_node_path5.resolve)(devicePath)
|
|
730
|
-
);
|
|
731
|
-
debug("[getUuidFromDevDisk] result: %o", result);
|
|
732
|
-
return result;
|
|
733
|
-
} catch (error) {
|
|
734
|
-
debug("[getUuidFromDevDisk] failed: " + error);
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
async function getLabelFromDevDisk(devicePath) {
|
|
739
|
-
try {
|
|
740
|
-
const result = await getBasenameLinkedTo(
|
|
741
|
-
"/dev/disk/by-label",
|
|
742
|
-
(0, import_node_path5.resolve)(devicePath)
|
|
743
|
-
);
|
|
744
|
-
debug("[getLabelFromDevDisk] result: %o", result);
|
|
745
|
-
return result;
|
|
746
|
-
} catch (error) {
|
|
747
|
-
debug("[getLabelFromDevDisk] failed: " + error);
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
async function getBasenameLinkedTo(linkDir, linkPath) {
|
|
752
|
-
for await (const ea of readLinks(linkDir)) {
|
|
753
|
-
if (ea.linkTarget === linkPath) {
|
|
754
|
-
return decodeEscapeSequences(ea.dirent.name);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
return;
|
|
758
|
-
}
|
|
759
|
-
async function* readLinks(directory) {
|
|
760
|
-
for (const dirent of await (0, import_promises3.readdir)(directory, { withFileTypes: true })) {
|
|
761
|
-
if (dirent.isSymbolicLink()) {
|
|
762
|
-
try {
|
|
763
|
-
const linkTarget = (0, import_node_path5.resolve)(
|
|
764
|
-
directory,
|
|
765
|
-
await (0, import_promises3.readlink)((0, import_node_path5.join)(directory, dirent.name))
|
|
766
|
-
);
|
|
767
|
-
yield { dirent, linkTarget };
|
|
768
|
-
} catch {
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// src/linux/mount_points.ts
|
|
775
|
-
var import_promises4 = require("fs/promises");
|
|
776
|
-
|
|
777
|
-
// src/mount_point.ts
|
|
778
|
-
function isMountPoint(obj) {
|
|
779
|
-
return isObject(obj) && "mountPoint" in obj && isNotBlank(obj.mountPoint);
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
// src/remote_info.ts
|
|
783
|
-
function isRemoteInfo(obj) {
|
|
784
|
-
if (!isObject(obj)) return false;
|
|
785
|
-
const { remoteHost, remoteShare } = obj;
|
|
786
|
-
return isNotBlank(remoteHost) && isNotBlank(remoteShare);
|
|
787
|
-
}
|
|
788
|
-
var NETWORK_FS_TYPE_ARRAY = [
|
|
789
|
-
"9p",
|
|
790
|
-
"afp",
|
|
791
|
-
"afs",
|
|
792
|
-
"beegfs",
|
|
793
|
-
"ceph",
|
|
794
|
-
"cifs",
|
|
795
|
-
"ftp",
|
|
796
|
-
"fuse",
|
|
797
|
-
"gfs2",
|
|
798
|
-
"glusterfs",
|
|
799
|
-
"lustre",
|
|
800
|
-
"ncpfs",
|
|
801
|
-
"nfs",
|
|
802
|
-
"nfs4",
|
|
803
|
-
"smb",
|
|
804
|
-
"smbfs",
|
|
805
|
-
"sshfs",
|
|
806
|
-
"webdav"
|
|
807
|
-
];
|
|
808
|
-
var NETWORK_FS_TYPES = new Set(NETWORK_FS_TYPE_ARRAY);
|
|
809
|
-
var FS_TYPE_ALIASES = /* @__PURE__ */ new Map([
|
|
810
|
-
["nfs1", "nfs"],
|
|
811
|
-
["nfs2", "nfs"],
|
|
812
|
-
["nfs3", "nfs"],
|
|
813
|
-
["nfs4", "nfs4"],
|
|
814
|
-
["fuse.sshfs", "sshfs"],
|
|
815
|
-
["sshfs.fuse", "sshfs"],
|
|
816
|
-
["davfs2", "webdav"],
|
|
817
|
-
["davfs", "webdav"],
|
|
818
|
-
["cifs.smb", "cifs"],
|
|
819
|
-
["smbfs", "cifs"],
|
|
820
|
-
["cephfs", "ceph"],
|
|
821
|
-
["fuse.ceph", "ceph"],
|
|
822
|
-
["fuse.cephfs", "ceph"],
|
|
823
|
-
["rbd", "ceph"],
|
|
824
|
-
["fuse.glusterfs", "glusterfs"]
|
|
825
|
-
]);
|
|
826
|
-
function normalizeFsType(fstype) {
|
|
827
|
-
const norm = toS(fstype).toLowerCase().replace(/:$/, "");
|
|
828
|
-
return FS_TYPE_ALIASES.get(norm) ?? norm;
|
|
829
|
-
}
|
|
830
|
-
function isRemoteFsType(fstype) {
|
|
831
|
-
return isNotBlank(fstype) && NETWORK_FS_TYPES.has(normalizeFsType(fstype));
|
|
832
|
-
}
|
|
833
|
-
function parseURL(s) {
|
|
834
|
-
try {
|
|
835
|
-
return isBlank(s) ? void 0 : new URL(s);
|
|
836
|
-
} catch {
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
function extractRemoteInfo(fsSpec) {
|
|
841
|
-
if (fsSpec == null || isBlank(fsSpec)) return;
|
|
842
|
-
if (isWindows) {
|
|
843
|
-
fsSpec = fsSpec.replace(/\\/g, "/");
|
|
844
|
-
}
|
|
845
|
-
const url = parseURL(fsSpec);
|
|
846
|
-
if (url?.protocol === "file:") {
|
|
847
|
-
return {
|
|
848
|
-
remote: false,
|
|
849
|
-
uri: fsSpec
|
|
850
|
-
};
|
|
851
|
-
}
|
|
852
|
-
const patterns2 = [
|
|
853
|
-
{
|
|
854
|
-
// CIFS/SMB pattern: //hostname/share or //user@host/share
|
|
855
|
-
regex: /^\/\/(?:(?<remoteUser>[^/@]+)@)?(?<remoteHost>[^/@]+)\/(?<remoteShare>.+)$/
|
|
856
|
-
},
|
|
857
|
-
{
|
|
858
|
-
// sshfs pattern: sshfs#USER@HOST:REMOTE_PATH
|
|
859
|
-
regex: /^(?:(?<protocol>\w+)#)?(?<remoteUser>[^@]+)@(?<remoteHost>[^:]+):(?<remoteShare>.+)$/
|
|
860
|
-
},
|
|
861
|
-
{
|
|
862
|
-
// NFS pattern: hostname:/share
|
|
863
|
-
protocol: "nfs",
|
|
864
|
-
regex: /^(?<remoteHost>[^:]+):\/(?!\/)(?<remoteShare>.+)$/
|
|
865
|
-
}
|
|
866
|
-
];
|
|
867
|
-
for (const { protocol, regex } of patterns2) {
|
|
868
|
-
const o = compactValues({
|
|
869
|
-
protocol,
|
|
870
|
-
remote: true,
|
|
871
|
-
...fsSpec.match(regex)?.groups ?? {}
|
|
872
|
-
});
|
|
873
|
-
if (isRemoteInfo(o)) {
|
|
874
|
-
debug("[extractRemoteInfo] matched pattern: %o", o);
|
|
875
|
-
return o;
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
try {
|
|
879
|
-
const parsed = new URL(fsSpec);
|
|
880
|
-
if (parsed != null) {
|
|
881
|
-
debug("[extractRemoteInfo] parsed URL: %o", parsed);
|
|
882
|
-
const fstype = normalizeFsType(parsed.protocol);
|
|
883
|
-
if (!isRemoteFsType(fstype)) {
|
|
884
|
-
return {
|
|
885
|
-
uri: fsSpec,
|
|
886
|
-
remote: false
|
|
887
|
-
};
|
|
888
|
-
} else {
|
|
889
|
-
return compactValues({
|
|
890
|
-
uri: fsSpec,
|
|
891
|
-
protocol: fstype,
|
|
892
|
-
remote: true,
|
|
893
|
-
remoteUser: parsed.username,
|
|
894
|
-
remoteHost: parsed.hostname,
|
|
895
|
-
// URL pathname includes leading slash:
|
|
896
|
-
remoteShare: parsed.pathname.replace(/^\//, "")
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
} catch {
|
|
901
|
-
}
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
// src/glob.ts
|
|
906
|
-
var cache = /* @__PURE__ */ new Map();
|
|
907
|
-
function compileGlob(patterns2) {
|
|
908
|
-
if (patterns2 == null || patterns2.length === 0) {
|
|
909
|
-
return NeverMatchRE;
|
|
910
|
-
}
|
|
911
|
-
const patternsKey = JSON.stringify(patterns2);
|
|
912
|
-
{
|
|
913
|
-
const prior = cache.get(patternsKey);
|
|
914
|
-
if (prior != null) {
|
|
915
|
-
return prior;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
const sorted = patterns2.slice().filter(isNotBlank).sort();
|
|
919
|
-
const sortedKey = JSON.stringify(sorted);
|
|
920
|
-
{
|
|
921
|
-
const prior = cache.get(sortedKey);
|
|
922
|
-
if (prior != null) {
|
|
923
|
-
cache.set(patternsKey, prior);
|
|
924
|
-
return prior;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
const result = _compileGlob(sorted);
|
|
928
|
-
if (cache.size > 256) {
|
|
929
|
-
cache.clear();
|
|
930
|
-
}
|
|
931
|
-
cache.set(patternsKey, result);
|
|
932
|
-
cache.set(sortedKey, result);
|
|
933
|
-
return result;
|
|
934
|
-
}
|
|
935
|
-
function _compileGlob(patterns2) {
|
|
936
|
-
const regexPatterns = patterns2.map((pattern) => {
|
|
937
|
-
let regex = "";
|
|
938
|
-
let i = 0;
|
|
939
|
-
while (i < pattern.length) {
|
|
940
|
-
if (pattern[i] === "*" && pattern[i + 1] === "*") {
|
|
941
|
-
regex += ".*";
|
|
942
|
-
i += 2;
|
|
943
|
-
if (pattern[i] === "/") {
|
|
944
|
-
i++;
|
|
945
|
-
}
|
|
946
|
-
continue;
|
|
947
|
-
}
|
|
948
|
-
if (pattern[i] === "*") {
|
|
949
|
-
regex += "[^/]*";
|
|
950
|
-
i++;
|
|
951
|
-
continue;
|
|
952
|
-
}
|
|
953
|
-
if (pattern[i] === "?") {
|
|
954
|
-
regex += "[^/]";
|
|
955
|
-
i++;
|
|
956
|
-
continue;
|
|
957
|
-
}
|
|
958
|
-
if (pattern[i] === ".") {
|
|
959
|
-
regex += "\\.";
|
|
960
|
-
i++;
|
|
961
|
-
continue;
|
|
962
|
-
}
|
|
963
|
-
if (pattern[i] === "/") {
|
|
964
|
-
if (i === pattern.length - 1) {
|
|
965
|
-
regex += "(?:/|$)";
|
|
966
|
-
i++;
|
|
967
|
-
continue;
|
|
968
|
-
} else if (isWindows) {
|
|
969
|
-
regex += "[\\/\\\\]";
|
|
970
|
-
i++;
|
|
971
|
-
continue;
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
if (/[+^${}()|[\]\\]/.test(pattern[i])) {
|
|
975
|
-
regex += "\\" + pattern[i];
|
|
976
|
-
i++;
|
|
977
|
-
continue;
|
|
978
|
-
}
|
|
979
|
-
regex += pattern[i];
|
|
980
|
-
i++;
|
|
981
|
-
}
|
|
982
|
-
return regex;
|
|
983
|
-
});
|
|
984
|
-
const final = regexPatterns.filter((ea) => ea.length > 0);
|
|
985
|
-
return final.length === 0 ? (
|
|
986
|
-
// Empty pattern matches nothing
|
|
987
|
-
NeverMatchRE
|
|
988
|
-
) : new RegExp(`^(?:${final.join("|")})$`, "i");
|
|
989
|
-
}
|
|
990
|
-
var NeverMatchRE = /(?!)/;
|
|
991
|
-
|
|
992
|
-
// src/system_volume.ts
|
|
993
|
-
function isSystemVolume(mountPoint, fstype, config = {}) {
|
|
994
|
-
if (isWindows) {
|
|
995
|
-
const systemDrive = normalizePath(process.env["SystemDrive"]);
|
|
996
|
-
if (systemDrive != null && mountPoint === systemDrive) {
|
|
997
|
-
debug("[isSystemVolume] %s is the Windows system drive", mountPoint);
|
|
998
|
-
return true;
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
const isSystemFsType = isNotBlank(fstype) && (config.systemFsTypes ?? SystemFsTypesDefault).includes(
|
|
1002
|
-
fstype
|
|
1003
|
-
);
|
|
1004
|
-
const hasSystemPath = compileGlob(
|
|
1005
|
-
config.systemPathPatterns ?? SystemPathPatternsDefault
|
|
1006
|
-
).test(mountPoint);
|
|
1007
|
-
const result = isSystemFsType || hasSystemPath;
|
|
1008
|
-
debug("[isSystemVolume]", {
|
|
1009
|
-
mountPoint,
|
|
1010
|
-
fstype,
|
|
1011
|
-
result,
|
|
1012
|
-
isSystemFsType,
|
|
1013
|
-
hasSystemPath
|
|
1014
|
-
});
|
|
1015
|
-
return result;
|
|
1016
|
-
}
|
|
1017
|
-
function assignSystemVolume(mp, config) {
|
|
1018
|
-
const result = isSystemVolume(mp.mountPoint, mp.fstype, config);
|
|
1019
|
-
if (isWindows) {
|
|
1020
|
-
mp.isSystemVolume ??= result;
|
|
1021
|
-
} else {
|
|
1022
|
-
mp.isSystemVolume = result;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
// src/linux/mtab.ts
|
|
1027
|
-
function mountEntryToMountPoint(entry) {
|
|
1028
|
-
const mountPoint = normalizePosixPath(entry.fs_file);
|
|
1029
|
-
const fstype = toNotBlank(entry.fs_vfstype) ?? toNotBlank(entry.fs_spec);
|
|
1030
|
-
return mountPoint == null || fstype == null ? void 0 : {
|
|
1031
|
-
mountPoint,
|
|
1032
|
-
fstype
|
|
1033
|
-
};
|
|
1034
|
-
}
|
|
1035
|
-
function mountEntryToPartialVolumeMetadata(entry, options = {}) {
|
|
1036
|
-
return {
|
|
1037
|
-
mountPoint: entry.fs_file,
|
|
1038
|
-
fstype: entry.fs_vfstype,
|
|
1039
|
-
mountFrom: entry.fs_spec,
|
|
1040
|
-
isSystemVolume: isSystemVolume(entry.fs_file, entry.fs_vfstype, options),
|
|
1041
|
-
remote: false,
|
|
1042
|
-
// < default to false, but it may be overridden by extractRemoteInfo
|
|
1043
|
-
...extractRemoteInfo(entry.fs_spec)
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function parseMtab(content) {
|
|
1047
|
-
const entries = [];
|
|
1048
|
-
const lines = content.split("\n");
|
|
1049
|
-
for (const line of lines) {
|
|
1050
|
-
if (isBlank(line) || line.trim().startsWith("#")) {
|
|
1051
|
-
continue;
|
|
1052
|
-
}
|
|
1053
|
-
const fields = line.trim().match(/(?:[^\s\\]|\\.)+/g)?.map(decodeEscapeSequences);
|
|
1054
|
-
if (!fields || fields.length < 3) {
|
|
1055
|
-
continue;
|
|
1056
|
-
}
|
|
1057
|
-
const fs_file = normalizePosixPath(fields[1]);
|
|
1058
|
-
if (fs_file != null) {
|
|
1059
|
-
entries.push({
|
|
1060
|
-
fs_spec: fields[0],
|
|
1061
|
-
// normalizeLinuxPath DOES NOT resolve()!
|
|
1062
|
-
fs_file,
|
|
1063
|
-
fs_vfstype: fields[2],
|
|
1064
|
-
fs_mntops: fields[3],
|
|
1065
|
-
fs_freq: toInt(fields[4]),
|
|
1066
|
-
fs_passno: toInt(fields[5])
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
return entries;
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
// src/linux/mount_points.ts
|
|
1074
|
-
async function getLinuxMountPoints(native, opts) {
|
|
1075
|
-
const o = optionsWithDefaults(opts);
|
|
1076
|
-
const raw = [];
|
|
1077
|
-
try {
|
|
1078
|
-
const arr = await (await native()).getGioMountPoints?.();
|
|
1079
|
-
debug("[getLinuxMountPoints] GIO mount points: %o", arr);
|
|
1080
|
-
if (arr != null) raw.push(...arr);
|
|
1081
|
-
} catch (error) {
|
|
1082
|
-
debug("Failed to get GIO mount points: %s", error);
|
|
1083
|
-
}
|
|
1084
|
-
let cause;
|
|
1085
|
-
for (const input of o.linuxMountTablePaths) {
|
|
1086
|
-
try {
|
|
1087
|
-
const mtabContent = await (0, import_promises4.readFile)(input, "utf8");
|
|
1088
|
-
const arr = parseMtab(mtabContent).map((ea) => mountEntryToMountPoint(ea)).filter((ea) => ea != null);
|
|
1089
|
-
debug("[getLinuxMountPoints] %s mount points: %o", input, arr);
|
|
1090
|
-
if (arr.length > 0) {
|
|
1091
|
-
raw.push(...arr);
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
} catch (error) {
|
|
1095
|
-
cause ??= toError(error);
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
const byMountPoint = /* @__PURE__ */ new Map();
|
|
1099
|
-
for (const ea of raw) {
|
|
1100
|
-
const prior = byMountPoint.get(ea.mountPoint);
|
|
1101
|
-
const merged = { ...compactValues(prior), ...compactValues(ea) };
|
|
1102
|
-
if (isMountPoint(merged)) {
|
|
1103
|
-
byMountPoint.set(merged.mountPoint, merged);
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
if (byMountPoint.size === 0) {
|
|
1107
|
-
throw new WrappedError(
|
|
1108
|
-
`Failed to find any mount points (tried: ${JSON.stringify(o.linuxMountTablePaths)})`,
|
|
1109
|
-
{ cause }
|
|
1110
|
-
);
|
|
1111
|
-
}
|
|
1112
|
-
const results = [...byMountPoint.values()];
|
|
1113
|
-
debug("[getLinuxMountPoints] %o", {
|
|
1114
|
-
results: results.map((ea) => ea.mountPoint)
|
|
1115
|
-
});
|
|
1116
|
-
return results;
|
|
1117
|
-
}
|
|
1118
|
-
async function getLinuxMtabMetadata(mountPoint, opts) {
|
|
1119
|
-
let caughtError;
|
|
1120
|
-
const inputs = optionsWithDefaults(opts).linuxMountTablePaths;
|
|
1121
|
-
for (const input of inputs) {
|
|
1122
|
-
try {
|
|
1123
|
-
const mtabContent = await (0, import_promises4.readFile)(input, "utf8");
|
|
1124
|
-
for (const ea of parseMtab(mtabContent)) {
|
|
1125
|
-
if (ea.fs_file === mountPoint) {
|
|
1126
|
-
return ea;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
} catch (error) {
|
|
1130
|
-
caughtError ??= toError(error);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
throw new WrappedError(
|
|
1134
|
-
`Failed to find mount point ${mountPoint} in an linuxMountTablePaths (tried: ${JSON.stringify(inputs)})`,
|
|
1135
|
-
caughtError
|
|
1136
|
-
);
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
// src/unc.ts
|
|
1140
|
-
function parseUNCPath(path) {
|
|
1141
|
-
if (path == null || isBlank(path) || !isString(path)) {
|
|
1142
|
-
return;
|
|
1143
|
-
}
|
|
1144
|
-
if (!path.startsWith("\\\\") && !path.startsWith("//")) {
|
|
1145
|
-
return;
|
|
1146
|
-
}
|
|
1147
|
-
const isForwardSlash = path.startsWith("//");
|
|
1148
|
-
const slashChar = isForwardSlash ? "/" : "\\";
|
|
1149
|
-
const parts = path.slice(2).split(slashChar);
|
|
1150
|
-
if (parts.length < 2) {
|
|
1151
|
-
return;
|
|
1152
|
-
}
|
|
1153
|
-
const [remoteHost, remoteShare] = parts;
|
|
1154
|
-
if (remoteHost == null || isBlank(remoteHost) || remoteShare == null || isBlank(remoteShare)) {
|
|
1155
|
-
return;
|
|
1156
|
-
}
|
|
1157
|
-
const invalidChars = /[<>:"|?*]/;
|
|
1158
|
-
if (invalidChars.test(remoteHost) || invalidChars.test(remoteShare)) {
|
|
1159
|
-
return;
|
|
1160
|
-
}
|
|
1161
|
-
const wrongSlash = isForwardSlash ? "\\" : "/";
|
|
1162
|
-
if (path.includes(wrongSlash)) {
|
|
1163
|
-
return;
|
|
1164
|
-
}
|
|
1165
|
-
return { remoteHost, remoteShare, remote: true };
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
// src/uuid.ts
|
|
1169
|
-
var uuidRegex = /[a-z0-9][a-z0-9-]{7,}/i;
|
|
1170
|
-
function extractUUID(uuid) {
|
|
1171
|
-
return toS(uuid).match(uuidRegex)?.[0];
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
// src/array.ts
|
|
1175
|
-
function uniqBy(arr, keyFn) {
|
|
1176
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1177
|
-
return arr.filter((item) => {
|
|
1178
|
-
const key = keyFn(item);
|
|
1179
|
-
if (key == null || seen.has(key)) return false;
|
|
1180
|
-
seen.add(key);
|
|
1181
|
-
return true;
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
// src/volume_mount_points.ts
|
|
1186
|
-
async function getVolumeMountPointsImpl(opts, nativeFn2) {
|
|
1187
|
-
const p = _getVolumeMountPoints(opts, nativeFn2);
|
|
1188
|
-
return isWindows ? p : withTimeout({ desc: "getVolumeMountPoints", ...opts, promise: p });
|
|
1189
|
-
}
|
|
1190
|
-
async function _getVolumeMountPoints(o, nativeFn2) {
|
|
1191
|
-
debug("[getVolumeMountPoints] gathering mount points with options: %o", o);
|
|
1192
|
-
const raw = await (isWindows || isMacOS ? (async () => {
|
|
1193
|
-
debug("[getVolumeMountPoints] using native implementation");
|
|
1194
|
-
const points = await (await nativeFn2()).getVolumeMountPoints(o);
|
|
1195
|
-
debug(
|
|
1196
|
-
"[getVolumeMountPoints] native returned %d mount points",
|
|
1197
|
-
points.length
|
|
1198
|
-
);
|
|
1199
|
-
return points;
|
|
1200
|
-
})() : getLinuxMountPoints(nativeFn2, o));
|
|
1201
|
-
debug("[getVolumeMountPoints] raw mount points: %o", raw);
|
|
1202
|
-
const compacted = raw.map((ea) => compactValues(ea)).filter((ea) => isNotBlank(ea.mountPoint));
|
|
1203
|
-
for (const ea of compacted) {
|
|
1204
|
-
assignSystemVolume(ea, o);
|
|
1205
|
-
}
|
|
1206
|
-
const filtered = o.includeSystemVolumes ? compacted : compacted.filter((ea) => !ea.isSystemVolume);
|
|
1207
|
-
const uniq = uniqBy(filtered, (ea) => toNotBlank(ea.mountPoint));
|
|
1208
|
-
debug("[getVolumeMountPoints] found %d unique mount points", uniq.length);
|
|
1209
|
-
const results = sortObjectsByLocale(uniq, (ea) => ea.mountPoint);
|
|
1210
|
-
debug(
|
|
1211
|
-
"[getVolumeMountPoints] getting status for %d mount points",
|
|
1212
|
-
results.length
|
|
1213
|
-
);
|
|
1214
|
-
await mapConcurrent({
|
|
1215
|
-
maxConcurrency: o.maxConcurrency,
|
|
1216
|
-
items: results.filter(
|
|
1217
|
-
// trust but verify
|
|
1218
|
-
(ea) => isBlank(ea.status) || ea.status === "healthy"
|
|
1219
|
-
),
|
|
1220
|
-
fn: async (mp) => {
|
|
1221
|
-
debug("[getVolumeMountPoints] checking status of %s", mp.mountPoint);
|
|
1222
|
-
mp.status = (await directoryStatus(mp.mountPoint, o.timeoutMs)).status;
|
|
1223
|
-
debug(
|
|
1224
|
-
"[getVolumeMountPoints] status for %s: %s",
|
|
1225
|
-
mp.mountPoint,
|
|
1226
|
-
mp.status
|
|
1227
|
-
);
|
|
1228
|
-
}
|
|
1229
|
-
});
|
|
1230
|
-
debug(
|
|
1231
|
-
"[getVolumeMountPoints] completed with %d mount points",
|
|
1232
|
-
results.length
|
|
1233
|
-
);
|
|
1234
|
-
return results;
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
// src/volume_metadata.ts
|
|
1238
|
-
async function getVolumeMetadataImpl(o, nativeFn2) {
|
|
1239
|
-
if (isBlank(o.mountPoint)) {
|
|
1240
|
-
throw new TypeError(
|
|
1241
|
-
"Invalid mountPoint: got " + JSON.stringify(o.mountPoint)
|
|
1242
|
-
);
|
|
1243
|
-
}
|
|
1244
|
-
const p = _getVolumeMetadata(o, nativeFn2);
|
|
1245
|
-
return isWindows ? p : withTimeout({
|
|
1246
|
-
desc: "getVolumeMetadata()",
|
|
1247
|
-
timeoutMs: o.timeoutMs,
|
|
1248
|
-
promise: p
|
|
1249
|
-
});
|
|
1250
|
-
}
|
|
1251
|
-
async function _getVolumeMetadata(o, nativeFn2) {
|
|
1252
|
-
o = optionsWithDefaults(o);
|
|
1253
|
-
const norm = normalizePath(o.mountPoint);
|
|
1254
|
-
if (norm == null) {
|
|
1255
|
-
throw new Error("Invalid mountPoint: " + JSON.stringify(o.mountPoint));
|
|
1256
|
-
}
|
|
1257
|
-
o.mountPoint = norm;
|
|
1258
|
-
debug(
|
|
1259
|
-
"[getVolumeMetadata] starting metadata collection for %s",
|
|
1260
|
-
o.mountPoint
|
|
1261
|
-
);
|
|
1262
|
-
debug("[getVolumeMetadata] options: %o", o);
|
|
1263
|
-
const { status, error } = await directoryStatus(o.mountPoint, o.timeoutMs);
|
|
1264
|
-
if (status !== VolumeHealthStatuses.healthy) {
|
|
1265
|
-
debug("[getVolumeMetadata] directoryStatus error: %s", error);
|
|
1266
|
-
throw error ?? new Error("Volume not healthy: " + status);
|
|
1267
|
-
}
|
|
1268
|
-
debug("[getVolumeMetadata] readdir status: %s", status);
|
|
1269
|
-
let remote = false;
|
|
1270
|
-
let mtabInfo;
|
|
1271
|
-
let device;
|
|
1272
|
-
if (isLinux) {
|
|
1273
|
-
debug("[getVolumeMetadata] collecting Linux mtab info");
|
|
1274
|
-
try {
|
|
1275
|
-
const m = await getLinuxMtabMetadata(o.mountPoint, o);
|
|
1276
|
-
mtabInfo = mountEntryToPartialVolumeMetadata(m, o);
|
|
1277
|
-
debug("[getVolumeMetadata] mtab info: %o", mtabInfo);
|
|
1278
|
-
if (mtabInfo.remote) {
|
|
1279
|
-
remote = true;
|
|
1280
|
-
}
|
|
1281
|
-
if (isNotBlank(m.fs_spec)) {
|
|
1282
|
-
device = m.fs_spec;
|
|
1283
|
-
}
|
|
1284
|
-
} catch (err) {
|
|
1285
|
-
debug("[getVolumeMetadata] failed to get mtab info: " + err);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
if (isNotBlank(device)) {
|
|
1289
|
-
o.device = device;
|
|
1290
|
-
debug("[getVolumeMetadata] using device: %s", device);
|
|
1291
|
-
}
|
|
1292
|
-
debug("[getVolumeMetadata] requesting native metadata");
|
|
1293
|
-
const metadata = await (await nativeFn2()).getVolumeMetadata(o);
|
|
1294
|
-
debug("[getVolumeMetadata] native metadata: %o", metadata);
|
|
1295
|
-
const remoteInfo = mtabInfo ?? extractRemoteInfo(metadata.uri) ?? extractRemoteInfo(metadata.mountFrom) ?? (isWindows ? parseUNCPath(o.mountPoint) : void 0);
|
|
1296
|
-
debug("[getVolumeMetadata] extracted remote info: %o", remoteInfo);
|
|
1297
|
-
remote ||= isRemoteFsType(metadata.fstype) || (remoteInfo?.remote ?? metadata.remote ?? false);
|
|
1298
|
-
debug("[getVolumeMetadata] assembling: %o", {
|
|
1299
|
-
status,
|
|
1300
|
-
mtabInfo,
|
|
1301
|
-
remoteInfo,
|
|
1302
|
-
metadata,
|
|
1303
|
-
mountPoint: o.mountPoint,
|
|
1304
|
-
remote
|
|
1305
|
-
});
|
|
1306
|
-
const result = compactValues({
|
|
1307
|
-
status,
|
|
1308
|
-
// < let the implementation's status win by having this first
|
|
1309
|
-
...compactValues(remoteInfo),
|
|
1310
|
-
...compactValues(metadata),
|
|
1311
|
-
...compactValues(mtabInfo),
|
|
1312
|
-
mountPoint: o.mountPoint,
|
|
1313
|
-
remote
|
|
1314
|
-
});
|
|
1315
|
-
if (isLinux && isNotBlank(device)) {
|
|
1316
|
-
result.uuid ??= await getUuidFromDevDisk(device) ?? "";
|
|
1317
|
-
result.label ??= await getLabelFromDevDisk(device) ?? "";
|
|
1318
|
-
}
|
|
1319
|
-
assignSystemVolume(result, o);
|
|
1320
|
-
result.uuid = extractUUID(result.uuid) ?? result.uuid ?? "";
|
|
1321
|
-
debug("[getVolumeMetadata] final result for %s: %o", o.mountPoint, result);
|
|
1322
|
-
return compactValues(result);
|
|
1323
|
-
}
|
|
1324
|
-
async function getAllVolumeMetadataImpl(opts, nativeFn2) {
|
|
1325
|
-
const o = optionsWithDefaults(opts);
|
|
1326
|
-
debug("[getAllVolumeMetadata] starting with options: %o", o);
|
|
1327
|
-
const arr = await getVolumeMountPointsImpl(o, nativeFn2);
|
|
1328
|
-
debug("[getAllVolumeMetadata] found %d mount points", arr.length);
|
|
1329
|
-
const unhealthyMountPoints = arr.filter(
|
|
1330
|
-
(ea) => ea.status != null && ea.status !== VolumeHealthStatuses.healthy
|
|
1331
|
-
).map((ea) => ({
|
|
1332
|
-
mountPoint: ea.mountPoint,
|
|
1333
|
-
error: new WrappedError("volume not healthy: " + ea.status, {
|
|
1334
|
-
name: "Skipped"
|
|
1335
|
-
})
|
|
1336
|
-
}));
|
|
1337
|
-
const includeSystemVolumes = opts?.includeSystemVolumes ?? IncludeSystemVolumesDefault;
|
|
1338
|
-
const systemMountPoints = includeSystemVolumes ? [] : arr.filter((ea) => ea.isSystemVolume).map((ea) => ({
|
|
1339
|
-
mountPoint: ea.mountPoint,
|
|
1340
|
-
error: new WrappedError("system volume", { name: "Skipped" })
|
|
1341
|
-
}));
|
|
1342
|
-
const healthy = arr.filter(
|
|
1343
|
-
(ea) => ea.status == null || ea.status === VolumeHealthStatuses.healthy
|
|
1344
|
-
);
|
|
1345
|
-
debug("[getAllVolumeMetadata] ", {
|
|
1346
|
-
allMountPoints: arr.map((ea) => ea.mountPoint),
|
|
1347
|
-
healthyMountPoints: healthy.map((ea) => ea.mountPoint)
|
|
1348
|
-
});
|
|
1349
|
-
debug(
|
|
1350
|
-
"[getAllVolumeMetadata] processing %d healthy volumes with max concurrency %d",
|
|
1351
|
-
healthy.length,
|
|
1352
|
-
o.maxConcurrency
|
|
1353
|
-
);
|
|
1354
|
-
const results = await mapConcurrent({
|
|
1355
|
-
maxConcurrency: o.maxConcurrency,
|
|
1356
|
-
items: opts?.includeSystemVolumes ?? IncludeSystemVolumesDefault ? healthy : healthy.filter((ea) => !ea.isSystemVolume),
|
|
1357
|
-
fn: async (mp) => getVolumeMetadataImpl({ ...mp, ...o }, nativeFn2).catch((error) => ({
|
|
1358
|
-
mountPoint: mp.mountPoint,
|
|
1359
|
-
error
|
|
1360
|
-
}))
|
|
1361
|
-
});
|
|
1362
|
-
debug("[getAllVolumeMetadata] completed processing all volumes");
|
|
1363
|
-
return arr.map(
|
|
1364
|
-
(result) => results.find((ea) => ea.mountPoint === result.mountPoint) ?? unhealthyMountPoints.find(
|
|
1365
|
-
(ea) => ea.mountPoint === result.mountPoint
|
|
1366
|
-
) ?? systemMountPoints.find((ea) => ea.mountPoint === result.mountPoint) ?? {
|
|
1367
|
-
...result,
|
|
1368
|
-
error: new WrappedError("Mount point metadata not retrieved", {
|
|
1369
|
-
name: "NotApplicableError"
|
|
1370
|
-
})
|
|
1371
|
-
}
|
|
1372
|
-
);
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
// src/index.ts
|
|
1376
|
-
var nativeFn = defer2(async () => {
|
|
1377
|
-
const start = Date.now();
|
|
1378
|
-
try {
|
|
1379
|
-
const dirname4 = _dirname();
|
|
1380
|
-
const dir = await findAncestorDir(dirname4, "binding.gyp");
|
|
1381
|
-
if (dir == null) {
|
|
1382
|
-
throw new Error(
|
|
1383
|
-
"Could not find bindings.gyp in any ancestor directory of " + dirname4
|
|
1384
|
-
);
|
|
1385
|
-
}
|
|
1386
|
-
const bindings = (0, import_node_gyp_build.default)(dir);
|
|
1387
|
-
bindings.setDebugLogging(isDebugEnabled());
|
|
1388
|
-
bindings.setDebugPrefix(debugLogContext() + ":native");
|
|
1389
|
-
return bindings;
|
|
1390
|
-
} catch (error) {
|
|
1391
|
-
debug("Loading native bindings failed: %s", error);
|
|
1392
|
-
throw error;
|
|
1393
|
-
} finally {
|
|
1394
|
-
debug(`Native bindings took %d ms to load`, Date.now() - start);
|
|
1395
|
-
}
|
|
1396
|
-
});
|
|
1397
|
-
function getVolumeMountPoints(opts) {
|
|
1398
|
-
return getVolumeMountPointsImpl(optionsWithDefaults(opts), nativeFn);
|
|
1399
|
-
}
|
|
1400
|
-
function getVolumeMetadata(mountPoint, opts) {
|
|
1401
|
-
return getVolumeMetadataImpl(
|
|
1402
|
-
{ ...optionsWithDefaults(opts), mountPoint },
|
|
1403
|
-
nativeFn
|
|
1404
|
-
);
|
|
1405
|
-
}
|
|
1406
|
-
function getAllVolumeMetadata(opts) {
|
|
1407
|
-
return getAllVolumeMetadataImpl(optionsWithDefaults(opts), nativeFn);
|
|
1408
|
-
}
|
|
1409
|
-
function isHidden(pathname) {
|
|
1410
|
-
return isHiddenImpl(pathname, nativeFn);
|
|
1411
|
-
}
|
|
1412
|
-
function isHiddenRecursive(pathname) {
|
|
1413
|
-
return isHiddenRecursiveImpl(pathname, nativeFn);
|
|
1414
|
-
}
|
|
1415
|
-
function getHiddenMetadata(pathname) {
|
|
1416
|
-
return getHiddenMetadataImpl(pathname, nativeFn);
|
|
1417
|
-
}
|
|
1418
|
-
function setHidden(pathname, hidden, method = "auto") {
|
|
1419
|
-
return setHiddenImpl(pathname, hidden, method, nativeFn);
|
|
1420
|
-
}
|
|
1421
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1422
|
-
0 && (module.exports = {
|
|
1423
|
-
IncludeSystemVolumesDefault,
|
|
1424
|
-
LinuxMountTablePathsDefault,
|
|
1425
|
-
OptionsDefault,
|
|
1426
|
-
SystemFsTypesDefault,
|
|
1427
|
-
SystemPathPatternsDefault,
|
|
1428
|
-
TimeoutMsDefault,
|
|
1429
|
-
VolumeHealthStatuses,
|
|
1430
|
-
getAllVolumeMetadata,
|
|
1431
|
-
getHiddenMetadata,
|
|
1432
|
-
getVolumeMetadata,
|
|
1433
|
-
getVolumeMountPoints,
|
|
1434
|
-
isHidden,
|
|
1435
|
-
isHiddenRecursive,
|
|
1436
|
-
optionsWithDefaults,
|
|
1437
|
-
setHidden
|
|
1438
|
-
});
|
|
1439
|
-
//# sourceMappingURL=index.cjs.map
|