@photostructure/fs-metadata 0.5.0 → 0.5.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 (130) hide show
  1. package/C++_REVIEW_TODO.md +1 -1
  2. package/CHANGELOG.md +11 -2
  3. package/CLAUDE.md +269 -92
  4. package/CONTRIBUTING.md +41 -0
  5. package/README.md +20 -1
  6. package/WINDOWS_DEBUG_GUIDE.md +89 -0
  7. package/binding.gyp +3 -2
  8. package/dist/index.cjs +1440 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +360 -0
  11. package/dist/index.d.mts +360 -0
  12. package/dist/index.d.ts +360 -0
  13. package/dist/index.mjs +1398 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/jest.config.cjs +1 -0
  16. package/package.json +25 -27
  17. package/prebuilds/darwin-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  18. package/prebuilds/linux-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  19. package/prebuilds/linux-arm64/@photostructure+fs-metadata.musl.node +0 -0
  20. package/prebuilds/linux-x64/@photostructure+fs-metadata.glibc.node +0 -0
  21. package/prebuilds/linux-x64/@photostructure+fs-metadata.musl.node +0 -0
  22. package/prebuilds/win32-x64/@photostructure+fs-metadata.glibc.node +0 -0
  23. package/scripts/check-memory.mjs +53 -173
  24. package/scripts/clang-tidy.ts +241 -0
  25. package/scripts/prebuild-linux-glibc.sh +108 -0
  26. package/scripts/precommit.ts +45 -0
  27. package/scripts/sanitizers-test.sh +157 -0
  28. package/scripts/{configure.mjs → setup-native.mjs} +4 -1
  29. package/scripts/valgrind-test.mjs +1 -1
  30. package/scripts/{valgrind.sh → valgrind-test.sh} +15 -0
  31. package/src/binding.cpp +1 -1
  32. package/src/common/error_utils.h +17 -0
  33. package/src/common/metadata_worker.h +4 -1
  34. package/src/darwin/hidden.cpp +13 -6
  35. package/src/darwin/volume_metadata.cpp +2 -2
  36. package/src/darwin/volume_mount_points.cpp +8 -1
  37. package/src/linux/blkid_cache.cpp +8 -2
  38. package/src/linux/volume_metadata.cpp +1 -1
  39. package/src/platform.ts +25 -0
  40. package/src/test-utils/benchmark-harness.ts +192 -0
  41. package/src/test-utils/debuglog-child.ts +30 -2
  42. package/src/test-utils/debuglog-enabled-child.ts +38 -8
  43. package/src/test-utils/jest-setup.ts +14 -0
  44. package/src/test-utils/worker-thread-helper.cjs +92 -0
  45. package/src/windows/hidden.cpp +20 -11
  46. package/coverage/base.css +0 -224
  47. package/coverage/block-navigation.js +0 -87
  48. package/coverage/favicon.png +0 -0
  49. package/coverage/index.html +0 -131
  50. package/coverage/lcov-report/base.css +0 -224
  51. package/coverage/lcov-report/block-navigation.js +0 -87
  52. package/coverage/lcov-report/favicon.png +0 -0
  53. package/coverage/lcov-report/index.html +0 -131
  54. package/coverage/lcov-report/prettify.css +0 -1
  55. package/coverage/lcov-report/prettify.js +0 -2
  56. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  57. package/coverage/lcov-report/sorter.js +0 -196
  58. package/coverage/lcov-report/src/array.ts.html +0 -217
  59. package/coverage/lcov-report/src/async.ts.html +0 -547
  60. package/coverage/lcov-report/src/debuglog.ts.html +0 -187
  61. package/coverage/lcov-report/src/defer.ts.html +0 -175
  62. package/coverage/lcov-report/src/dirname.ts.html +0 -124
  63. package/coverage/lcov-report/src/error.ts.html +0 -322
  64. package/coverage/lcov-report/src/fs.ts.html +0 -316
  65. package/coverage/lcov-report/src/glob.ts.html +0 -472
  66. package/coverage/lcov-report/src/hidden.ts.html +0 -724
  67. package/coverage/lcov-report/src/index.html +0 -521
  68. package/coverage/lcov-report/src/index.ts.html +0 -676
  69. package/coverage/lcov-report/src/linux/dev_disk.ts.html +0 -316
  70. package/coverage/lcov-report/src/linux/index.html +0 -146
  71. package/coverage/lcov-report/src/linux/mount_points.ts.html +0 -364
  72. package/coverage/lcov-report/src/linux/mtab.ts.html +0 -493
  73. package/coverage/lcov-report/src/mount_point.ts.html +0 -106
  74. package/coverage/lcov-report/src/number.ts.html +0 -148
  75. package/coverage/lcov-report/src/object.ts.html +0 -265
  76. package/coverage/lcov-report/src/options.ts.html +0 -475
  77. package/coverage/lcov-report/src/path.ts.html +0 -268
  78. package/coverage/lcov-report/src/platform.ts.html +0 -112
  79. package/coverage/lcov-report/src/random.ts.html +0 -205
  80. package/coverage/lcov-report/src/remote_info.ts.html +0 -553
  81. package/coverage/lcov-report/src/stack_path.ts.html +0 -298
  82. package/coverage/lcov-report/src/string.ts.html +0 -382
  83. package/coverage/lcov-report/src/string_enum.ts.html +0 -208
  84. package/coverage/lcov-report/src/system_volume.ts.html +0 -301
  85. package/coverage/lcov-report/src/unc.ts.html +0 -274
  86. package/coverage/lcov-report/src/units.ts.html +0 -274
  87. package/coverage/lcov-report/src/uuid.ts.html +0 -157
  88. package/coverage/lcov-report/src/volume_health_status.ts.html +0 -259
  89. package/coverage/lcov-report/src/volume_metadata.ts.html +0 -787
  90. package/coverage/lcov-report/src/volume_mount_points.ts.html +0 -388
  91. package/coverage/lcov.info +0 -3581
  92. package/coverage/prettify.css +0 -1
  93. package/coverage/prettify.js +0 -2
  94. package/coverage/sort-arrow-sprite.png +0 -0
  95. package/coverage/sorter.js +0 -196
  96. package/coverage/src/array.ts.html +0 -217
  97. package/coverage/src/async.ts.html +0 -547
  98. package/coverage/src/debuglog.ts.html +0 -187
  99. package/coverage/src/defer.ts.html +0 -175
  100. package/coverage/src/dirname.ts.html +0 -124
  101. package/coverage/src/error.ts.html +0 -322
  102. package/coverage/src/fs.ts.html +0 -316
  103. package/coverage/src/glob.ts.html +0 -472
  104. package/coverage/src/hidden.ts.html +0 -724
  105. package/coverage/src/index.html +0 -521
  106. package/coverage/src/index.ts.html +0 -676
  107. package/coverage/src/linux/dev_disk.ts.html +0 -316
  108. package/coverage/src/linux/index.html +0 -146
  109. package/coverage/src/linux/mount_points.ts.html +0 -364
  110. package/coverage/src/linux/mtab.ts.html +0 -493
  111. package/coverage/src/mount_point.ts.html +0 -106
  112. package/coverage/src/number.ts.html +0 -148
  113. package/coverage/src/object.ts.html +0 -265
  114. package/coverage/src/options.ts.html +0 -475
  115. package/coverage/src/path.ts.html +0 -268
  116. package/coverage/src/platform.ts.html +0 -112
  117. package/coverage/src/random.ts.html +0 -205
  118. package/coverage/src/remote_info.ts.html +0 -553
  119. package/coverage/src/stack_path.ts.html +0 -298
  120. package/coverage/src/string.ts.html +0 -382
  121. package/coverage/src/string_enum.ts.html +0 -208
  122. package/coverage/src/system_volume.ts.html +0 -301
  123. package/coverage/src/unc.ts.html +0 -274
  124. package/coverage/src/units.ts.html +0 -274
  125. package/coverage/src/uuid.ts.html +0 -157
  126. package/coverage/src/volume_health_status.ts.html +0 -259
  127. package/coverage/src/volume_metadata.ts.html +0 -787
  128. package/coverage/src/volume_mount_points.ts.html +0 -388
  129. package/scripts/clang-tidy.mjs +0 -73
  130. package/scripts/run-asan.sh +0 -92
@@ -0,0 +1,360 @@
1
+ /**
2
+ * Represents the detailed state of a file or directory's hidden attribute
3
+ */
4
+ interface HiddenMetadata {
5
+ /**
6
+ * Whether the item is considered hidden by any method
7
+ */
8
+ hidden: boolean;
9
+ /**
10
+ * Whether the item has a dot prefix (POSIX-style hidden). Windows doesn't
11
+ * care about dot prefixes.
12
+ */
13
+ dotPrefix: boolean;
14
+ /**
15
+ * Whether the item has system hidden flags set, like via `chflags` on macOS
16
+ * or on Windows via `GetFileAttributesW`
17
+ */
18
+ systemFlag: boolean;
19
+ /**
20
+ * Indicates which hiding methods are supported on the current platform
21
+ */
22
+ supported: {
23
+ /**
24
+ * Whether dot prefix hiding is supported on the current operating system
25
+ */
26
+ dotPrefix: boolean;
27
+ /**
28
+ * Whether system flag hiding is supported
29
+ */
30
+ systemFlag: boolean;
31
+ };
32
+ }
33
+
34
+ type StringEnumType<T extends string> = {
35
+ [K in T]: K;
36
+ };
37
+ type StringEnum<T extends string> = StringEnumType<T> & {
38
+ values: T[];
39
+ size: number;
40
+ get(s: string | undefined): T | undefined;
41
+ };
42
+ type StringEnumKeys<Type> = Type extends StringEnum<infer X> ? X : never;
43
+
44
+ /**
45
+ * Health statuses for volumes (mostly applicable to Windows).
46
+ *
47
+ * - `healthy`: Volume is "OK": accessible and functioning normally
48
+ * - `timeout`: Volume could not be accessed before the specified timeout. It
49
+ * may be inaccessible or disconnected.
50
+ * - `inaccessible`: Volume exists but can't be accessed (permissions/locks)
51
+ * - `disconnected`: Network volume that's offline
52
+ * - `unknown`: Status can't be determined
53
+ */
54
+ declare const VolumeHealthStatuses: StringEnum<"healthy" | "timeout" | "inaccessible" | "disconnected" | "unknown">;
55
+ type VolumeHealthStatus = StringEnumKeys<typeof VolumeHealthStatuses>;
56
+
57
+ /**
58
+ * A mount point is a location in the file system where a volume is mounted.
59
+ *
60
+ * @see https://en.wikipedia.org/wiki/Mount_(computing)
61
+ */
62
+ interface MountPoint {
63
+ /**
64
+ * Mount location (like "/" or "C:\").
65
+ */
66
+ mountPoint: string;
67
+ /**
68
+ * The type of file system on the volume, like `ext4`, `apfs`, or `ntfs`.
69
+ *
70
+ * Note: on Windows this may show as "ntfs" for remote filesystems, as that
71
+ * is how the filesystem is presented to the OS.
72
+ */
73
+ fstype?: string;
74
+ /**
75
+ * On Windows, returns the health status of the volume.
76
+ *
77
+ * Note that this is only available on Windows, as both Linux and macOS are
78
+ * prohibitively expensive, requiring forking `fsck -N` or `diskutil
79
+ * verifyVolume`.
80
+ *
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).
83
+ *
84
+ * @see {@link VolumeHealthStatuses} for values returned by Windows.
85
+ */
86
+ status?: VolumeHealthStatus | string;
87
+ /**
88
+ * Indicates if this volume is primarily for system use (e.g., swap, snap
89
+ * loopbacks, EFI boot, or only system directories).
90
+ *
91
+ * Note: This is a best-effort classification and is not 100% accurate.
92
+ *
93
+ * @see {@link Options.systemPathPatterns} and {@link Options.systemFsTypes}
94
+ */
95
+ isSystemVolume?: boolean;
96
+ /**
97
+ * If there are non-critical errors while extracting metadata, those errors
98
+ * may be added to this field.
99
+ */
100
+ error?: Error | string;
101
+ }
102
+
103
+ /**
104
+ * Configuration options for filesystem operations.
105
+ *
106
+ * @see {@link optionsWithDefaults} for creating an options object with default values
107
+ * @see {@link OptionsDefault} for the default values
108
+ */
109
+ interface Options {
110
+ /**
111
+ * Timeout in milliseconds for filesystem operations.
112
+ *
113
+ * Disable timeouts by setting this to 0.
114
+ *
115
+ * @see {@link TimeoutMsDefault}.
116
+ */
117
+ timeoutMs: number;
118
+ /**
119
+ * Maximum number of concurrent filesystem operations.
120
+ *
121
+ * Defaults to {@link https://nodejs.org/api/os.html#osavailableparallelism | availableParallelism}.
122
+ */
123
+ maxConcurrency: number;
124
+ /**
125
+ * On Linux and macOS, mount point pathnames that matches any of these glob
126
+ * patterns will have {@link MountPoint.isSystemVolume} set to true.
127
+ *
128
+ * @see {@link SystemPathPatternsDefault} for the default value
129
+ */
130
+ systemPathPatterns: string[];
131
+ /**
132
+ * On Linux and macOS, volumes whose filesystem matches any of these strings
133
+ * will have {@link MountPoint.isSystemVolume} set to true.
134
+ *
135
+ * @see {@link SystemFsTypesDefault} for the default value
136
+ */
137
+ systemFsTypes: string[];
138
+ /**
139
+ * On Linux, use the first mount point table in this array that is readable.
140
+ *
141
+ * @see {@link LinuxMountTablePathsDefault} for the default values
142
+ */
143
+ linuxMountTablePaths: string[];
144
+ /**
145
+ * Should system volumes be included in result arrays? Defaults to true on
146
+ * Windows and false elsewhere.
147
+ */
148
+ includeSystemVolumes: boolean;
149
+ }
150
+
151
+ /**
152
+ * Represents remote filesystem information.
153
+ */
154
+ interface RemoteInfo {
155
+ /**
156
+ * We can sometimes fetch a URI of the resource (like "smb://server/share" or
157
+ * "file:///media/user/usb")
158
+ */
159
+ uri?: string;
160
+ /**
161
+ * Protocol used to access the share.
162
+ */
163
+ protocol?: string;
164
+ /**
165
+ * Does the protocol seem to be a remote filesystem?
166
+ */
167
+ remote: boolean;
168
+ /**
169
+ * If remote, may include the username used to access the share.
170
+ *
171
+ * This will be undefined on NFS and other remote filesystem types that do
172
+ * authentication out of band.
173
+ */
174
+ remoteUser?: string;
175
+ /**
176
+ * If remote, the ip or hostname hosting the share (like "rusty" or "10.1.1.3")
177
+ */
178
+ remoteHost?: string;
179
+ /**
180
+ * If remote, the name of the share (like "homes")
181
+ */
182
+ remoteShare?: string;
183
+ }
184
+
185
+ /**
186
+ * Metadata associated to a volume.
187
+ *
188
+ * @see https://en.wikipedia.org/wiki/Volume_(computing)
189
+ */
190
+ interface VolumeMetadata extends RemoteInfo, MountPoint {
191
+ /**
192
+ * The name of the partition
193
+ */
194
+ label?: string;
195
+ /**
196
+ * Total size in bytes
197
+ */
198
+ size?: number;
199
+ /**
200
+ * Used size in bytes
201
+ */
202
+ used?: number;
203
+ /**
204
+ * Available size in bytes
205
+ */
206
+ available?: number;
207
+ /**
208
+ * Path to the device or service that the mountpoint is from.
209
+ *
210
+ * Examples include `/dev/sda1`, `nfs-server:/export`,
211
+ * `//username@remoteHost/remoteShare`, or `//cifs-server/share`.
212
+ *
213
+ * May be undefined for remote volumes.
214
+ */
215
+ mountFrom?: string;
216
+ /**
217
+ * The name of the mount. This may match the resolved mountPoint.
218
+ */
219
+ mountName?: string;
220
+ /**
221
+ * UUID for the volume, like "c9b08f6e-b392-11ef-bf19-4b13bb7db4b4".
222
+ *
223
+ * On windows, this _may_ be the 128-bit volume UUID, but if that is not
224
+ * available, like in the case of remote volumes, we fallback to the 32-bit
225
+ * volume serial number, rendered in lowercase hexadecimal.
226
+ */
227
+ uuid?: string;
228
+ }
229
+
230
+ type HideMethod = "dotPrefix" | "systemFlag" | "all" | "auto";
231
+ type SetHiddenResult = {
232
+ pathname: string;
233
+ actions: {
234
+ dotPrefix: boolean;
235
+ systemFlag: boolean;
236
+ };
237
+ };
238
+
239
+ /**
240
+ * Default timeout in milliseconds for {@link Options.timeoutMs}.
241
+ *
242
+ * Note that this timeout may be insufficient for some devices, like spun-down
243
+ * optical drives or network shares that need to spin up or reconnect.
244
+ */
245
+ declare const TimeoutMsDefault: 5000;
246
+ /**
247
+ * System paths and globs that indicate system volumes
248
+ */
249
+ declare const SystemPathPatternsDefault: readonly ["/boot", "/boot/efi", "/dev", "/dev/**", "/proc/**", "/run", "/run/credentials/**", "/run/lock", "/run/snapd/**", "/run/user/*/doc", "/run/user/*/gvfs", "/snap/**", "/sys/**", "/tmp", "/var/tmp", "**/#snapshot", "/mnt/wslg/distro", "/mnt/wslg/doc", "/mnt/wslg/versions.txt", "/usr/lib/wsl/drivers", "/private/var/vm", "/System/Volumes/Hardware", "/System/Volumes/iSCPreboot", "/System/Volumes/Preboot", "/System/Volumes/Recovery", "/System/Volumes/Reserved", "/System/Volumes/Update", "/System/Volumes/VM", "/System/Volumes/xarts"];
250
+ /**
251
+ * Filesystem types that indicate system volumes
252
+ */
253
+ declare const SystemFsTypesDefault: readonly ["autofs", "binfmt_misc", "cgroup", "cgroup2", "configfs", "debugfs", "devpts", "devtmpfs", "efivarfs", "fusectl", "fuse.snapfuse", "hugetlbfs", "mqueue", "none", "proc", "pstore", "rootfs", "securityfs", "snap*", "squashfs", "sysfs", "tmpfs"];
254
+ declare const LinuxMountTablePathsDefault: readonly ["/proc/self/mounts", "/proc/mounts", "/etc/mtab"];
255
+ /**
256
+ * Should {@link getAllVolumeMetadata} include system volumes by
257
+ * default?
258
+ */
259
+ declare const IncludeSystemVolumesDefault: boolean;
260
+ /**
261
+ * Default {@link Options} object.
262
+ *
263
+ * @see {@link optionsWithDefaults} for creating an options object with default values
264
+ */
265
+ declare const OptionsDefault: Options;
266
+ /**
267
+ * Create an {@link Options} object using default values from
268
+ * {@link OptionsDefault} for missing fields.
269
+ */
270
+ declare function optionsWithDefaults<T extends Options>(overrides?: Partial<T>): T;
271
+
272
+ /**
273
+ * Configuration for system volume detection
274
+ *
275
+ * @see {@link MountPoint.isSystemVolume}
276
+ */
277
+ type SystemVolumeConfig = Pick<Options, "systemPathPatterns" | "systemFsTypes">;
278
+
279
+ type GetVolumeMountPointOptions = Partial<Pick<Options, "timeoutMs" | "linuxMountTablePaths" | "maxConcurrency" | "includeSystemVolumes"> & SystemVolumeConfig>;
280
+
281
+ /**
282
+ * List all active local and remote mount points on the system.
283
+ *
284
+ * Only readable directories are included in the results.
285
+ *
286
+ * Note that on Windows, `timeoutMs` will be used **per system call** and not
287
+ * for the entire operation.
288
+ *
289
+ * @param opts Optional filesystem operation settings to override default values
290
+ */
291
+ declare function getVolumeMountPoints(opts?: Partial<GetVolumeMountPointOptions>): Promise<MountPoint[]>;
292
+ /**
293
+ * Get metadata for the volume at the given mount point.
294
+ *
295
+ * @param mountPoint Must be a non-blank string
296
+ * @param opts Optional filesystem operation settings
297
+ */
298
+ declare function getVolumeMetadata(mountPoint: string, opts?: Partial<Pick<Options, "timeoutMs">>): Promise<VolumeMetadata>;
299
+ /**
300
+ * Retrieves metadata for all mounted volumes with optional filtering and
301
+ * concurrency control.
302
+ *
303
+ * @param opts - Optional configuration object
304
+ * @param opts.includeSystemVolumes - If true, includes system volumes in the
305
+ * results. Defaults to true on Windows and false elsewhere.
306
+ * @param opts.maxConcurrency - Maximum number of concurrent operations.
307
+ * Defaults to the system's available parallelism: see
308
+ * {@link https://nodejs.org/api/os.html#osavailableparallelism | os.availableParallelism()}
309
+ * @param opts.timeoutMs - Maximum time to wait for
310
+ * {@link getVolumeMountPointsImpl}, as well as **each** {@link getVolumeMetadataImpl}
311
+ * to complete. Defaults to {@link TimeoutMsDefault}
312
+ * @returns Promise that resolves to an array of either VolumeMetadata objects
313
+ * or error objects containing the mount point and error
314
+ * @throws Never - errors are caught and returned as part of the result array
315
+ */
316
+ declare function getAllVolumeMetadata(opts?: Partial<Options> & {
317
+ includeSystemVolumes?: boolean;
318
+ }): Promise<VolumeMetadata[]>;
319
+ /**
320
+ * Check if a file or directory is hidden.
321
+ *
322
+ * Note that `path` may be _effectively_ hidden if any of the ancestor
323
+ * directories are hidden: use {@link isHiddenRecursive} to check for this.
324
+ *
325
+ * @param pathname Path to file or directory
326
+ * @returns Promise resolving to boolean indicating hidden state
327
+ */
328
+ declare function isHidden(pathname: string): Promise<boolean>;
329
+ /**
330
+ * Check if a file or directory is hidden, or if any of its ancestor
331
+ * directories are hidden.
332
+ *
333
+ * @param pathname Path to file or directory
334
+ * @returns Promise resolving to boolean indicating hidden state
335
+ */
336
+ declare function isHiddenRecursive(pathname: string): Promise<boolean>;
337
+ /**
338
+ * Get detailed metadata about the hidden state of a file or directory.
339
+ *
340
+ * @param pathname Path to file or directory
341
+ * @returns Promise resolving to metadata about the hidden state
342
+ */
343
+ declare function getHiddenMetadata(pathname: string): Promise<HiddenMetadata>;
344
+ /**
345
+ * Set the hidden state of a file or directory
346
+ *
347
+ * @param pathname Path to file or directory
348
+ * @param hidden - Whether the item should be hidden (true) or visible (false)
349
+ * @param method Method to use for hiding the file or directory. The default
350
+ * is "auto", which is "dotPrefix" on Linux and macOS, and "systemFlag" on
351
+ * Windows. "all" will attempt to use all relevant methods for the current
352
+ * operating system.
353
+ * @returns Promise resolving the final name of the file or directory (as it
354
+ * will change on POSIX systems), and the action(s) taken.
355
+ * @throws {Error} If the file doesn't exist, permissions are insufficient, or
356
+ * the requested method is unsupported
357
+ */
358
+ declare function setHidden(pathname: string, hidden: boolean, method?: HideMethod): Promise<SetHiddenResult>;
359
+
360
+ export { type GetVolumeMountPointOptions, type HiddenMetadata, type HideMethod, IncludeSystemVolumesDefault, LinuxMountTablePathsDefault, type MountPoint, type Options, OptionsDefault, type SetHiddenResult, type StringEnum, type StringEnumKeys, type StringEnumType, SystemFsTypesDefault, SystemPathPatternsDefault, type SystemVolumeConfig, TimeoutMsDefault, type VolumeHealthStatus, VolumeHealthStatuses, type VolumeMetadata, getAllVolumeMetadata, getHiddenMetadata, getVolumeMetadata, getVolumeMountPoints, isHidden, isHiddenRecursive, optionsWithDefaults, setHidden };