@photostructure/fs-metadata 1.2.0 → 1.4.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/CHANGELOG.md +37 -0
- package/CONTRIBUTING.md +3 -3
- package/binding.gyp +0 -22
- package/dist/index.cjs +11 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.mts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.mjs +11 -40
- package/dist/index.mjs.map +1 -1
- package/doc/C++_REVIEW_TODO.md +3 -36
- package/doc/LINUX_API_REFERENCE.md +4 -147
- package/doc/SECURITY_AUDIT_2026.md +5 -0
- package/doc/gotchas.md +27 -0
- package/package.json +9 -10
- package/prebuilds/darwin-arm64/@photostructure+fs-metadata.glibc.node +0 -0
- package/prebuilds/darwin-x64/@photostructure+fs-metadata.glibc.node +0 -0
- package/prebuilds/linux-arm64/@photostructure+fs-metadata.glibc.node +0 -0
- package/prebuilds/linux-x64/@photostructure+fs-metadata.glibc.node +0 -0
- package/prebuilds/win32-arm64/@photostructure+fs-metadata.glibc.node +0 -0
- package/prebuilds/win32-x64/@photostructure+fs-metadata.glibc.node +0 -0
- package/scripts/clang-tidy.ts +1 -3
- package/scripts/prebuild-linux-glibc.sh +1 -5
- package/scripts/sanitizers-test.sh +0 -1
- package/src/binding.cpp +0 -15
- package/src/index.ts +6 -2
- package/src/linux/mount_points.ts +8 -42
- package/src/linux/volume_metadata.cpp +0 -16
- package/src/mount_point_for_path.ts +1 -1
- package/src/types/mount_point.ts +1 -1
- package/src/types/native_bindings.ts +0 -5
- package/src/types/options.ts +14 -0
- package/src/volume_metadata.ts +22 -11
- package/src/volume_mount_points.ts +1 -1
- package/scripts/setup-native.mjs +0 -39
- package/src/linux/gio_mount_points.cpp +0 -80
- package/src/linux/gio_mount_points.h +0 -37
- package/src/linux/gio_utils.cpp +0 -115
- package/src/linux/gio_utils.h +0 -69
- package/src/linux/gio_volume_metadata.cpp +0 -81
- package/src/linux/gio_volume_metadata.h +0 -20
package/dist/index.d.cts
CHANGED
|
@@ -79,7 +79,7 @@ interface MountPoint {
|
|
|
79
79
|
* verifyVolume`.
|
|
80
80
|
*
|
|
81
81
|
* If there are non-critical errors while extracting metadata, those error
|
|
82
|
-
* messages may be added to this field (say, from blkid
|
|
82
|
+
* messages may be added to this field (say, from blkid).
|
|
83
83
|
*
|
|
84
84
|
* @see {@link VolumeHealthStatuses} for values returned by Windows.
|
|
85
85
|
*/
|
|
@@ -132,6 +132,18 @@ interface MountPoint {
|
|
|
132
132
|
* @see {@link OptionsDefault} for the default values
|
|
133
133
|
*/
|
|
134
134
|
interface Options {
|
|
135
|
+
/**
|
|
136
|
+
* Pre-fetched mount points to use instead of querying the system.
|
|
137
|
+
*
|
|
138
|
+
* When provided, functions like {@link getMountPointForPath} and
|
|
139
|
+
* {@link getVolumeMetadataForPath} will use these mount points for device ID
|
|
140
|
+
* matching instead of calling {@link getVolumeMountPoints} internally. This
|
|
141
|
+
* avoids redundant system queries when resolving multiple paths.
|
|
142
|
+
*
|
|
143
|
+
* Obtain via `getVolumeMountPoints({ includeSystemVolumes: true })` — system
|
|
144
|
+
* volumes must be included for device ID matching to work correctly.
|
|
145
|
+
*/
|
|
146
|
+
mountPoints?: MountPoint[];
|
|
135
147
|
/**
|
|
136
148
|
* Timeout in milliseconds for filesystem operations.
|
|
137
149
|
*
|
|
@@ -367,7 +379,7 @@ declare function getVolumeMetadata(mountPoint: string, opts?: Partial<Pick<Optio
|
|
|
367
379
|
* @param pathname Path to any file or directory
|
|
368
380
|
* @param opts Optional filesystem operation settings
|
|
369
381
|
*/
|
|
370
|
-
declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths">>): Promise<VolumeMetadata>;
|
|
382
|
+
declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths" | "mountPoints">>): Promise<VolumeMetadata>;
|
|
371
383
|
/**
|
|
372
384
|
* Get the mount point path for an arbitrary file or directory path.
|
|
373
385
|
*
|
|
@@ -383,7 +395,7 @@ declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<
|
|
|
383
395
|
* @param opts Optional settings (timeoutMs, linuxMountTablePaths)
|
|
384
396
|
* @returns The mount point path (e.g., "/", "/System/Volumes/Data", "C:\\")
|
|
385
397
|
*/
|
|
386
|
-
declare function getMountPointForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths">>): Promise<string>;
|
|
398
|
+
declare function getMountPointForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths" | "mountPoints">>): Promise<string>;
|
|
387
399
|
/**
|
|
388
400
|
* Retrieves metadata for all mounted volumes with optional filtering and
|
|
389
401
|
* concurrency control.
|
package/dist/index.d.mts
CHANGED
|
@@ -79,7 +79,7 @@ interface MountPoint {
|
|
|
79
79
|
* verifyVolume`.
|
|
80
80
|
*
|
|
81
81
|
* If there are non-critical errors while extracting metadata, those error
|
|
82
|
-
* messages may be added to this field (say, from blkid
|
|
82
|
+
* messages may be added to this field (say, from blkid).
|
|
83
83
|
*
|
|
84
84
|
* @see {@link VolumeHealthStatuses} for values returned by Windows.
|
|
85
85
|
*/
|
|
@@ -132,6 +132,18 @@ interface MountPoint {
|
|
|
132
132
|
* @see {@link OptionsDefault} for the default values
|
|
133
133
|
*/
|
|
134
134
|
interface Options {
|
|
135
|
+
/**
|
|
136
|
+
* Pre-fetched mount points to use instead of querying the system.
|
|
137
|
+
*
|
|
138
|
+
* When provided, functions like {@link getMountPointForPath} and
|
|
139
|
+
* {@link getVolumeMetadataForPath} will use these mount points for device ID
|
|
140
|
+
* matching instead of calling {@link getVolumeMountPoints} internally. This
|
|
141
|
+
* avoids redundant system queries when resolving multiple paths.
|
|
142
|
+
*
|
|
143
|
+
* Obtain via `getVolumeMountPoints({ includeSystemVolumes: true })` — system
|
|
144
|
+
* volumes must be included for device ID matching to work correctly.
|
|
145
|
+
*/
|
|
146
|
+
mountPoints?: MountPoint[];
|
|
135
147
|
/**
|
|
136
148
|
* Timeout in milliseconds for filesystem operations.
|
|
137
149
|
*
|
|
@@ -367,7 +379,7 @@ declare function getVolumeMetadata(mountPoint: string, opts?: Partial<Pick<Optio
|
|
|
367
379
|
* @param pathname Path to any file or directory
|
|
368
380
|
* @param opts Optional filesystem operation settings
|
|
369
381
|
*/
|
|
370
|
-
declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths">>): Promise<VolumeMetadata>;
|
|
382
|
+
declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths" | "mountPoints">>): Promise<VolumeMetadata>;
|
|
371
383
|
/**
|
|
372
384
|
* Get the mount point path for an arbitrary file or directory path.
|
|
373
385
|
*
|
|
@@ -383,7 +395,7 @@ declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<
|
|
|
383
395
|
* @param opts Optional settings (timeoutMs, linuxMountTablePaths)
|
|
384
396
|
* @returns The mount point path (e.g., "/", "/System/Volumes/Data", "C:\\")
|
|
385
397
|
*/
|
|
386
|
-
declare function getMountPointForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths">>): Promise<string>;
|
|
398
|
+
declare function getMountPointForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths" | "mountPoints">>): Promise<string>;
|
|
387
399
|
/**
|
|
388
400
|
* Retrieves metadata for all mounted volumes with optional filtering and
|
|
389
401
|
* concurrency control.
|
package/dist/index.d.ts
CHANGED
|
@@ -79,7 +79,7 @@ interface MountPoint {
|
|
|
79
79
|
* verifyVolume`.
|
|
80
80
|
*
|
|
81
81
|
* If there are non-critical errors while extracting metadata, those error
|
|
82
|
-
* messages may be added to this field (say, from blkid
|
|
82
|
+
* messages may be added to this field (say, from blkid).
|
|
83
83
|
*
|
|
84
84
|
* @see {@link VolumeHealthStatuses} for values returned by Windows.
|
|
85
85
|
*/
|
|
@@ -132,6 +132,18 @@ interface MountPoint {
|
|
|
132
132
|
* @see {@link OptionsDefault} for the default values
|
|
133
133
|
*/
|
|
134
134
|
interface Options {
|
|
135
|
+
/**
|
|
136
|
+
* Pre-fetched mount points to use instead of querying the system.
|
|
137
|
+
*
|
|
138
|
+
* When provided, functions like {@link getMountPointForPath} and
|
|
139
|
+
* {@link getVolumeMetadataForPath} will use these mount points for device ID
|
|
140
|
+
* matching instead of calling {@link getVolumeMountPoints} internally. This
|
|
141
|
+
* avoids redundant system queries when resolving multiple paths.
|
|
142
|
+
*
|
|
143
|
+
* Obtain via `getVolumeMountPoints({ includeSystemVolumes: true })` — system
|
|
144
|
+
* volumes must be included for device ID matching to work correctly.
|
|
145
|
+
*/
|
|
146
|
+
mountPoints?: MountPoint[];
|
|
135
147
|
/**
|
|
136
148
|
* Timeout in milliseconds for filesystem operations.
|
|
137
149
|
*
|
|
@@ -367,7 +379,7 @@ declare function getVolumeMetadata(mountPoint: string, opts?: Partial<Pick<Optio
|
|
|
367
379
|
* @param pathname Path to any file or directory
|
|
368
380
|
* @param opts Optional filesystem operation settings
|
|
369
381
|
*/
|
|
370
|
-
declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths">>): Promise<VolumeMetadata>;
|
|
382
|
+
declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths" | "mountPoints">>): Promise<VolumeMetadata>;
|
|
371
383
|
/**
|
|
372
384
|
* Get the mount point path for an arbitrary file or directory path.
|
|
373
385
|
*
|
|
@@ -383,7 +395,7 @@ declare function getVolumeMetadataForPath(pathname: string, opts?: Partial<Pick<
|
|
|
383
395
|
* @param opts Optional settings (timeoutMs, linuxMountTablePaths)
|
|
384
396
|
* @returns The mount point path (e.g., "/", "/System/Volumes/Data", "C:\\")
|
|
385
397
|
*/
|
|
386
|
-
declare function getMountPointForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths">>): Promise<string>;
|
|
398
|
+
declare function getMountPointForPath(pathname: string, opts?: Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths" | "mountPoints">>): Promise<string>;
|
|
387
399
|
/**
|
|
388
400
|
* Retrieves metadata for all mounted volumes with optional filtering and
|
|
389
401
|
* concurrency control.
|
package/dist/index.mjs
CHANGED
|
@@ -649,11 +649,6 @@ async function* readLinks(directory) {
|
|
|
649
649
|
// src/linux/mount_points.ts
|
|
650
650
|
import { readFile } from "fs/promises";
|
|
651
651
|
|
|
652
|
-
// src/mount_point.ts
|
|
653
|
-
function isMountPoint(obj) {
|
|
654
|
-
return isObject(obj) && "mountPoint" in obj && isNotBlank(obj.mountPoint);
|
|
655
|
-
}
|
|
656
|
-
|
|
657
652
|
// src/options.ts
|
|
658
653
|
import { availableParallelism as availableParallelism2 } from "os";
|
|
659
654
|
import { env as env2 } from "process";
|
|
@@ -1135,49 +1130,25 @@ function parseMtab(content) {
|
|
|
1135
1130
|
}
|
|
1136
1131
|
|
|
1137
1132
|
// src/linux/mount_points.ts
|
|
1138
|
-
async function getLinuxMountPoints(
|
|
1133
|
+
async function getLinuxMountPoints(opts) {
|
|
1139
1134
|
const o = optionsWithDefaults(opts);
|
|
1140
|
-
const raw = [];
|
|
1141
|
-
try {
|
|
1142
|
-
const arr = await (await native()).getGioMountPoints?.();
|
|
1143
|
-
debug("[getLinuxMountPoints] GIO mount points: %o", arr);
|
|
1144
|
-
if (arr != null) raw.push(...arr);
|
|
1145
|
-
} catch (error) {
|
|
1146
|
-
debug("Failed to get GIO mount points: %s", error);
|
|
1147
|
-
}
|
|
1148
1135
|
let cause;
|
|
1149
1136
|
for (const input of o.linuxMountTablePaths) {
|
|
1150
1137
|
try {
|
|
1151
1138
|
const mtabContent = await readFile(input, "utf8");
|
|
1152
|
-
const
|
|
1153
|
-
debug("[getLinuxMountPoints] %s mount points: %o", input,
|
|
1154
|
-
if (
|
|
1155
|
-
|
|
1156
|
-
break;
|
|
1139
|
+
const results = parseMtab(mtabContent).map((ea) => mountEntryToMountPoint(ea)).filter((ea) => ea != null);
|
|
1140
|
+
debug("[getLinuxMountPoints] %s mount points: %o", input, results);
|
|
1141
|
+
if (results.length > 0) {
|
|
1142
|
+
return results;
|
|
1157
1143
|
}
|
|
1158
1144
|
} catch (error) {
|
|
1159
1145
|
cause ??= toError(error);
|
|
1160
1146
|
}
|
|
1161
1147
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
if (isMountPoint(merged)) {
|
|
1167
|
-
byMountPoint.set(merged.mountPoint, merged);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
if (byMountPoint.size === 0) {
|
|
1171
|
-
throw new WrappedError(
|
|
1172
|
-
`Failed to find any mount points (tried: ${JSON.stringify(o.linuxMountTablePaths)})`,
|
|
1173
|
-
{ cause }
|
|
1174
|
-
);
|
|
1175
|
-
}
|
|
1176
|
-
const results = [...byMountPoint.values()];
|
|
1177
|
-
debug("[getLinuxMountPoints] %o", {
|
|
1178
|
-
results: results.map((ea) => ea.mountPoint)
|
|
1179
|
-
});
|
|
1180
|
-
return results;
|
|
1148
|
+
throw new WrappedError(
|
|
1149
|
+
`Failed to find any mount points (tried: ${JSON.stringify(o.linuxMountTablePaths)})`,
|
|
1150
|
+
{ cause }
|
|
1151
|
+
);
|
|
1181
1152
|
}
|
|
1182
1153
|
async function getLinuxMtabMetadata(mountPoint, opts) {
|
|
1183
1154
|
let caughtError;
|
|
@@ -1304,7 +1275,7 @@ async function _getVolumeMountPoints(o, nativeFn2) {
|
|
|
1304
1275
|
points.length
|
|
1305
1276
|
);
|
|
1306
1277
|
return points;
|
|
1307
|
-
})() : getLinuxMountPoints(
|
|
1278
|
+
})() : getLinuxMountPoints(o));
|
|
1308
1279
|
debug("[getVolumeMountPoints] raw mount points: %o", raw);
|
|
1309
1280
|
const compacted = raw.map((ea) => compactValues(ea)).filter((ea) => isNotBlank(ea.mountPoint));
|
|
1310
1281
|
for (const ea of compacted) {
|
|
@@ -1457,7 +1428,7 @@ async function getVolumeMetadataForPathImpl(pathname, opts, nativeFn2) {
|
|
|
1457
1428
|
}
|
|
1458
1429
|
async function findMountPointByDeviceId(resolved, resolvedStat, opts, nativeFn2) {
|
|
1459
1430
|
const targetDev = resolvedStat.dev;
|
|
1460
|
-
const mountPoints = await getVolumeMountPointsImpl(
|
|
1431
|
+
const mountPoints = opts.mountPoints ?? await getVolumeMountPointsImpl(
|
|
1461
1432
|
{ ...opts, includeSystemVolumes: true },
|
|
1462
1433
|
nativeFn2
|
|
1463
1434
|
);
|