@photostructure/fs-metadata 0.4.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 (115) hide show
  1. package/C++_REVIEW_TODO.md +291 -0
  2. package/CHANGELOG.md +38 -1
  3. package/CLAUDE.md +346 -0
  4. package/CONTRIBUTING.md +66 -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 +2 -1
  9. package/dist/index.cjs.map +1 -1
  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 +17 -15
  14. package/dist/index.mjs.map +1 -1
  15. package/jest.config.cjs +68 -6
  16. package/package.json +56 -48
  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 +123 -0
  24. package/scripts/clang-tidy.ts +241 -0
  25. package/scripts/is-platform.mjs +12 -0
  26. package/scripts/post-build.mjs +21 -0
  27. package/scripts/prebuild-linux-glibc.sh +108 -0
  28. package/scripts/precommit.ts +45 -0
  29. package/scripts/sanitizers-test.sh +157 -0
  30. package/scripts/{configure.mjs → setup-native.mjs} +4 -1
  31. package/scripts/valgrind-test.mjs +83 -0
  32. package/scripts/valgrind-test.sh +85 -0
  33. package/src/async.ts +3 -3
  34. package/src/binding.cpp +4 -4
  35. package/src/common/error_utils.h +17 -0
  36. package/src/common/metadata_worker.h +4 -1
  37. package/src/darwin/hidden.cpp +13 -6
  38. package/src/darwin/volume_metadata.cpp +2 -2
  39. package/src/darwin/volume_mount_points.cpp +8 -1
  40. package/src/error.ts +3 -3
  41. package/src/fs.ts +1 -1
  42. package/src/glob.ts +2 -2
  43. package/src/hidden.ts +6 -6
  44. package/src/index.ts +19 -23
  45. package/src/linux/blkid_cache.cpp +23 -14
  46. package/src/linux/dev_disk.ts +2 -2
  47. package/src/linux/gio_mount_points.cpp +7 -7
  48. package/src/linux/gio_utils.cpp +19 -8
  49. package/src/linux/gio_volume_metadata.cpp +15 -15
  50. package/src/linux/mount_points.ts +9 -9
  51. package/src/linux/mtab.ts +7 -7
  52. package/src/linux/volume_metadata.cpp +7 -2
  53. package/src/object.ts +1 -1
  54. package/src/options.ts +3 -3
  55. package/src/path.ts +2 -2
  56. package/src/platform.ts +25 -0
  57. package/src/remote_info.ts +5 -5
  58. package/src/system_volume.ts +8 -8
  59. package/src/test-utils/assert.ts +2 -2
  60. package/src/test-utils/benchmark-harness.ts +192 -0
  61. package/src/test-utils/debuglog-child.ts +30 -4
  62. package/src/test-utils/debuglog-enabled-child.ts +40 -0
  63. package/src/test-utils/hidden-tests.ts +1 -1
  64. package/src/test-utils/jest-setup.ts +14 -0
  65. package/src/test-utils/platform.ts +3 -3
  66. package/src/test-utils/worker-thread-helper.cjs +92 -0
  67. package/src/types/native_bindings.ts +3 -3
  68. package/src/types/volume_metadata.ts +2 -2
  69. package/src/unc.ts +2 -2
  70. package/src/uuid.ts +1 -1
  71. package/src/volume_health_status.ts +6 -6
  72. package/src/volume_metadata.ts +20 -23
  73. package/src/volume_mount_points.ts +12 -17
  74. package/src/windows/drive_status.h +30 -13
  75. package/src/windows/hidden.cpp +32 -11
  76. package/src/windows/volume_metadata.cpp +17 -7
  77. package/tsup.config.ts +8 -2
  78. package/dist/types/array.d.ts +0 -25
  79. package/dist/types/async.d.ts +0 -42
  80. package/dist/types/debuglog.d.ts +0 -3
  81. package/dist/types/defer.d.ts +0 -10
  82. package/dist/types/dirname.d.ts +0 -1
  83. package/dist/types/error.d.ts +0 -17
  84. package/dist/types/fs.d.ts +0 -22
  85. package/dist/types/glob.d.ts +0 -17
  86. package/dist/types/hidden.d.ts +0 -29
  87. package/dist/types/index.d.ts +0 -91
  88. package/dist/types/linux/dev_disk.d.ts +0 -13
  89. package/dist/types/linux/mount_points.d.ts +0 -6
  90. package/dist/types/linux/mtab.d.ts +0 -47
  91. package/dist/types/mount_point.d.ts +0 -2
  92. package/dist/types/number.d.ts +0 -3
  93. package/dist/types/object.d.ts +0 -18
  94. package/dist/types/options.d.ts +0 -33
  95. package/dist/types/path.d.ts +0 -17
  96. package/dist/types/platform.d.ts +0 -4
  97. package/dist/types/random.d.ts +0 -12
  98. package/dist/types/remote_info.d.ts +0 -6
  99. package/dist/types/stack_path.d.ts +0 -2
  100. package/dist/types/string.d.ts +0 -37
  101. package/dist/types/string_enum.d.ts +0 -19
  102. package/dist/types/system_volume.d.ts +0 -14
  103. package/dist/types/types/hidden_metadata.d.ts +0 -32
  104. package/dist/types/types/mount_point.d.ts +0 -46
  105. package/dist/types/types/native_bindings.d.ts +0 -51
  106. package/dist/types/types/options.d.ts +0 -47
  107. package/dist/types/types/remote_info.d.ts +0 -33
  108. package/dist/types/types/volume_metadata.d.ts +0 -46
  109. package/dist/types/unc.d.ts +0 -11
  110. package/dist/types/units.d.ts +0 -38
  111. package/dist/types/uuid.d.ts +0 -16
  112. package/dist/types/volume_health_status.d.ts +0 -24
  113. package/dist/types/volume_metadata.d.ts +0 -8
  114. package/dist/types/volume_mount_points.d.ts +0 -6
  115. package/jest.config.base.cjs +0 -63
@@ -66,10 +66,16 @@ class GetHiddenWorker : public Napi::AsyncWorker {
66
66
 
67
67
  public:
68
68
  GetHiddenWorker(Napi::Env env, std::string p, Napi::Promise::Deferred def)
69
- : Napi::AsyncWorker(env), path(std::move(p)), deferred(std::move(def)) {}
69
+ : Napi::AsyncWorker(env), path(std::move(p)), deferred(def) {}
70
70
 
71
71
  void Execute() override {
72
72
  try {
73
+ // Add path validation to prevent directory traversal
74
+ if (path.find("..") != std::string::npos) {
75
+ throw FSException("Invalid path containing '..'",
76
+ ERROR_INVALID_PARAMETER);
77
+ }
78
+
73
79
  auto wpath = PathConverter::ToWString(path);
74
80
  FileAttributeHandler handler(wpath);
75
81
  result = handler.isHidden();
@@ -80,9 +86,15 @@ public:
80
86
  }
81
87
  }
82
88
 
83
- void OnOK() override { deferred.Resolve(Napi::Boolean::New(Env(), result)); }
89
+ void OnOK() override {
90
+ Napi::HandleScope scope(Env());
91
+ deferred.Resolve(Napi::Boolean::New(Env(), result));
92
+ }
84
93
 
85
- void OnError(const Napi::Error &e) override { deferred.Reject(e.Value()); }
94
+ void OnError(const Napi::Error &e) override {
95
+ Napi::HandleScope scope(Env());
96
+ deferred.Reject(e.Value());
97
+ }
86
98
  };
87
99
 
88
100
  class SetHiddenWorker : public Napi::AsyncWorker {
@@ -93,11 +105,16 @@ class SetHiddenWorker : public Napi::AsyncWorker {
93
105
  public:
94
106
  SetHiddenWorker(Napi::Env env, std::string p, bool v,
95
107
  Napi::Promise::Deferred def)
96
- : Napi::AsyncWorker(env), path(std::move(p)), value(v),
97
- deferred(std::move(def)) {}
108
+ : Napi::AsyncWorker(env), path(std::move(p)), value(v), deferred(def) {}
98
109
 
99
110
  void Execute() override {
100
111
  try {
112
+ // Add path validation to prevent directory traversal
113
+ if (path.find("..") != std::string::npos) {
114
+ throw FSException("Invalid path containing '..'",
115
+ ERROR_INVALID_PARAMETER);
116
+ }
117
+
101
118
  auto wpath = PathConverter::ToWString(path);
102
119
  FileAttributeHandler handler(wpath);
103
120
  handler.setHidden(value);
@@ -108,9 +125,15 @@ public:
108
125
  }
109
126
  }
110
127
 
111
- void OnOK() override { deferred.Resolve(Napi::Boolean::New(Env(), true)); }
128
+ void OnOK() override {
129
+ Napi::HandleScope scope(Env());
130
+ deferred.Resolve(Napi::Boolean::New(Env(), true));
131
+ }
112
132
 
113
- void OnError(const Napi::Error &e) override { deferred.Reject(e.Value()); }
133
+ void OnError(const Napi::Error &e) override {
134
+ Napi::HandleScope scope(Env());
135
+ deferred.Reject(e.Value());
136
+ }
114
137
  };
115
138
 
116
139
  Napi::Promise GetHiddenAttribute(const Napi::CallbackInfo &info) {
@@ -123,8 +146,7 @@ Napi::Promise GetHiddenAttribute(const Napi::CallbackInfo &info) {
123
146
  }
124
147
 
125
148
  std::string path = info[0].As<Napi::String>();
126
- auto *worker =
127
- new GetHiddenWorker(env, std::move(path), std::move(deferred));
149
+ auto *worker = new GetHiddenWorker(env, std::move(path), deferred);
128
150
  worker->Queue();
129
151
 
130
152
  return deferred.Promise();
@@ -146,8 +168,7 @@ Napi::Promise SetHiddenAttribute(const Napi::CallbackInfo &info) {
146
168
  std::string path = info[0].As<Napi::String>();
147
169
  bool value = info[1].As<Napi::Boolean>();
148
170
 
149
- auto *worker =
150
- new SetHiddenWorker(env, std::move(path), value, std::move(deferred));
171
+ auto *worker = new SetHiddenWorker(env, std::move(path), value, deferred);
151
172
  worker->Queue();
152
173
 
153
174
  return deferred.Promise();
@@ -24,11 +24,20 @@ class WNetConnection {
24
24
 
25
25
  public:
26
26
  explicit WNetConnection(const std::string &path)
27
- : drivePath(path.substr(0, 2)), bufferSize(BUFFER_SIZE),
28
- buffer(std::make_unique<char[]>(BUFFER_SIZE)) {
27
+ : drivePath(path.substr(0, 2)), bufferSize(MAX_PATH) {
28
+
29
+ // Allocate initial buffer
30
+ buffer = std::make_unique<char[]>(bufferSize);
29
31
 
30
32
  DWORD result =
31
33
  WNetGetConnectionA(drivePath.c_str(), buffer.get(), &bufferSize);
34
+
35
+ if (result == ERROR_MORE_DATA) {
36
+ // bufferSize now contains the required size
37
+ buffer = std::make_unique<char[]>(bufferSize);
38
+ result = WNetGetConnectionA(drivePath.c_str(), buffer.get(), &bufferSize);
39
+ }
40
+
32
41
  isValid = (result == NO_ERROR);
33
42
  }
34
43
 
@@ -70,8 +79,9 @@ inline std::string GetVolumeGUID(const std::string &mountPoint) {
70
79
 
71
80
  // RAII wrapper for volume information
72
81
  class VolumeInfo {
73
- char volumeName[BUFFER_SIZE];
74
- char fstype[BUFFER_SIZE];
82
+ static constexpr DWORD VOLUME_NAME_SIZE = MAX_PATH + 1; // 261 characters
83
+ char volumeName[VOLUME_NAME_SIZE];
84
+ char fstype[VOLUME_NAME_SIZE];
75
85
  DWORD serialNumber;
76
86
  DWORD maxComponentLen;
77
87
  DWORD fsFlags;
@@ -79,9 +89,9 @@ class VolumeInfo {
79
89
 
80
90
  public:
81
91
  explicit VolumeInfo(const std::string &mountPoint) {
82
- valid = GetVolumeInformationA(mountPoint.c_str(), volumeName, BUFFER_SIZE,
83
- &serialNumber, &maxComponentLen, &fsFlags,
84
- fstype, BUFFER_SIZE);
92
+ valid = GetVolumeInformationA(
93
+ mountPoint.c_str(), volumeName, VOLUME_NAME_SIZE, &serialNumber,
94
+ &maxComponentLen, &fsFlags, fstype, VOLUME_NAME_SIZE);
85
95
 
86
96
  if (!valid && GetLastError() != ERROR_NOT_READY) {
87
97
  throw FSException("GetVolumeInformation", GetLastError());
package/tsup.config.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  import { defineConfig } from "tsup";
2
2
 
3
3
  export default defineConfig({
4
+ entry: ["src/index.ts"],
5
+ format: ["cjs", "esm"],
6
+ dts: true, // Generate .d.ts files automatically
7
+ clean: true, // Clean dist before each build
8
+ sourcemap: true,
4
9
  outExtension: ({ format }) => ({
5
10
  js: format === "cjs" ? ".cjs" : ".mjs", // Use .cjs for CommonJS and .mjs for ESM
6
11
  }),
7
- shims: true,
8
- sourcemap: true,
12
+ shims: true, // Inject CJS shims (__dirname, __filename) in ESM output
13
+ target: "es2022", // Align with TypeScript target
14
+ tsconfig: "tsconfig.build.json", // Use a single tsconfig for building
9
15
  });
@@ -1,25 +0,0 @@
1
- /**
2
- * Remove duplicate elements from an array.
3
- *
4
- * - Primitive values are compared using strict equality.
5
- * - Objects and arrays are compared by reference.
6
- *
7
- * @return A new array with duplicate elements removed
8
- */
9
- export declare function uniq<T>(arr: T[]): T[];
10
- /**
11
- * Remove duplicate elements from an array based on a key function.
12
- * @param keyFn A function that returns a key for each element. Elements that
13
- * the key function returns nullish will be removed from the returned array.
14
- * @return a new array omitting duplicate elements based on a key function.
15
- */
16
- export declare function uniqBy<T, K>(arr: T[], keyFn: (item: T) => K | undefined): T[];
17
- /**
18
- * @return an array of specified length, with each element created by calling
19
- * the provided function.
20
- */
21
- export declare function times<T>(length: number, fn: (index: number) => T): T[];
22
- /**
23
- * @return a new array with elements that are not `null` or `undefined`.
24
- */
25
- export declare function compact<T>(arr: (T | null | undefined)[] | undefined): T[];
@@ -1,42 +0,0 @@
1
- /**
2
- * An error that is thrown when a promise does not resolve within the specified
3
- * time.
4
- */
5
- export declare class TimeoutError extends Error {
6
- constructor(message: string, captureStackTrace?: boolean);
7
- }
8
- /**
9
- * Rejects the promise with a TimeoutError if it does not resolve within the
10
- * specified time.
11
- *
12
- * @param promise The promise to wrap.
13
- * @param timeoutMs The timeout in milliseconds. Timeouts are disabled if this is 0.
14
- * @returns A promise that resolves when the input promise resolves, or rejects
15
- * with a TimeoutError if the input promise does not resolve within the
16
- * specified time.
17
- * @throws {TimeoutError} if the input promise does not resolve within the
18
- * specified time.
19
- * @throws {TypeError} if timeoutMs is not a number that is greater than 0.
20
- */
21
- export declare function withTimeout<T>(opts: {
22
- desc?: string;
23
- promise: Promise<T>;
24
- timeoutMs: number;
25
- }): Promise<T>;
26
- /**
27
- * Delay for the specified number of milliseconds.
28
- *
29
- * @param ms The number of milliseconds to delay
30
- * @param t Optional value to resolve with after delay
31
- * @returns Promise that resolves with the provided value (or void if none provided)
32
- */
33
- export declare function delay<T = void>(ms: number, t?: T): Promise<T>;
34
- /**
35
- * Apply `fn` to every item in `items` with a maximum concurrency of
36
- * `maxConcurrency`.
37
- */
38
- export declare function mapConcurrent<I, O>({ items, fn, maxConcurrency, }: {
39
- items: I[];
40
- fn: (t: I) => Promise<O>;
41
- maxConcurrency?: number;
42
- }): Promise<(O | Error)[]>;
@@ -1,3 +0,0 @@
1
- export declare const debugLogContext: () => string;
2
- export declare const isDebugEnabled: () => boolean;
3
- export declare function debug(msg: string, ...args: unknown[]): void;
@@ -1,10 +0,0 @@
1
- export type Defer<T> = (() => T) & {
2
- reset: () => void;
3
- };
4
- /**
5
- * Creates a deferred value that is computed once on first access and cached for
6
- * subsequent accesses.
7
- * @param thunk A function that takes no arguments and returns a value
8
- * @returns A function that returns the computed value
9
- */
10
- export declare function defer<T>(thunk: () => T): Defer<T>;
@@ -1 +0,0 @@
1
- export declare function _dirname(): string;
@@ -1,17 +0,0 @@
1
- export declare class WrappedError extends Error {
2
- errno?: number;
3
- code?: string;
4
- syscall?: string;
5
- path?: string;
6
- constructor(context: string, options?: {
7
- name?: string;
8
- cause?: unknown;
9
- errno?: number;
10
- code?: string;
11
- syscall?: string;
12
- path?: string;
13
- });
14
- get details(): Record<string, unknown>;
15
- toString(): string;
16
- }
17
- export declare function toError(cause: unknown): Error;
@@ -1,22 +0,0 @@
1
- import { type PathLike, type StatOptions, Stats } from "node:fs";
2
- /**
3
- * Wrapping node:fs/promises.stat() so we can mock it in tests.
4
- */
5
- export declare function statAsync(path: PathLike, options?: StatOptions & {
6
- bigint?: false;
7
- }): Promise<Stats>;
8
- export declare function canStatAsync(path: string): Promise<boolean>;
9
- /**
10
- * @return true if `path` exists and is a directory
11
- */
12
- export declare function isDirectory(path: string): Promise<boolean>;
13
- /**
14
- * @return the first directory containing `file` or an empty string
15
- */
16
- export declare function findAncestorDir(dir: string, file: string): Promise<string | undefined>;
17
- export declare function existsSync(path: string): boolean;
18
- /**
19
- * @return `true` if `dir` exists and is a directory and at least one entry can be read.
20
- * @throws {Error} if `dir` does not exist or is not a directory or cannot be read.
21
- */
22
- export declare function canReaddir(dir: string, timeoutMs: number): Promise<true>;
@@ -1,17 +0,0 @@
1
- /**
2
- * Compiles an array of glob patterns into a single regular expression.
3
- *
4
- * The function supports the following patterns:
5
- * - `**` matches any number of directories.
6
- * - `*` matches any number of characters except for `/`.
7
- * - `?` matches exactly one character except for `/`.
8
- * - `.` is escaped to match a literal period.
9
- * - `/` at the end of the pattern matches either a slash or the end of the string.
10
- * - Other regex special characters are escaped.
11
- *
12
- * @param patterns - An array of glob patterns to compile.
13
- * @returns A `RegExp` object that matches any of the provided patterns.
14
- */
15
- export declare function compileGlob(patterns: string[] | readonly string[] | undefined): RegExp;
16
- export declare const AlwaysMatchRE: RegExp;
17
- export declare const NeverMatchRE: RegExp;
@@ -1,29 +0,0 @@
1
- import type { HiddenMetadata } from "./types/hidden_metadata.js";
2
- import type { NativeBindingsFn } from "./types/native_bindings.js";
3
- export declare const LocalSupport: {
4
- dotPrefix: boolean;
5
- systemFlag: boolean;
6
- };
7
- /**
8
- * Checks if the file or directory is hidden through any available method
9
- * @returns A boolean indicating if the item is hidden
10
- * @throws {Error} If the file doesn't exist or permissions are insufficient
11
- */
12
- export declare function isHiddenImpl(pathname: string, nativeFn: NativeBindingsFn): Promise<boolean>;
13
- export declare function isHiddenRecursiveImpl(path: string, nativeFn: NativeBindingsFn): Promise<boolean>;
14
- export declare function createHiddenPosixPath(pathname: string, hidden: boolean): string;
15
- /**
16
- * Gets detailed information about the hidden state of the file or directory
17
- * @returns An object containing detailed hidden state information
18
- * @throws {Error} If the file doesn't exist or permissions are insufficient
19
- */
20
- export declare function getHiddenMetadataImpl(pathname: string, nativeFn: NativeBindingsFn): Promise<HiddenMetadata>;
21
- export type HideMethod = "dotPrefix" | "systemFlag" | "all" | "auto";
22
- export type SetHiddenResult = {
23
- pathname: string;
24
- actions: {
25
- dotPrefix: boolean;
26
- systemFlag: boolean;
27
- };
28
- };
29
- export declare function setHiddenImpl(pathname: string, hide: boolean, method: HideMethod, nativeFn: NativeBindingsFn): Promise<SetHiddenResult>;
@@ -1,91 +0,0 @@
1
- import type { HideMethod, SetHiddenResult } from "./hidden.js";
2
- import { IncludeSystemVolumesDefault, LinuxMountTablePathsDefault, OptionsDefault, optionsWithDefaults, SystemFsTypesDefault, SystemPathPatternsDefault, TimeoutMsDefault } from "./options.js";
3
- import type { StringEnum, StringEnumKeys, StringEnumType } from "./string_enum.js";
4
- import type { SystemVolumeConfig } from "./system_volume.js";
5
- import type { HiddenMetadata } from "./types/hidden_metadata.js";
6
- import type { MountPoint } from "./types/mount_point.js";
7
- import type { Options } from "./types/options.js";
8
- import type { VolumeMetadata } from "./types/volume_metadata.js";
9
- import type { VolumeHealthStatus } from "./volume_health_status.js";
10
- import { VolumeHealthStatuses } from "./volume_health_status.js";
11
- import type { GetVolumeMountPointOptions } from "./volume_mount_points.js";
12
- export type { GetVolumeMountPointOptions, HiddenMetadata, HideMethod, MountPoint, Options, SetHiddenResult, StringEnum, StringEnumKeys, StringEnumType, SystemVolumeConfig, VolumeHealthStatus, VolumeMetadata, };
13
- /**
14
- * List all active local and remote mount points on the system.
15
- *
16
- * Only readable directories are included in the results.
17
- *
18
- * Note that on Windows, `timeoutMs` will be used **per system call** and not
19
- * for the entire operation.
20
- *
21
- * @param opts Optional filesystem operation settings to override default values
22
- */
23
- export declare function getVolumeMountPoints(opts?: Partial<GetVolumeMountPointOptions>): Promise<MountPoint[]>;
24
- /**
25
- * Get metadata for the volume at the given mount point.
26
- *
27
- * @param mountPoint Must be a non-blank string
28
- * @param opts Optional filesystem operation settings
29
- */
30
- export declare function getVolumeMetadata(mountPoint: string, opts?: Partial<Pick<Options, "timeoutMs">>): Promise<VolumeMetadata>;
31
- /**
32
- * Retrieves metadata for all mounted volumes with optional filtering and
33
- * concurrency control.
34
- *
35
- * @param opts - Optional configuration object
36
- * @param opts.includeSystemVolumes - If true, includes system volumes in the
37
- * results. Defaults to true on Windows and false elsewhere.
38
- * @param opts.maxConcurrency - Maximum number of concurrent operations.
39
- * Defaults to the system's available parallelism: see
40
- * {@link https://nodejs.org/api/os.html#osavailableparallelism | os.availableParallelism()}
41
- * @param opts.timeoutMs - Maximum time to wait for
42
- * {@link getVolumeMountPointsImpl}, as well as **each** {@link getVolumeMetadataImpl}
43
- * to complete. Defaults to {@link TimeoutMsDefault}
44
- * @returns Promise that resolves to an array of either VolumeMetadata objects
45
- * or error objects containing the mount point and error
46
- * @throws Never - errors are caught and returned as part of the result array
47
- */
48
- export declare function getAllVolumeMetadata(opts?: Partial<Options> & {
49
- includeSystemVolumes?: boolean;
50
- }): Promise<VolumeMetadata[]>;
51
- /**
52
- * Check if a file or directory is hidden.
53
- *
54
- * Note that `path` may be _effectively_ hidden if any of the ancestor
55
- * directories are hidden: use {@link isHiddenRecursive} to check for this.
56
- *
57
- * @param pathname Path to file or directory
58
- * @returns Promise resolving to boolean indicating hidden state
59
- */
60
- export declare function isHidden(pathname: string): Promise<boolean>;
61
- /**
62
- * Check if a file or directory is hidden, or if any of its ancestor
63
- * directories are hidden.
64
- *
65
- * @param pathname Path to file or directory
66
- * @returns Promise resolving to boolean indicating hidden state
67
- */
68
- export declare function isHiddenRecursive(pathname: string): Promise<boolean>;
69
- /**
70
- * Get detailed metadata about the hidden state of a file or directory.
71
- *
72
- * @param pathname Path to file or directory
73
- * @returns Promise resolving to metadata about the hidden state
74
- */
75
- export declare function getHiddenMetadata(pathname: string): Promise<HiddenMetadata>;
76
- /**
77
- * Set the hidden state of a file or directory
78
- *
79
- * @param pathname Path to file or directory
80
- * @param hidden - Whether the item should be hidden (true) or visible (false)
81
- * @param method Method to use for hiding the file or directory. The default
82
- * is "auto", which is "dotPrefix" on Linux and macOS, and "systemFlag" on
83
- * Windows. "all" will attempt to use all relevant methods for the current
84
- * operating system.
85
- * @returns Promise resolving the final name of the file or directory (as it
86
- * will change on POSIX systems), and the action(s) taken.
87
- * @throws {Error} If the file doesn't exist, permissions are insufficient, or
88
- * the requested method is unsupported
89
- */
90
- export declare function setHidden(pathname: string, hidden: boolean, method?: HideMethod): Promise<SetHiddenResult>;
91
- export { IncludeSystemVolumesDefault, LinuxMountTablePathsDefault, OptionsDefault, optionsWithDefaults, SystemFsTypesDefault, SystemPathPatternsDefault, TimeoutMsDefault, VolumeHealthStatuses, };
@@ -1,13 +0,0 @@
1
- /**
2
- * Gets the UUID from symlinks for a given device path asynchronously
3
- * @param devicePath The device path to look up
4
- * @returns Promise that resolves to the UUID if found, empty string otherwise
5
- */
6
- export declare function getUuidFromDevDisk(devicePath: string): Promise<string | undefined>;
7
- /**
8
- * Gets the label from symlinks for a given device path asynchronously
9
- * @param devicePath The device path to look up
10
- * @returns Promise that resolves to the label if found, empty string otherwise
11
- */
12
- export declare function getLabelFromDevDisk(devicePath: string): Promise<string | undefined>;
13
- export declare function getBasenameLinkedTo(linkDir: string, linkPath: string): Promise<string | undefined>;
@@ -1,6 +0,0 @@
1
- import { type MountPoint } from "../types/mount_point.js";
2
- import type { NativeBindingsFn } from "../types/native_bindings.js";
3
- import type { Options } from "../types/options.js";
4
- import { MountEntry } from "./mtab.js";
5
- export declare function getLinuxMountPoints(native: NativeBindingsFn, opts?: Pick<Options, "linuxMountTablePaths">): Promise<MountPoint[]>;
6
- export declare function getLinuxMtabMetadata(mountPoint: string, opts?: Pick<Options, "linuxMountTablePaths">): Promise<MountEntry>;
@@ -1,47 +0,0 @@
1
- import { SystemVolumeConfig } from "../system_volume.js";
2
- import type { MountPoint } from "../types/mount_point.js";
3
- import type { VolumeMetadata } from "../types/volume_metadata.js";
4
- /**
5
- * Represents an entry in the mount table.
6
- */
7
- export interface MountEntry {
8
- /**
9
- * Device or remote filesystem
10
- */
11
- fs_spec: string;
12
- /**
13
- * Mount point
14
- */
15
- fs_file: string;
16
- /**
17
- * Filesystem type
18
- */
19
- fs_vfstype: string;
20
- /**
21
- * Mount options
22
- */
23
- fs_mntops: string | undefined;
24
- /**
25
- * Dump frequency
26
- */
27
- fs_freq: number | undefined;
28
- /**
29
- * fsck pass number
30
- */
31
- fs_passno: number | undefined;
32
- }
33
- export declare function mountEntryToMountPoint(entry: MountEntry): MountPoint | undefined;
34
- export type MtabVolumeMetadata = Omit<VolumeMetadata, "size" | "used" | "available" | "label" | "uuid" | "status">;
35
- export declare function mountEntryToPartialVolumeMetadata(entry: MountEntry, options?: Partial<SystemVolumeConfig>): MtabVolumeMetadata;
36
- /**
37
- * Parses an mtab/fstab file content into structured mount entries
38
- * @param content - Raw content of the mtab/fstab file
39
- * @returns Array of parsed mount entries
40
- */
41
- export declare function parseMtab(content: string): MountEntry[];
42
- /**
43
- * Formats mount entries back into mtab file format
44
- * @param entries - Array of mount entries
45
- * @returns Formatted mtab file content
46
- */
47
- export declare function formatMtab(entries: MountEntry[]): string;
@@ -1,2 +0,0 @@
1
- import { MountPoint } from "./types/mount_point";
2
- export declare function isMountPoint(obj: unknown): obj is MountPoint;
@@ -1,3 +0,0 @@
1
- export declare function isNumber(value: unknown): value is number;
2
- export declare function toInt(value: unknown): number | undefined;
3
- export declare function gt0(value: unknown): value is number;
@@ -1,18 +0,0 @@
1
- /**
2
- * @return true iff value is an object and not an array
3
- */
4
- export declare function isObject(value: unknown): value is object;
5
- /**
6
- * @return undefined if `obj` is nullish, or the return value of `fn` applied
7
- * against `obj` if `obj` is defined
8
- */
9
- export declare function map<T, U>(obj: T | undefined, fn: (value: T) => U): U | undefined;
10
- /**
11
- * @return a shallow copy of `obj` that omits the specified `keys`
12
- */
13
- export declare function omit<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
14
- /**
15
- * @return a shallow copy of `obj` that only includes fields that are defined
16
- * and not nullish or blank.
17
- */
18
- export declare function compactValues<T extends object>(obj: T | undefined): Partial<T>;
@@ -1,33 +0,0 @@
1
- import type { Options } from "./types/options.js";
2
- /**
3
- * Default timeout in milliseconds for {@link Options.timeoutMs}.
4
- *
5
- * Note that this timeout may be insufficient for some devices, like spun-down
6
- * optical drives or network shares that need to spin up or reconnect.
7
- */
8
- export declare const TimeoutMsDefault: 5000;
9
- /**
10
- * System paths and globs that indicate system volumes
11
- */
12
- export 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"];
13
- /**
14
- * Filesystem types that indicate system volumes
15
- */
16
- export 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"];
17
- export declare const LinuxMountTablePathsDefault: readonly ["/proc/self/mounts", "/proc/mounts", "/etc/mtab"];
18
- /**
19
- * Should {@link getAllVolumeMetadata} include system volumes by
20
- * default?
21
- */
22
- export declare const IncludeSystemVolumesDefault: boolean;
23
- /**
24
- * Default {@link Options} object.
25
- *
26
- * @see {@link optionsWithDefaults} for creating an options object with default values
27
- */
28
- export declare const OptionsDefault: Options;
29
- /**
30
- * Create an {@link Options} object using default values from
31
- * {@link OptionsDefault} for missing fields.
32
- */
33
- export declare function optionsWithDefaults<T extends Options>(overrides?: Partial<T>): T;
@@ -1,17 +0,0 @@
1
- export declare function normalizePath(mountPoint: string | undefined): string | undefined;
2
- /**
3
- * Normalizes a Linux or macOS mount point by removing any trailing slashes.
4
- * This is a no-op for root mount points.
5
- */
6
- export declare function normalizePosixPath(mountPoint: string | undefined): string | undefined;
7
- /**
8
- * Normalizes a Windows mount point by ensuring drive letters end with a
9
- * backslash.
10
- */
11
- export declare function normalizeWindowsPath(mountPoint: string): string;
12
- /**
13
- * @return true if `path` is the root directory--this is platform-specific. Only
14
- * "/" on linux/macOS is considered a root directory. On Windows, the root
15
- * directory is a drive letter followed by a colon, e.g. "C:\".
16
- */
17
- export declare function isRootDirectory(path: string): boolean;
@@ -1,4 +0,0 @@
1
- export declare const isLinux: boolean;
2
- export declare const isWindows: boolean;
3
- export declare const isMacOS: boolean;
4
- export declare const isArm: boolean;
@@ -1,12 +0,0 @@
1
- /**
2
- * @return a random character `[a-z]`
3
- */
4
- export declare function randomLetter(): string;
5
- export declare function randomLetters(length: number): string;
6
- /**
7
- * Shuffle an array using the Fisher-Yates (Knuth) algorithm.
8
- * @param a The array to shuffle
9
- * @returns A shallow shuffled copy of `a`
10
- */
11
- export declare function shuffle<T>(a: T[]): T[];
12
- export declare function pickRandom<T>(a: T[]): T;
@@ -1,6 +0,0 @@
1
- import { RemoteInfo } from "./types/remote_info.js";
2
- export declare function isRemoteInfo(obj: unknown): obj is RemoteInfo;
3
- export declare function normalizeFsType(fstype: string): string;
4
- export declare function isRemoteFsType(fstype: string | undefined): boolean;
5
- export declare function parseURL(s: string): URL | undefined;
6
- export declare function extractRemoteInfo(fsSpec: string | undefined): RemoteInfo | undefined;
@@ -1,2 +0,0 @@
1
- export declare function getCallerDirname(): string;
2
- export declare function extractCallerPath(stack: string): string;
@@ -1,37 +0,0 @@
1
- export declare function isString(input: unknown): input is string;
2
- export declare function toS(input: unknown): string;
3
- /**
4
- * @return true iff the input is a string and has at least one non-whitespace character
5
- */
6
- export declare function isNotBlank(input: unknown): input is string;
7
- /**
8
- * @return true iff the input is not a string or only has non-whitespace characters
9
- */
10
- export declare function isBlank(input: unknown): input is undefined;
11
- export declare function toNotBlank(input: unknown): string | undefined;
12
- /**
13
- * Decodes a string containing octal (\000-\377) and/or hexadecimal
14
- * (\x00-\xFF) escape sequences
15
- * @param input The string containing escape sequences to decode
16
- * @returns The decoded string with escape sequences converted to their
17
- * corresponding characters
18
- * @throws Error if an invalid escape sequence is encountered
19
- */
20
- export declare function decodeEscapeSequences(input: string): string;
21
- export declare function encodeEscapeSequences(input: string): string;
22
- /**
23
- * Sort an array of strings using the locale-aware collation algorithm.
24
- *
25
- * @param arr The array of strings to sort. The original array **is sorted in
26
- * place**.
27
- */
28
- export declare function sortByLocale(arr: string[], locales?: Intl.LocalesArgument, options?: Intl.CollatorOptions): string[];
29
- /**
30
- * Sort an array of objects using the locale-aware collation algorithm.
31
- *
32
- * @param arr The array of objects to sort.
33
- * @param fn The function to extract the key to sort by from each object.
34
- * @param locales The locales to use for sorting.
35
- * @param options The collation options to use for sorting.
36
- */
37
- export declare function sortObjectsByLocale<T>(arr: T[], fn: (key: T) => string, locales?: Intl.LocalesArgument, options?: Intl.CollatorOptions): T[];