@photostructure/fs-metadata 0.7.1 → 0.8.1

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 (45) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/CLAUDE.md +1 -1
  3. package/CONTRIBUTING.md +15 -0
  4. package/README.md +7 -14
  5. package/dist/index.cjs +29 -4
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +11 -6
  8. package/dist/index.d.mts +11 -6
  9. package/dist/index.d.ts +11 -6
  10. package/dist/index.mjs +28 -3
  11. package/dist/index.mjs.map +1 -1
  12. package/doc/LINUX_API_REFERENCE.md +310 -0
  13. package/doc/MACOS_API_REFERENCE.md +367 -31
  14. package/doc/WINDOWS_API_REFERENCE.md +35 -2
  15. package/doc/gotchas.md +28 -0
  16. package/package.json +16 -38
  17. package/prebuilds/darwin-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  18. package/prebuilds/darwin-x64/@photostructure+fs-metadata.glibc.node +0 -0
  19. package/prebuilds/linux-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  20. package/prebuilds/linux-arm64/@photostructure+fs-metadata.musl.node +0 -0
  21. package/prebuilds/linux-x64/@photostructure+fs-metadata.glibc.node +0 -0
  22. package/prebuilds/linux-x64/@photostructure+fs-metadata.musl.node +0 -0
  23. package/prebuilds/win32-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  24. package/prebuilds/win32-x64/@photostructure+fs-metadata.glibc.node +0 -0
  25. package/scripts/precommit.ts +4 -1
  26. package/src/common/fd_guard.h +71 -0
  27. package/src/{darwin → common}/path_security.h +8 -5
  28. package/src/common/volume_utils.h +51 -0
  29. package/src/darwin/hidden.cpp +47 -14
  30. package/src/darwin/raii_utils.h +8 -8
  31. package/src/darwin/volume_metadata.cpp +33 -39
  32. package/src/index.ts +3 -3
  33. package/src/linux/blkid_cache.cpp +5 -11
  34. package/src/linux/blkid_cache.h +21 -0
  35. package/src/linux/gio_utils.cpp +7 -23
  36. package/src/linux/gio_utils.h +16 -40
  37. package/src/linux/gio_volume_metadata.cpp +16 -88
  38. package/src/linux/volume_metadata.cpp +35 -27
  39. package/src/options.ts +35 -3
  40. package/src/types/options.ts +1 -1
  41. package/src/windows/drive_status.h +74 -49
  42. package/src/windows/error_utils.h +2 -2
  43. package/src/windows/security_utils.h +47 -2
  44. package/src/windows/thread_pool.h +29 -4
  45. package/src/windows/volume_metadata.cpp +17 -12
package/CHANGELOG.md CHANGED
@@ -14,6 +14,45 @@ Fixed for any bug fixes.
14
14
  Security in case of vulnerabilities.
15
15
  -->
16
16
 
17
+ ## 0.8.1 - 2025-12-28
18
+
19
+ ### Changed
20
+
21
+ - Added container runtime paths to the default set of system paths. See SystemPathPatternsDefault
22
+
23
+ ## 0.8.0 - 2025-12-01
24
+
25
+ ### Added
26
+
27
+ - `FS_METADATA_TIMEOUT_MS` environment variable for configuring operation timeout (see [gotchas.md](./doc/gotchas.md))
28
+
29
+ ### Security
30
+
31
+ - Fixed TOCTOU race condition in macOS hidden file operations by using `fstat()`/`fchflags()` with file descriptors instead of path-based `stat()`/`chflags()`
32
+
33
+ ### Fixed
34
+
35
+ - Added `O_CLOEXEC` flag to `open()` calls to prevent fd leaks on fork/exec
36
+ - Fixed logic bug attempting to convert invalid CFStringRef in `ProcessNetworkVolume`
37
+ - Fixed inconsistent `status` field when DiskArbitration returns partial results
38
+ - Added `noexcept` to all RAII destructors to prevent `std::terminate` during stack unwinding
39
+ - Removed `GVolumeMonitor` from Linux GIO metadata enrichment to fix thread safety issues
40
+ - Fixed exception safety in Linux GIO metadata loop using RAII smart pointers
41
+ - Fixed Windows `FindFirstFileEx` handle leak by using `FindClose` instead of `CloseHandle`
42
+ - Fixed Windows promise race condition and resource leak from detached timeout threads
43
+ - Added `CreateEvent` error checking in Windows thread pool
44
+ - Zero-initialized `VolumeInfo` and `DiskSpaceInfo` members to prevent undefined behavior on `ERROR_NOT_READY`
45
+
46
+ ### Changed
47
+
48
+ - Extracted shared `FdGuard` RAII class to `common/fd_guard.h`
49
+ - Extracted shared `WouldOverflow()` utility to `common/volume_utils.h`
50
+ - Moved `path_security.h` to `common/` (POSIX-portable)
51
+ - Simplified CFString null-terminator handling using `strlen()`
52
+ - Documented intentional static dispatch queue singleton pattern
53
+ - Consolidated Linux GIO RAII helpers (`GFilePtr`, `GVolumePtr`, etc.) in `gio_utils.h`
54
+ - Added move semantics to `BlkidCache` for proper resource transfer
55
+
17
56
  ## 0.7.1 - 2025-10-29
18
57
 
19
58
  - Audit and address [several resource handling issues](./doc/SECURITY_AUDIT_2025.md)
package/CLAUDE.md CHANGED
@@ -197,4 +197,4 @@ git push origin main --follow-tags
197
197
 
198
198
  Never do inline imports like `const { mkdirSync } = await import("node:fs");` -- just use standard imports.
199
199
 
200
- Never include claude code messages in git commits
200
+ **NEVER** add "Generated with Claude Code" or "Co-Authored-By: Claude" lines to git commit messages. Keep commits clean and professional.
package/CONTRIBUTING.md CHANGED
@@ -6,6 +6,21 @@ For major changes, please open an issue first to discuss what you would like to
6
6
 
7
7
  Please make sure to update tests and documentation as appropriate.
8
8
 
9
+ ## Development Setup
10
+
11
+ This repository uses `ignore-scripts=true` in `.npmrc` as a security measure against [supply chain attacks](https://www.nodejs-security.com/blog/npm-ignore-scripts-best-practices-as-security-mitigation-for-malicious-packages). Since this is a native module, you need to explicitly enable scripts for the initial build:
12
+
13
+ ```bash
14
+ # Clone the repository
15
+ git clone https://github.com/photostructure/fs-metadata.git
16
+ cd fs-metadata
17
+
18
+ # Install with scripts enabled (required for native module build)
19
+ npm install --ignore-scripts=false
20
+
21
+ # Subsequent installs of new dependencies will have scripts disabled by default
22
+ ```
23
+
9
24
  ## Building from Source
10
25
 
11
26
  ### On Windows
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ![PhotoStructure fs-metadata logo](https://raw.githubusercontent.com/photostructure/fs-metadata/main/doc/logo.svg)
2
2
 
3
- Cross-platform native Node.js module for filesystem metadata, mount points, and volume information.
3
+ Cross-platform native Node.js module for filesystem metadata, mount points, and volume information. Built for and supported by [PhotoStructure](https://photostructure.com).
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@photostructure/fs-metadata.svg)](https://www.npmjs.com/package/@photostructure/fs-metadata)
6
6
  [![Build](https://github.com/photostructure/fs-metadata/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/photostructure/fs-metadata/actions/workflows/build.yml)
@@ -48,21 +48,14 @@ console.log(metadata);
48
48
 
49
49
  ## Documentation
50
50
 
51
- - 📖 [API Reference](https://photostructure.github.io/fs-metadata/modules.html)
52
- - 💡 [Examples](./doc/examples.md) - Common usage patterns and recipes
53
- - ⚠️ [Gotchas](./doc/gotchas.md) - Platform quirks, timeouts, and troubleshooting
54
- - 🔧 [Contributing](./CONTRIBUTING.md) - Build instructions and development guide
51
+ - [API Reference](https://photostructure.github.io/fs-metadata/modules.html)
52
+ - [Examples](./doc/examples.md) - Common usage patterns and recipes
53
+ - [Gotchas](./doc/gotchas.md) - Platform quirks, timeouts, and troubleshooting
54
+ - [Contributing](./CONTRIBUTING.md) - Build instructions and development guide
55
55
 
56
56
  ### Options
57
57
 
58
58
  - **Debug**: Set `NODE_DEBUG=fs-meta` for debug output
59
- - **Timeouts**: Configure [timeout duration](https://photostructure.github.io/fs-metadata/variables/TimeoutMsDefault.html) for slow devices
59
+ - **Timeouts**: Configure [timeout duration](https://photostructure.github.io/fs-metadata/functions/getTimeoutMsDefault.html) for slow devices
60
+ - Set `FS_METADATA_TIMEOUT_MS` environment variable to override the default (5000ms)
60
61
  - **System Volumes**: Control [system volume filtering](https://photostructure.github.io/fs-metadata/interfaces/Options.html)
61
-
62
- ## Support
63
-
64
- Built and supported by [PhotoStructure](https://photostructure.com)
65
-
66
- - [GitHub Issues](https://github.com/photostructure/fs-metadata/issues)
67
- - [Security Policy](./SECURITY.md)
68
- - [MIT License](./LICENSE.txt)
package/dist/index.cjs CHANGED
@@ -35,10 +35,10 @@ __export(index_exports, {
35
35
  OptionsDefault: () => OptionsDefault,
36
36
  SystemFsTypesDefault: () => SystemFsTypesDefault,
37
37
  SystemPathPatternsDefault: () => SystemPathPatternsDefault,
38
- TimeoutMsDefault: () => TimeoutMsDefault,
39
38
  VolumeHealthStatuses: () => VolumeHealthStatuses,
40
39
  getAllVolumeMetadata: () => getAllVolumeMetadata,
41
40
  getHiddenMetadata: () => getHiddenMetadata,
41
+ getTimeoutMsDefault: () => getTimeoutMsDefault,
42
42
  getVolumeMetadata: () => getVolumeMetadata,
43
43
  getVolumeMountPoints: () => getVolumeMountPoints,
44
44
  isHidden: () => isHidden,
@@ -612,7 +612,14 @@ async function setHiddenImpl(pathname, hide, method, nativeFn2) {
612
612
 
613
613
  // src/options.ts
614
614
  var import_node_os2 = require("os");
615
- var TimeoutMsDefault = 5e3;
615
+ var import_node_process3 = require("process");
616
+ var DefaultTimeoutMs = 5e3;
617
+ function getTimeoutMsDefault() {
618
+ const value = import_node_process3.env["FS_METADATA_TIMEOUT_MS"];
619
+ if (value == null) return DefaultTimeoutMs;
620
+ const parsed = parseInt(value, 10);
621
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : DefaultTimeoutMs;
622
+ }
616
623
  var SystemPathPatternsDefault = [
617
624
  "/boot",
618
625
  "/boot/efi",
@@ -632,6 +639,24 @@ var SystemPathPatternsDefault = [
632
639
  // we aren't including /tmp/**, as some people temporarily mount volumes there, like /tmp/project.
633
640
  "**/#snapshot",
634
641
  // Synology and Kubernetes volume snapshots
642
+ // Container runtime paths - these are internal infrastructure paths that are
643
+ // inaccessible to non-root processes and should never be scanned.
644
+ //
645
+ // Docker: https://docs.docker.com/engine/storage/drivers/overlayfs-driver/
646
+ // - /var/lib/docker contains overlay2 filesystems, container layers, images
647
+ // - /run/docker contains runtime data like network namespaces
648
+ "/run/docker/**",
649
+ "/var/lib/docker/**",
650
+ //
651
+ // containerd: https://github.com/containerd/containerd/blob/main/docs/ops.md
652
+ // - Used by Kubernetes, Docker (as backend), and standalone
653
+ "/run/containerd/**",
654
+ "/var/lib/containerd/**",
655
+ //
656
+ // Podman/CRI-O: https://podman.io/docs/installation#storage
657
+ // - Rootless and rootful container storage
658
+ "/run/containers/**",
659
+ "/var/lib/containers/**",
635
660
  // windows for linux:
636
661
  "/mnt/wslg/distro",
637
662
  "/mnt/wslg/doc",
@@ -681,7 +706,7 @@ var LinuxMountTablePathsDefault = [
681
706
  var IncludeSystemVolumesDefault = isWindows;
682
707
  var SkipNetworkVolumesDefault = false;
683
708
  var OptionsDefault = {
684
- timeoutMs: TimeoutMsDefault,
709
+ timeoutMs: getTimeoutMsDefault(),
685
710
  maxConcurrency: (0, import_node_os2.availableParallelism)(),
686
711
  systemPathPatterns: [...SystemPathPatternsDefault],
687
712
  systemFsTypes: [...SystemFsTypesDefault],
@@ -1456,10 +1481,10 @@ function setHidden(pathname, hidden, method = "auto") {
1456
1481
  OptionsDefault,
1457
1482
  SystemFsTypesDefault,
1458
1483
  SystemPathPatternsDefault,
1459
- TimeoutMsDefault,
1460
1484
  VolumeHealthStatuses,
1461
1485
  getAllVolumeMetadata,
1462
1486
  getHiddenMetadata,
1487
+ getTimeoutMsDefault,
1463
1488
  getVolumeMetadata,
1464
1489
  getVolumeMountPoints,
1465
1490
  isHidden,