@gjsify/fs 0.3.13 → 0.3.14

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/lib/esm/sync.js CHANGED
@@ -1,393 +1,418 @@
1
+ import { decode, encodeUint8Array, getEncodingFromOptions } from "./encoding.js";
2
+ import { normalizePath, tempDirPath } from "./utils.js";
3
+ import { FSWatcher } from "./fs-watcher.js";
4
+ import { Dirent } from "./dirent.js";
5
+ import { BigIntStats, STAT_ATTRIBUTES, Stats } from "./stats.js";
6
+ import { FileHandle } from "./file-handle.js";
7
+ import { createNodeError as createNodeError$1, isNotFoundError } from "./errors.js";
1
8
  import GLib from "@girs/glib-2.0";
2
9
  import Gio from "@girs/gio-2.0";
3
- import { existsSync } from "@gjsify/utils";
4
- import { Buffer } from "node:buffer";
5
10
  import { join } from "node:path";
6
- import FSWatcher from "./fs-watcher.js";
7
- import { getEncodingFromOptions, encodeUint8Array, decode } from "./encoding.js";
8
- import { FileHandle } from "./file-handle.js";
9
- import { Dirent } from "./dirent.js";
10
- import { Stats, BigIntStats, STAT_ATTRIBUTES } from "./stats.js";
11
- import { createNodeError, isNotFoundError } from "./errors.js";
12
- import { tempDirPath, normalizePath } from "./utils.js";
11
+ import { Buffer } from "node:buffer";
12
+ import { existsSync } from "@gjsify/utils";
13
+
14
+ //#region src/sync.ts
13
15
  function statSync(path, options) {
14
- const pathStr = normalizePath(path);
15
- try {
16
- const file = Gio.File.new_for_path(pathStr);
17
- const info = file.query_info(STAT_ATTRIBUTES, Gio.FileQueryInfoFlags.NONE, null);
18
- return options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr);
19
- } catch (err) {
20
- if (options?.throwIfNoEntry === false && isNotFoundError(err)) return void 0;
21
- throw createNodeError(err, "stat", pathStr);
22
- }
16
+ const pathStr = normalizePath(path);
17
+ try {
18
+ const file = Gio.File.new_for_path(pathStr);
19
+ const info = file.query_info(STAT_ATTRIBUTES, Gio.FileQueryInfoFlags.NONE, null);
20
+ return options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr);
21
+ } catch (err) {
22
+ if (options?.throwIfNoEntry === false && isNotFoundError(err)) return undefined;
23
+ throw createNodeError$1(err, "stat", pathStr);
24
+ }
23
25
  }
24
26
  function lstatSync(path, options) {
25
- const pathStr = normalizePath(path);
26
- try {
27
- const file = Gio.File.new_for_path(pathStr);
28
- const info = file.query_info(STAT_ATTRIBUTES, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
29
- return options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr);
30
- } catch (err) {
31
- if (options?.throwIfNoEntry === false && isNotFoundError(err)) return void 0;
32
- throw createNodeError(err, "lstat", pathStr);
33
- }
27
+ const pathStr = normalizePath(path);
28
+ try {
29
+ const file = Gio.File.new_for_path(pathStr);
30
+ const info = file.query_info(STAT_ATTRIBUTES, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
31
+ return options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr);
32
+ } catch (err) {
33
+ if (options?.throwIfNoEntry === false && isNotFoundError(err)) return undefined;
34
+ throw createNodeError$1(err, "lstat", pathStr);
35
+ }
34
36
  }
35
37
  function readdirSync(path, options) {
36
- const pathStr = normalizePath(path);
37
- const file = Gio.File.new_for_path(pathStr);
38
- const enumerator = file.enumerate_children(
39
- "standard::name,standard::type",
40
- Gio.FileQueryInfoFlags.NONE,
41
- null
42
- );
43
- const result = [];
44
- let info = enumerator.next_file(null);
45
- while (info !== null) {
46
- const childName = info.get_name();
47
- const childPath = join(pathStr, childName);
48
- if (options?.withFileTypes) {
49
- result.push(new Dirent(childPath, childName));
50
- } else {
51
- result.push(childName);
52
- }
53
- if (options?.recursive && info.get_file_type() === Gio.FileType.DIRECTORY) {
54
- const subEntries = readdirSync(childPath, options);
55
- for (const entry of subEntries) {
56
- if (typeof entry === "string") {
57
- result.push(join(childName, entry));
58
- } else {
59
- result.push(entry);
60
- }
61
- }
62
- }
63
- info = enumerator.next_file(null);
64
- }
65
- return result;
38
+ const pathStr = normalizePath(path);
39
+ const file = Gio.File.new_for_path(pathStr);
40
+ const enumerator = file.enumerate_children("standard::name,standard::type", Gio.FileQueryInfoFlags.NONE, null);
41
+ const result = [];
42
+ let info = enumerator.next_file(null);
43
+ while (info !== null) {
44
+ const childName = info.get_name();
45
+ const childPath = join(pathStr, childName);
46
+ if (options?.withFileTypes) {
47
+ result.push(new Dirent(childPath, childName));
48
+ } else {
49
+ result.push(childName);
50
+ }
51
+ if (options?.recursive && info.get_file_type() === Gio.FileType.DIRECTORY) {
52
+ const subEntries = readdirSync(childPath, options);
53
+ for (const entry of subEntries) {
54
+ if (typeof entry === "string") {
55
+ result.push(join(childName, entry));
56
+ } else {
57
+ result.push(entry);
58
+ }
59
+ }
60
+ }
61
+ info = enumerator.next_file(null);
62
+ }
63
+ return result;
66
64
  }
67
65
  const MAX_SYMLINK_DEPTH = 40;
68
66
  function realpathSync(path) {
69
- const pathStr = normalizePath(path);
70
- let current = Gio.File.new_for_path(pathStr);
71
- let depth = 0;
72
- while (true) {
73
- const info = current.query_info(
74
- "standard::is-symlink,standard::symlink-target",
75
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
76
- null
77
- );
78
- if (!info.get_is_symlink()) {
79
- return current.get_path();
80
- }
81
- const target = info.get_symlink_target();
82
- const parent = current.get_parent();
83
- current = parent ? parent.resolve_relative_path(target) : Gio.File.new_for_path(target);
84
- if (++depth > MAX_SYMLINK_DEPTH) {
85
- throw new Error(`ELOOP: too many levels of symbolic links, realpath '${pathStr}'`);
86
- }
87
- }
67
+ const pathStr = normalizePath(path);
68
+ let current = Gio.File.new_for_path(pathStr);
69
+ let depth = 0;
70
+ while (true) {
71
+ const info = current.query_info("standard::is-symlink,standard::symlink-target", Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
72
+ if (!info.get_is_symlink()) {
73
+ return current.get_path();
74
+ }
75
+ const target = info.get_symlink_target();
76
+ const parent = current.get_parent();
77
+ current = parent ? parent.resolve_relative_path(target) : Gio.File.new_for_path(target);
78
+ if (++depth > MAX_SYMLINK_DEPTH) {
79
+ throw new Error(`ELOOP: too many levels of symbolic links, realpath '${pathStr}'`);
80
+ }
81
+ }
88
82
  }
89
83
  realpathSync.native = realpathSync;
90
84
  function symlinkSync(target, path, _type) {
91
- const pathStr = normalizePath(path);
92
- const targetStr = normalizePath(target);
93
- const file = Gio.File.new_for_path(pathStr);
94
- file.make_symbolic_link(targetStr, null);
85
+ const pathStr = normalizePath(path);
86
+ const targetStr = normalizePath(target);
87
+ const file = Gio.File.new_for_path(pathStr);
88
+ file.make_symbolic_link(targetStr, null);
95
89
  }
96
- function readFileSync(path, options = { encoding: null, flag: "r" }) {
97
- const pathStr = normalizePath(path);
98
- const file = Gio.File.new_for_path(pathStr);
99
- try {
100
- const [ok, data] = file.load_contents(null);
101
- if (!ok) {
102
- throw createNodeError(new Error("failed to read file"), "read", pathStr);
103
- }
104
- return encodeUint8Array(getEncodingFromOptions(options, "buffer"), data);
105
- } catch (err) {
106
- if (err.code && typeof err.code === "string") throw err;
107
- throw createNodeError(err, "read", pathStr);
108
- }
90
+ function readFileSync(path, options = {
91
+ encoding: null,
92
+ flag: "r"
93
+ }) {
94
+ const pathStr = normalizePath(path);
95
+ const file = Gio.File.new_for_path(pathStr);
96
+ try {
97
+ const [ok, data] = file.load_contents(null);
98
+ if (!ok) {
99
+ throw createNodeError$1(new Error("failed to read file"), "read", pathStr);
100
+ }
101
+ return encodeUint8Array(getEncodingFromOptions(options, "buffer"), data);
102
+ } catch (err) {
103
+ if (err.code && typeof err.code === "string") throw err;
104
+ throw createNodeError$1(err, "read", pathStr);
105
+ }
109
106
  }
107
+ /**
108
+ * Synchronous mkdir(2) - create a directory.
109
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
110
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
111
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
112
+ */
110
113
  function mkdirSync(path, options) {
111
- let recursive = false;
112
- let mode = 511;
113
- if (typeof options === "object") {
114
- if (options?.recursive) recursive = options.recursive;
115
- if (options?.mode) mode = options.mode;
116
- } else {
117
- mode = options || 511;
118
- }
119
- path = normalizePath(path);
120
- if (typeof mode === "string") {
121
- throw new TypeError("mode as string is currently not supported!");
122
- }
123
- if (recursive) {
124
- return mkdirSyncRecursive(path, mode);
125
- }
126
- const file = Gio.File.new_for_path(path);
127
- try {
128
- file.make_directory(null);
129
- } catch (err) {
130
- throw createNodeError(err, "mkdir", path);
131
- }
132
- return void 0;
114
+ let recursive = false;
115
+ let mode = 511;
116
+ if (typeof options === "object") {
117
+ if (options?.recursive) recursive = options.recursive;
118
+ if (options?.mode) mode = options.mode;
119
+ } else {
120
+ mode = options || 511;
121
+ }
122
+ path = normalizePath(path);
123
+ if (typeof mode === "string") {
124
+ throw new TypeError("mode as string is currently not supported!");
125
+ }
126
+ if (recursive) {
127
+ return mkdirSyncRecursive(path, mode);
128
+ }
129
+ const file = Gio.File.new_for_path(path);
130
+ try {
131
+ file.make_directory(null);
132
+ } catch (err) {
133
+ throw createNodeError$1(err, "mkdir", path);
134
+ }
135
+ return undefined;
133
136
  }
137
+ /**
138
+ * Recursively creates directories, similar to `mkdir -p`.
139
+ * Returns the first directory path created, or undefined if all directories already existed.
140
+ */
134
141
  function mkdirSyncRecursive(pathStr, mode) {
135
- const file = Gio.File.new_for_path(pathStr);
136
- try {
137
- file.make_directory(null);
138
- return pathStr;
139
- } catch (err) {
140
- const gErr = err;
141
- if (gErr.code === Gio.IOErrorEnum.EXISTS) {
142
- return void 0;
143
- }
144
- if (gErr.code === Gio.IOErrorEnum.NOT_FOUND) {
145
- const parentPath = join(pathStr, "..");
146
- const resolvedParent = Gio.File.new_for_path(parentPath).get_path();
147
- if (resolvedParent === pathStr) {
148
- throw createNodeError(err, "mkdir", pathStr);
149
- }
150
- const firstCreated = mkdirSyncRecursive(resolvedParent, mode);
151
- const retryFile = Gio.File.new_for_path(pathStr);
152
- try {
153
- retryFile.make_directory(null);
154
- } catch (retryErr) {
155
- throw createNodeError(retryErr, "mkdir", pathStr);
156
- }
157
- return firstCreated ?? pathStr;
158
- }
159
- throw createNodeError(err, "mkdir", pathStr);
160
- }
142
+ const file = Gio.File.new_for_path(pathStr);
143
+ try {
144
+ file.make_directory(null);
145
+ return pathStr;
146
+ } catch (err) {
147
+ const gErr = err;
148
+ if (gErr.code === Gio.IOErrorEnum.EXISTS) {
149
+ return undefined;
150
+ }
151
+ if (gErr.code === Gio.IOErrorEnum.NOT_FOUND) {
152
+ const parentPath = join(pathStr, "..");
153
+ const resolvedParent = Gio.File.new_for_path(parentPath).get_path();
154
+ if (resolvedParent === pathStr) {
155
+ throw createNodeError$1(err, "mkdir", pathStr);
156
+ }
157
+ const firstCreated = mkdirSyncRecursive(resolvedParent, mode);
158
+ const retryFile = Gio.File.new_for_path(pathStr);
159
+ try {
160
+ retryFile.make_directory(null);
161
+ } catch (retryErr) {
162
+ throw createNodeError$1(retryErr, "mkdir", pathStr);
163
+ }
164
+ return firstCreated ?? pathStr;
165
+ }
166
+ throw createNodeError$1(err, "mkdir", pathStr);
167
+ }
161
168
  }
169
+ /**
170
+ * Synchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). Returns `undefined`.
171
+ *
172
+ * Using `fs.rmdirSync()` on a file (not a directory) results in an `ENOENT` error
173
+ * on Windows and an `ENOTDIR` error on POSIX.
174
+ *
175
+ * To get a behavior similar to the `rm -rf` Unix command, use {@link rmSync} with options `{ recursive: true, force: true }`.
176
+ * @since v0.1.21
177
+ */
162
178
  function rmdirSync(path, _options) {
163
- const pathStr = normalizePath(path);
164
- const file = Gio.File.new_for_path(pathStr);
165
- try {
166
- const info = file.query_info("standard::type", Gio.FileQueryInfoFlags.NONE, null);
167
- if (info.get_file_type() !== Gio.FileType.DIRECTORY) {
168
- const err = Object.assign(new Error(), { code: 4 });
169
- throw createNodeError(err, "rmdir", pathStr);
170
- }
171
- const enumerator = file.enumerate_children("standard::name", Gio.FileQueryInfoFlags.NONE, null);
172
- if (enumerator.next_file(null) !== null) {
173
- const err = Object.assign(new Error(), { code: 5 });
174
- throw createNodeError(err, "rmdir", pathStr);
175
- }
176
- file.delete(null);
177
- } catch (err) {
178
- if (err.code && typeof err.code === "string") throw err;
179
- throw createNodeError(err, "rmdir", pathStr);
180
- }
179
+ const pathStr = normalizePath(path);
180
+ const file = Gio.File.new_for_path(pathStr);
181
+ try {
182
+ const info = file.query_info("standard::type", Gio.FileQueryInfoFlags.NONE, null);
183
+ if (info.get_file_type() !== Gio.FileType.DIRECTORY) {
184
+ const err = Object.assign(new Error(), { code: 4 });
185
+ throw createNodeError$1(err, "rmdir", pathStr);
186
+ }
187
+ const enumerator = file.enumerate_children("standard::name", Gio.FileQueryInfoFlags.NONE, null);
188
+ if (enumerator.next_file(null) !== null) {
189
+ const err = Object.assign(new Error(), { code: 5 });
190
+ throw createNodeError$1(err, "rmdir", pathStr);
191
+ }
192
+ file.delete(null);
193
+ } catch (err) {
194
+ if (err.code && typeof err.code === "string") throw err;
195
+ throw createNodeError$1(err, "rmdir", pathStr);
196
+ }
181
197
  }
182
198
  function unlinkSync(path) {
183
- const pathStr = normalizePath(path);
184
- const file = Gio.File.new_for_path(pathStr);
185
- try {
186
- file.delete(null);
187
- } catch (err) {
188
- throw createNodeError(err, "unlink", pathStr);
189
- }
199
+ const pathStr = normalizePath(path);
200
+ const file = Gio.File.new_for_path(pathStr);
201
+ try {
202
+ file.delete(null);
203
+ } catch (err) {
204
+ throw createNodeError$1(err, "unlink", pathStr);
205
+ }
190
206
  }
191
207
  function writeFileSync(path, data) {
192
- GLib.file_set_contents(normalizePath(path), data);
208
+ GLib.file_set_contents(normalizePath(path), data);
193
209
  }
194
210
  function renameSync(oldPath, newPath) {
195
- const oldStr = normalizePath(oldPath);
196
- const newStr = normalizePath(newPath);
197
- const src = Gio.File.new_for_path(oldStr);
198
- const dest = Gio.File.new_for_path(newStr);
199
- try {
200
- src.move(dest, Gio.FileCopyFlags.OVERWRITE, null, null);
201
- } catch (err) {
202
- throw createNodeError(err, "rename", oldStr, newStr);
203
- }
211
+ const oldStr = normalizePath(oldPath);
212
+ const newStr = normalizePath(newPath);
213
+ const src = Gio.File.new_for_path(oldStr);
214
+ const dest = Gio.File.new_for_path(newStr);
215
+ try {
216
+ src.move(dest, Gio.FileCopyFlags.OVERWRITE, null, null);
217
+ } catch (err) {
218
+ throw createNodeError$1(err, "rename", oldStr, newStr);
219
+ }
204
220
  }
205
221
  function copyFileSync(src, dest, mode) {
206
- const srcStr = normalizePath(src);
207
- const destStr = normalizePath(dest);
208
- const srcFile = Gio.File.new_for_path(srcStr);
209
- const destFile = Gio.File.new_for_path(destStr);
210
- let flags = Gio.FileCopyFlags.NONE;
211
- if (mode && (mode & 1) === 0) {
212
- flags = Gio.FileCopyFlags.OVERWRITE;
213
- } else if (!mode) {
214
- flags = Gio.FileCopyFlags.OVERWRITE;
215
- }
216
- try {
217
- srcFile.copy(destFile, flags, null, null);
218
- } catch (err) {
219
- throw createNodeError(err, "copyfile", srcStr, destStr);
220
- }
222
+ const srcStr = normalizePath(src);
223
+ const destStr = normalizePath(dest);
224
+ const srcFile = Gio.File.new_for_path(srcStr);
225
+ const destFile = Gio.File.new_for_path(destStr);
226
+ let flags = Gio.FileCopyFlags.NONE;
227
+ if (mode && (mode & 1) === 0) {
228
+ flags = Gio.FileCopyFlags.OVERWRITE;
229
+ } else if (!mode) {
230
+ flags = Gio.FileCopyFlags.OVERWRITE;
231
+ }
232
+ try {
233
+ srcFile.copy(destFile, flags, null, null);
234
+ } catch (err) {
235
+ throw createNodeError$1(err, "copyfile", srcStr, destStr);
236
+ }
221
237
  }
222
238
  function accessSync(path, mode) {
223
- const pathStr = normalizePath(path);
224
- const file = Gio.File.new_for_path(pathStr);
225
- try {
226
- const info = file.query_info("access::*", Gio.FileQueryInfoFlags.NONE, null);
227
- if (mode !== void 0 && mode !== 0) {
228
- const permErr = { code: 14, message: `permission denied, access '${pathStr}'` };
229
- if (mode & 4 && !info.get_attribute_boolean("access::can-read")) {
230
- throw createNodeError(permErr, "access", pathStr);
231
- }
232
- if (mode & 2 && !info.get_attribute_boolean("access::can-write")) {
233
- throw createNodeError(permErr, "access", pathStr);
234
- }
235
- if (mode & 1 && !info.get_attribute_boolean("access::can-execute")) {
236
- throw createNodeError(permErr, "access", pathStr);
237
- }
238
- }
239
- } catch (err) {
240
- if (err.code && typeof err.code === "string") throw err;
241
- throw createNodeError(err, "access", pathStr);
242
- }
239
+ const pathStr = normalizePath(path);
240
+ const file = Gio.File.new_for_path(pathStr);
241
+ try {
242
+ const info = file.query_info("access::*", Gio.FileQueryInfoFlags.NONE, null);
243
+ if (mode !== undefined && mode !== 0) {
244
+ const permErr = {
245
+ code: 14,
246
+ message: `permission denied, access '${pathStr}'`
247
+ };
248
+ if (mode & 4 && !info.get_attribute_boolean("access::can-read")) {
249
+ throw createNodeError$1(permErr, "access", pathStr);
250
+ }
251
+ if (mode & 2 && !info.get_attribute_boolean("access::can-write")) {
252
+ throw createNodeError$1(permErr, "access", pathStr);
253
+ }
254
+ if (mode & 1 && !info.get_attribute_boolean("access::can-execute")) {
255
+ throw createNodeError$1(permErr, "access", pathStr);
256
+ }
257
+ }
258
+ } catch (err) {
259
+ if (err.code && typeof err.code === "string") throw err;
260
+ throw createNodeError$1(err, "access", pathStr);
261
+ }
243
262
  }
244
263
  function appendFileSync(path, data, options) {
245
- const pathStr = normalizePath(path);
246
- const file = Gio.File.new_for_path(pathStr);
247
- let bytes;
248
- if (typeof data === "string") {
249
- bytes = new TextEncoder().encode(data);
250
- } else {
251
- bytes = data;
252
- }
253
- try {
254
- const stream = file.append_to(Gio.FileCreateFlags.NONE, null);
255
- if (bytes.length > 0) {
256
- stream.write_bytes(new GLib.Bytes(bytes), null);
257
- }
258
- stream.close(null);
259
- } catch (err) {
260
- throw createNodeError(err, "appendfile", pathStr);
261
- }
264
+ const pathStr = normalizePath(path);
265
+ const file = Gio.File.new_for_path(pathStr);
266
+ let bytes;
267
+ if (typeof data === "string") {
268
+ bytes = new TextEncoder().encode(data);
269
+ } else {
270
+ bytes = data;
271
+ }
272
+ try {
273
+ const stream = file.append_to(Gio.FileCreateFlags.NONE, null);
274
+ if (bytes.length > 0) {
275
+ stream.write_bytes(new GLib.Bytes(bytes), null);
276
+ }
277
+ stream.close(null);
278
+ } catch (err) {
279
+ throw createNodeError$1(err, "appendfile", pathStr);
280
+ }
262
281
  }
263
282
  function readlinkSync(path, options) {
264
- const pathStr = normalizePath(path);
265
- const file = Gio.File.new_for_path(pathStr);
266
- try {
267
- const info = file.query_info("standard::symlink-target", Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
268
- const target = info.get_symlink_target();
269
- if (!target) {
270
- throw Object.assign(new Error(`EINVAL: invalid argument, readlink '${pathStr}'`), { code: "EINVAL", errno: -22, syscall: "readlink", path: pathStr });
271
- }
272
- const encoding = typeof options === "string" ? options : options?.encoding;
273
- if (encoding === "buffer") {
274
- return Buffer.from(target);
275
- }
276
- return target;
277
- } catch (err) {
278
- if (typeof err.code === "string") throw err;
279
- throw createNodeError(err, "readlink", pathStr);
280
- }
283
+ const pathStr = normalizePath(path);
284
+ const file = Gio.File.new_for_path(pathStr);
285
+ try {
286
+ const info = file.query_info("standard::symlink-target", Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
287
+ const target = info.get_symlink_target();
288
+ if (!target) {
289
+ throw Object.assign(new Error(`EINVAL: invalid argument, readlink '${pathStr}'`), {
290
+ code: "EINVAL",
291
+ errno: -22,
292
+ syscall: "readlink",
293
+ path: pathStr
294
+ });
295
+ }
296
+ const encoding = typeof options === "string" ? options : options?.encoding;
297
+ if (encoding === "buffer") {
298
+ return Buffer.from(target);
299
+ }
300
+ return target;
301
+ } catch (err) {
302
+ if (typeof err.code === "string") throw err;
303
+ throw createNodeError$1(err, "readlink", pathStr);
304
+ }
281
305
  }
282
306
  function linkSync(existingPath, newPath) {
283
- const existingStr = normalizePath(existingPath);
284
- const newStr = normalizePath(newPath);
285
- const result = GLib.spawn_command_line_sync(`ln ${existingStr} ${newStr}`);
286
- if (!result[0]) {
287
- throw Object.assign(new Error(`EPERM: operation not permitted, link '${existingStr}' -> '${newStr}'`), { code: "EPERM", errno: -1, syscall: "link", path: existingStr, dest: newStr });
288
- }
307
+ const existingStr = normalizePath(existingPath);
308
+ const newStr = normalizePath(newPath);
309
+ const result = GLib.spawn_command_line_sync(`ln ${existingStr} ${newStr}`);
310
+ if (!result[0]) {
311
+ throw Object.assign(new Error(`EPERM: operation not permitted, link '${existingStr}' -> '${newStr}'`), {
312
+ code: "EPERM",
313
+ errno: -1,
314
+ syscall: "link",
315
+ path: existingStr,
316
+ dest: newStr
317
+ });
318
+ }
289
319
  }
290
320
  function truncateSync(path, len) {
291
- const pathStr = normalizePath(path);
292
- const file = Gio.File.new_for_path(pathStr);
293
- try {
294
- const stream = file.replace(null, false, Gio.FileCreateFlags.NONE, null);
295
- if (len && len > 0) {
296
- const [, data] = file.load_contents(null);
297
- const truncated = data.slice(0, len);
298
- if (truncated.length > 0) {
299
- stream.write_bytes(new GLib.Bytes(truncated), null);
300
- }
301
- }
302
- stream.close(null);
303
- } catch (err) {
304
- throw createNodeError(err, "truncate", pathStr);
305
- }
321
+ const pathStr = normalizePath(path);
322
+ const file = Gio.File.new_for_path(pathStr);
323
+ try {
324
+ const stream = file.replace(null, false, Gio.FileCreateFlags.NONE, null);
325
+ if (len && len > 0) {
326
+ const [, data] = file.load_contents(null);
327
+ const truncated = data.slice(0, len);
328
+ if (truncated.length > 0) {
329
+ stream.write_bytes(new GLib.Bytes(truncated), null);
330
+ }
331
+ }
332
+ stream.close(null);
333
+ } catch (err) {
334
+ throw createNodeError$1(err, "truncate", pathStr);
335
+ }
306
336
  }
307
337
  function chmodSync(path, mode) {
308
- const pathStr = normalizePath(path);
309
- const modeNum = typeof mode === "string" ? parseInt(mode, 8) : mode;
310
- const result = GLib.spawn_command_line_sync(`chmod ${modeNum.toString(8)} ${pathStr}`);
311
- if (!result[0]) {
312
- throw Object.assign(new Error(`EPERM: operation not permitted, chmod '${pathStr}'`), { code: "EPERM", errno: -1, syscall: "chmod", path: pathStr });
313
- }
338
+ const pathStr = normalizePath(path);
339
+ const modeNum = typeof mode === "string" ? parseInt(mode, 8) : mode;
340
+ const result = GLib.spawn_command_line_sync(`chmod ${modeNum.toString(8)} ${pathStr}`);
341
+ if (!result[0]) {
342
+ throw Object.assign(new Error(`EPERM: operation not permitted, chmod '${pathStr}'`), {
343
+ code: "EPERM",
344
+ errno: -1,
345
+ syscall: "chmod",
346
+ path: pathStr
347
+ });
348
+ }
314
349
  }
315
350
  function chownSync(path, uid, gid) {
316
- const pathStr = normalizePath(path);
317
- const result = GLib.spawn_command_line_sync(`chown ${uid}:${gid} ${pathStr}`);
318
- if (!result[0]) {
319
- throw Object.assign(new Error(`EPERM: operation not permitted, chown '${pathStr}'`), { code: "EPERM", errno: -1, syscall: "chown", path: pathStr });
320
- }
351
+ const pathStr = normalizePath(path);
352
+ const result = GLib.spawn_command_line_sync(`chown ${uid}:${gid} ${pathStr}`);
353
+ if (!result[0]) {
354
+ throw Object.assign(new Error(`EPERM: operation not permitted, chown '${pathStr}'`), {
355
+ code: "EPERM",
356
+ errno: -1,
357
+ syscall: "chown",
358
+ path: pathStr
359
+ });
360
+ }
321
361
  }
322
362
  function watch(filename, options, listener) {
323
- return new FSWatcher(normalizePath(filename), options, listener);
363
+ return new FSWatcher(normalizePath(filename), options, listener);
324
364
  }
325
365
  function openSync(path, flags, mode) {
326
- return new FileHandle({ path, flags, mode });
366
+ return new FileHandle({
367
+ path,
368
+ flags,
369
+ mode
370
+ });
327
371
  }
328
372
  function mkdtempSync(prefix, options) {
329
- const encoding = getEncodingFromOptions(options);
330
- const path = tempDirPath(prefix);
331
- mkdirSync(
332
- path,
333
- { recursive: false, mode: 511 }
334
- );
335
- return decode(path, encoding);
373
+ const encoding = getEncodingFromOptions(options);
374
+ const path = tempDirPath(prefix);
375
+ mkdirSync(path, {
376
+ recursive: false,
377
+ mode: 511
378
+ });
379
+ return decode(path, encoding);
336
380
  }
381
+ /**
382
+ * Synchronously removes files and directories (modeled on the standard POSIX `rm`utility). Returns `undefined`.
383
+ * @since v14.14.0
384
+ */
337
385
  function rmSync(path, options) {
338
- const pathStr = normalizePath(path);
339
- const file = Gio.File.new_for_path(pathStr);
340
- const recursive = options?.recursive || false;
341
- const force = options?.force || false;
342
- let dirent;
343
- try {
344
- dirent = new Dirent(pathStr);
345
- } catch (err) {
346
- if (force && isNotFoundError(err)) return;
347
- throw createNodeError(err, "rm", path);
348
- }
349
- if (dirent.isDirectory()) {
350
- const childFiles = readdirSync(path, { withFileTypes: true });
351
- if (!recursive && childFiles.length) {
352
- const err = Object.assign(new Error(), { code: 5 });
353
- throw createNodeError(err, "rm", path);
354
- }
355
- for (const childFile of childFiles) {
356
- if (typeof childFile !== "string") {
357
- rmSync(join(pathStr, childFile.name), options);
358
- }
359
- }
360
- }
361
- try {
362
- file.delete(null);
363
- } catch (err) {
364
- if (force && isNotFoundError(err)) return;
365
- throw createNodeError(err, "rm", path);
366
- }
386
+ const pathStr = normalizePath(path);
387
+ const file = Gio.File.new_for_path(pathStr);
388
+ const recursive = options?.recursive || false;
389
+ const force = options?.force || false;
390
+ let dirent;
391
+ try {
392
+ dirent = new Dirent(pathStr);
393
+ } catch (err) {
394
+ if (force && isNotFoundError(err)) return;
395
+ throw createNodeError$1(err, "rm", path);
396
+ }
397
+ if (dirent.isDirectory()) {
398
+ const childFiles = readdirSync(path, { withFileTypes: true });
399
+ if (!recursive && childFiles.length) {
400
+ const err = Object.assign(new Error(), { code: 5 });
401
+ throw createNodeError$1(err, "rm", path);
402
+ }
403
+ for (const childFile of childFiles) {
404
+ if (typeof childFile !== "string") {
405
+ rmSync(join(pathStr, childFile.name), options);
406
+ }
407
+ }
408
+ }
409
+ try {
410
+ file.delete(null);
411
+ } catch (err) {
412
+ if (force && isNotFoundError(err)) return;
413
+ throw createNodeError$1(err, "rm", path);
414
+ }
367
415
  }
368
- export {
369
- accessSync,
370
- appendFileSync,
371
- chmodSync,
372
- chownSync,
373
- copyFileSync,
374
- existsSync,
375
- linkSync,
376
- lstatSync,
377
- mkdirSync,
378
- mkdtempSync,
379
- openSync,
380
- readFileSync,
381
- readdirSync,
382
- readlinkSync,
383
- realpathSync,
384
- renameSync,
385
- rmSync,
386
- rmdirSync,
387
- statSync,
388
- symlinkSync,
389
- truncateSync,
390
- unlinkSync,
391
- watch,
392
- writeFileSync
393
- };
416
+
417
+ //#endregion
418
+ export { accessSync, appendFileSync, chmodSync, chownSync, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, symlinkSync, truncateSync, unlinkSync, watch, writeFileSync };