@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.
Files changed (41) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/CONTRIBUTING.md +3 -3
  3. package/binding.gyp +0 -22
  4. package/dist/index.cjs +11 -40
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +15 -3
  7. package/dist/index.d.mts +15 -3
  8. package/dist/index.d.ts +15 -3
  9. package/dist/index.mjs +11 -40
  10. package/dist/index.mjs.map +1 -1
  11. package/doc/C++_REVIEW_TODO.md +3 -36
  12. package/doc/LINUX_API_REFERENCE.md +4 -147
  13. package/doc/SECURITY_AUDIT_2026.md +5 -0
  14. package/doc/gotchas.md +27 -0
  15. package/package.json +9 -10
  16. package/prebuilds/darwin-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  17. package/prebuilds/darwin-x64/@photostructure+fs-metadata.glibc.node +0 -0
  18. package/prebuilds/linux-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  19. package/prebuilds/linux-x64/@photostructure+fs-metadata.glibc.node +0 -0
  20. package/prebuilds/win32-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  21. package/prebuilds/win32-x64/@photostructure+fs-metadata.glibc.node +0 -0
  22. package/scripts/clang-tidy.ts +1 -3
  23. package/scripts/prebuild-linux-glibc.sh +1 -5
  24. package/scripts/sanitizers-test.sh +0 -1
  25. package/src/binding.cpp +0 -15
  26. package/src/index.ts +6 -2
  27. package/src/linux/mount_points.ts +8 -42
  28. package/src/linux/volume_metadata.cpp +0 -16
  29. package/src/mount_point_for_path.ts +1 -1
  30. package/src/types/mount_point.ts +1 -1
  31. package/src/types/native_bindings.ts +0 -5
  32. package/src/types/options.ts +14 -0
  33. package/src/volume_metadata.ts +22 -11
  34. package/src/volume_mount_points.ts +1 -1
  35. package/scripts/setup-native.mjs +0 -39
  36. package/src/linux/gio_mount_points.cpp +0 -80
  37. package/src/linux/gio_mount_points.h +0 -37
  38. package/src/linux/gio_utils.cpp +0 -115
  39. package/src/linux/gio_utils.h +0 -69
  40. package/src/linux/gio_volume_metadata.cpp +0 -81
  41. 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 or gio).
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 or gio).
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 or gio).
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(native, opts) {
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 arr = parseMtab(mtabContent).map((ea) => mountEntryToMountPoint(ea)).filter((ea) => ea != null);
1153
- debug("[getLinuxMountPoints] %s mount points: %o", input, arr);
1154
- if (arr.length > 0) {
1155
- raw.push(...arr);
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
- const byMountPoint = /* @__PURE__ */ new Map();
1163
- for (const ea of raw) {
1164
- const prior = byMountPoint.get(ea.mountPoint);
1165
- const merged = { ...compactValues(prior), ...compactValues(ea) };
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(nativeFn2, o));
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
  );