@gjsify/fs 0.3.12 → 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.
@@ -1,444 +1,471 @@
1
- import Gio from "@girs/gio-2.0";
2
- import GLib from "@girs/glib-2.0";
3
- import { join, dirname } from "node:path";
4
- import { getEncodingFromOptions, encodeUint8Array, decode } from "./encoding.js";
5
- import { realpathSync, readdirSync as readdirSyncFn, renameSync, copyFileSync, accessSync, appendFileSync, readlinkSync, truncateSync, chmodSync, chownSync, linkSync } from "./sync.js";
6
- import { cpAsync } from "./cp.js";
7
- import { opendirAsync } from "./dir.js";
8
- import { globAsync } from "./glob.js";
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { decode, encodeUint8Array, getEncodingFromOptions } from "./encoding.js";
3
+ import { normalizePath, tempDirPath } from "./utils.js";
9
4
  import { watchAsync } from "./fs-watcher.js";
10
- import { statfsAsync } from "./statfs.js";
11
- import { utimesAsync, lutimesAsync, lchownAsync, lchmodAsync } from "./utimes.js";
12
- import {
13
- fstatAsync,
14
- ftruncateAsync,
15
- fdatasyncAsync,
16
- fsyncAsync,
17
- fchmodAsync,
18
- fchownAsync,
19
- futimesAsync,
20
- readvAsync,
21
- writevAsync,
22
- openAsBlob
23
- } from "./fd-ops.js";
24
- import { FileHandle } from "./file-handle.js";
25
- import { tempDirPath, normalizePath } from "./utils.js";
26
5
  import { Dirent } from "./dirent.js";
27
- import { Stats, BigIntStats, STAT_ATTRIBUTES } from "./stats.js";
6
+ import { BigIntStats, STAT_ATTRIBUTES, Stats } from "./stats.js";
7
+ import { FileHandle } from "./file-handle.js";
28
8
  import { createNodeError } from "./errors.js";
9
+ import { accessSync, appendFileSync, chmodSync, chownSync, copyFileSync, linkSync, readdirSync, readlinkSync, realpathSync, renameSync, truncateSync } from "./sync.js";
10
+ import { cpAsync as cpPromises } from "./cp.js";
11
+ import { opendirAsync } from "./dir.js";
12
+ import { globAsync } from "./glob.js";
13
+ import { statfsAsync } from "./statfs.js";
14
+ import { lchmodAsync, lchownAsync, lutimesAsync, utimesAsync } from "./utimes.js";
15
+ import { fchmodAsync, fchownAsync, fdatasyncAsync, fstatAsync, fsyncAsync, ftruncateAsync, futimesAsync, openAsBlob, readvAsync, writevAsync } from "./fd-ops.js";
16
+ import GLib from "@girs/glib-2.0";
17
+ import Gio from "@girs/gio-2.0";
18
+ import { dirname, join } from "node:path";
19
+
20
+ //#region src/promises.ts
21
+ var promises_exports = /* @__PURE__ */ __exportAll({
22
+ access: () => access,
23
+ appendFile: () => appendFile,
24
+ chmod: () => chmod,
25
+ chown: () => chown,
26
+ copyFile: () => copyFile,
27
+ cp: () => cpPromises,
28
+ default: () => promises_default,
29
+ fchmod: () => fchmodAsync,
30
+ fchown: () => fchownAsync,
31
+ fdatasync: () => fdatasyncAsync,
32
+ fstat: () => fstatAsync,
33
+ fsync: () => fsyncAsync,
34
+ ftruncate: () => ftruncateAsync,
35
+ futimes: () => futimesAsync,
36
+ glob: () => globAsync,
37
+ lchmod: () => lchmodAsync,
38
+ lchown: () => lchownAsync,
39
+ link: () => link,
40
+ lstat: () => lstat,
41
+ lutimes: () => lutimesAsync,
42
+ mkdir: () => mkdir,
43
+ mkdtemp: () => mkdtemp,
44
+ open: () => open,
45
+ openAsBlob: () => openAsBlob,
46
+ opendir: () => opendirAsync,
47
+ readFile: () => readFile,
48
+ readdir: () => readdir,
49
+ readlink: () => readlink,
50
+ readv: () => readvAsync,
51
+ realpath: () => realpath,
52
+ rename: () => rename,
53
+ rm: () => rm,
54
+ rmdir: () => rmdir,
55
+ stat: () => stat,
56
+ statfs: () => statfsAsync,
57
+ symlink: () => symlink,
58
+ truncate: () => truncate,
59
+ unlink: () => unlink,
60
+ utimes: () => utimesAsync,
61
+ watch: () => watchAsync,
62
+ write: () => write,
63
+ writeFile: () => writeFile,
64
+ writev: () => writevAsync
65
+ });
29
66
  async function mkdir(path, options) {
30
- let recursive;
31
- let _mode = 511;
32
- if (typeof options === "object") {
33
- if (options.recursive) recursive = options.recursive;
34
- if (options.mode) _mode = options.mode;
35
- } else {
36
- _mode = options;
37
- }
38
- const pathStr = normalizePath(path);
39
- if (recursive) {
40
- return mkdirRecursiveAsync(pathStr);
41
- }
42
- const file = Gio.File.new_for_path(pathStr);
43
- return new Promise((resolve, reject) => {
44
- file.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
45
- try {
46
- file.make_directory_finish(res);
47
- resolve(void 0);
48
- } catch (err) {
49
- reject(createNodeError(err, "mkdir", pathStr));
50
- }
51
- });
52
- });
67
+ let recursive;
68
+ let _mode = 511;
69
+ if (typeof options === "object") {
70
+ if (options.recursive) recursive = options.recursive;
71
+ if (options.mode) _mode = options.mode;
72
+ } else {
73
+ _mode = options;
74
+ }
75
+ const pathStr = normalizePath(path);
76
+ if (recursive) {
77
+ return mkdirRecursiveAsync(pathStr);
78
+ }
79
+ const file = Gio.File.new_for_path(pathStr);
80
+ return new Promise((resolve, reject) => {
81
+ file.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
82
+ try {
83
+ file.make_directory_finish(res);
84
+ resolve(undefined);
85
+ } catch (err) {
86
+ reject(createNodeError(err, "mkdir", pathStr));
87
+ }
88
+ });
89
+ });
53
90
  }
91
+ /**
92
+ * Recursively creates directories, similar to `mkdir -p`.
93
+ * Returns the first directory path created, or undefined if all directories already existed.
94
+ */
54
95
  async function mkdirRecursiveAsync(pathStr) {
55
- const file = Gio.File.new_for_path(pathStr);
56
- try {
57
- await new Promise((resolve, reject) => {
58
- file.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
59
- try {
60
- file.make_directory_finish(res);
61
- resolve();
62
- } catch (err) {
63
- reject(err);
64
- }
65
- });
66
- });
67
- return pathStr;
68
- } catch (err) {
69
- const gErr = err;
70
- if (gErr.code === Gio.IOErrorEnum.EXISTS) {
71
- return void 0;
72
- }
73
- if (gErr.code === Gio.IOErrorEnum.NOT_FOUND) {
74
- const parentPath = dirname(pathStr);
75
- if (parentPath === pathStr) {
76
- throw createNodeError(err, "mkdir", pathStr);
77
- }
78
- const firstCreated = await mkdirRecursiveAsync(parentPath);
79
- const retryFile = Gio.File.new_for_path(pathStr);
80
- await new Promise((resolve, reject) => {
81
- retryFile.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
82
- try {
83
- retryFile.make_directory_finish(res);
84
- resolve();
85
- } catch (retryErr) {
86
- reject(createNodeError(retryErr, "mkdir", pathStr));
87
- }
88
- });
89
- });
90
- return firstCreated ?? pathStr;
91
- }
92
- throw createNodeError(err, "mkdir", pathStr);
93
- }
96
+ const file = Gio.File.new_for_path(pathStr);
97
+ try {
98
+ await new Promise((resolve, reject) => {
99
+ file.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
100
+ try {
101
+ file.make_directory_finish(res);
102
+ resolve();
103
+ } catch (err) {
104
+ reject(err);
105
+ }
106
+ });
107
+ });
108
+ return pathStr;
109
+ } catch (err) {
110
+ const gErr = err;
111
+ if (gErr.code === Gio.IOErrorEnum.EXISTS) {
112
+ return undefined;
113
+ }
114
+ if (gErr.code === Gio.IOErrorEnum.NOT_FOUND) {
115
+ const parentPath = dirname(pathStr);
116
+ if (parentPath === pathStr) {
117
+ throw createNodeError(err, "mkdir", pathStr);
118
+ }
119
+ const firstCreated = await mkdirRecursiveAsync(parentPath);
120
+ const retryFile = Gio.File.new_for_path(pathStr);
121
+ await new Promise((resolve, reject) => {
122
+ retryFile.make_directory_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
123
+ try {
124
+ retryFile.make_directory_finish(res);
125
+ resolve();
126
+ } catch (retryErr) {
127
+ reject(createNodeError(retryErr, "mkdir", pathStr));
128
+ }
129
+ });
130
+ });
131
+ return firstCreated ?? pathStr;
132
+ }
133
+ throw createNodeError(err, "mkdir", pathStr);
134
+ }
94
135
  }
95
- async function readFile(path, options = { encoding: null, flag: "r" }) {
96
- const pathStr = normalizePath(path);
97
- const file = Gio.File.new_for_path(pathStr);
98
- let ok;
99
- let data;
100
- try {
101
- [ok, data] = await new Promise((resolve, reject) => {
102
- file.load_contents_async(null, (self, res) => {
103
- try {
104
- resolve(file.load_contents_finish(res));
105
- } catch (error) {
106
- reject(error);
107
- }
108
- });
109
- });
110
- } catch (error) {
111
- throw createNodeError(error, "open", pathStr);
112
- }
113
- if (!ok) {
114
- throw createNodeError(new Error("failed to read file"), "open", pathStr);
115
- }
116
- return encodeUint8Array(getEncodingFromOptions(options, "buffer"), data);
136
+ async function readFile(path, options = {
137
+ encoding: null,
138
+ flag: "r"
139
+ }) {
140
+ const pathStr = normalizePath(path);
141
+ const file = Gio.File.new_for_path(pathStr);
142
+ let ok;
143
+ let data;
144
+ try {
145
+ [ok, data] = await new Promise((resolve, reject) => {
146
+ file.load_contents_async(null, (self, res) => {
147
+ try {
148
+ resolve(file.load_contents_finish(res));
149
+ } catch (error) {
150
+ reject(error);
151
+ }
152
+ });
153
+ });
154
+ } catch (error) {
155
+ throw createNodeError(error, "open", pathStr);
156
+ }
157
+ if (!ok) {
158
+ throw createNodeError(new Error("failed to read file"), "open", pathStr);
159
+ }
160
+ return encodeUint8Array(getEncodingFromOptions(options, "buffer"), data);
117
161
  }
118
162
  async function mkdtemp(prefix, options) {
119
- const encoding = getEncodingFromOptions(options);
120
- const path = tempDirPath(prefix);
121
- await mkdir(
122
- path,
123
- { recursive: false, mode: 448 }
124
- );
125
- return decode(path, encoding);
163
+ const encoding = getEncodingFromOptions(options);
164
+ const path = tempDirPath(prefix);
165
+ await mkdir(path, {
166
+ recursive: false,
167
+ mode: 448
168
+ });
169
+ return decode(path, encoding);
126
170
  }
127
171
  async function writeFile(path, data) {
128
- const pathStr = normalizePath(path);
129
- const file = Gio.File.new_for_path(pathStr);
130
- let bytes;
131
- if (typeof data === "string") {
132
- bytes = new TextEncoder().encode(data);
133
- } else if (data instanceof Uint8Array) {
134
- bytes = data;
135
- } else {
136
- bytes = new TextEncoder().encode(String(data));
137
- }
138
- const outputStream = await new Promise((resolve, reject) => {
139
- file.replace_async(null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
140
- try {
141
- resolve(file.replace_finish(res));
142
- } catch (err) {
143
- reject(createNodeError(err, "open", pathStr));
144
- }
145
- });
146
- });
147
- if (bytes.length > 0) {
148
- const glibBytes = new GLib.Bytes(bytes);
149
- await new Promise((resolve, reject) => {
150
- outputStream.write_bytes_async(glibBytes, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
151
- try {
152
- outputStream.write_bytes_finish(res);
153
- resolve();
154
- } catch (err) {
155
- reject(createNodeError(err, "write", pathStr));
156
- }
157
- });
158
- });
159
- }
160
- await new Promise((resolve, reject) => {
161
- outputStream.close_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
162
- try {
163
- outputStream.close_finish(res);
164
- resolve();
165
- } catch (err) {
166
- reject(createNodeError(err, "close", pathStr));
167
- }
168
- });
169
- });
172
+ const pathStr = normalizePath(path);
173
+ const file = Gio.File.new_for_path(pathStr);
174
+ let bytes;
175
+ if (typeof data === "string") {
176
+ bytes = new TextEncoder().encode(data);
177
+ } else if (data instanceof Uint8Array) {
178
+ bytes = data;
179
+ } else {
180
+ bytes = new TextEncoder().encode(String(data));
181
+ }
182
+ const outputStream = await new Promise((resolve, reject) => {
183
+ file.replace_async(null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
184
+ try {
185
+ resolve(file.replace_finish(res));
186
+ } catch (err) {
187
+ reject(createNodeError(err, "open", pathStr));
188
+ }
189
+ });
190
+ });
191
+ if (bytes.length > 0) {
192
+ const glibBytes = new GLib.Bytes(bytes);
193
+ await new Promise((resolve, reject) => {
194
+ outputStream.write_bytes_async(glibBytes, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
195
+ try {
196
+ outputStream.write_bytes_finish(res);
197
+ resolve();
198
+ } catch (err) {
199
+ reject(createNodeError(err, "write", pathStr));
200
+ }
201
+ });
202
+ });
203
+ }
204
+ await new Promise((resolve, reject) => {
205
+ outputStream.close_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
206
+ try {
207
+ outputStream.close_finish(res);
208
+ resolve();
209
+ } catch (err) {
210
+ reject(createNodeError(err, "close", pathStr));
211
+ }
212
+ });
213
+ });
170
214
  }
215
+ /**
216
+ * Removes the directory identified by `path`.
217
+ *
218
+ * Using `fsPromises.rmdir()` on a file (not a directory) results in the
219
+ * promise being rejected with an `ENOENT` error on Windows and an `ENOTDIR`error on POSIX.
220
+ *
221
+ * To get a behavior similar to the `rm -rf` Unix command, use `fsPromises.rm()` with options `{ recursive: true, force: true }`.
222
+ * @since v10.0.0
223
+ * @return Fulfills with `undefined` upon success.
224
+ */
171
225
  async function rmdir(path, _options) {
172
- const pathStr = normalizePath(path);
173
- const file = Gio.File.new_for_path(pathStr);
174
- const info = await new Promise((resolve, reject) => {
175
- file.query_info_async("standard::type", Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
176
- try {
177
- resolve(file.query_info_finish(res));
178
- } catch (err) {
179
- reject(createNodeError(err, "rmdir", pathStr));
180
- }
181
- });
182
- });
183
- if (info.get_file_type() !== Gio.FileType.DIRECTORY) {
184
- const err = Object.assign(new Error(), { code: 4 });
185
- throw createNodeError(err, "rmdir", pathStr);
186
- }
187
- const children = await new Promise((resolve, reject) => {
188
- file.enumerate_children_async("standard::name", Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
189
- try {
190
- resolve(file.enumerate_children_finish(res));
191
- } catch (err) {
192
- reject(createNodeError(err, "rmdir", pathStr));
193
- }
194
- });
195
- });
196
- const firstChild = children.next_file(null);
197
- if (firstChild !== null) {
198
- const err = Object.assign(new Error(), { code: 5 });
199
- throw createNodeError(err, "rmdir", pathStr);
200
- }
201
- await new Promise((resolve, reject) => {
202
- file.delete_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
203
- try {
204
- file.delete_finish(res);
205
- resolve();
206
- } catch (err) {
207
- reject(createNodeError(err, "rmdir", pathStr));
208
- }
209
- });
210
- });
226
+ const pathStr = normalizePath(path);
227
+ const file = Gio.File.new_for_path(pathStr);
228
+ const info = await new Promise((resolve, reject) => {
229
+ file.query_info_async("standard::type", Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
230
+ try {
231
+ resolve(file.query_info_finish(res));
232
+ } catch (err) {
233
+ reject(createNodeError(err, "rmdir", pathStr));
234
+ }
235
+ });
236
+ });
237
+ if (info.get_file_type() !== Gio.FileType.DIRECTORY) {
238
+ const err = Object.assign(new Error(), { code: 4 });
239
+ throw createNodeError(err, "rmdir", pathStr);
240
+ }
241
+ const children = await new Promise((resolve, reject) => {
242
+ file.enumerate_children_async("standard::name", Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
243
+ try {
244
+ resolve(file.enumerate_children_finish(res));
245
+ } catch (err) {
246
+ reject(createNodeError(err, "rmdir", pathStr));
247
+ }
248
+ });
249
+ });
250
+ const firstChild = children.next_file(null);
251
+ if (firstChild !== null) {
252
+ const err = Object.assign(new Error(), { code: 5 });
253
+ throw createNodeError(err, "rmdir", pathStr);
254
+ }
255
+ await new Promise((resolve, reject) => {
256
+ file.delete_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
257
+ try {
258
+ file.delete_finish(res);
259
+ resolve();
260
+ } catch (err) {
261
+ reject(createNodeError(err, "rmdir", pathStr));
262
+ }
263
+ });
264
+ });
211
265
  }
212
266
  async function unlink(path) {
213
- const pathStr = normalizePath(path);
214
- const file = Gio.File.new_for_path(pathStr);
215
- await new Promise((resolve, reject) => {
216
- file.delete_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
217
- try {
218
- file.delete_finish(res);
219
- resolve();
220
- } catch (err) {
221
- reject(createNodeError(err, "unlink", pathStr));
222
- }
223
- });
224
- });
267
+ const pathStr = normalizePath(path);
268
+ const file = Gio.File.new_for_path(pathStr);
269
+ await new Promise((resolve, reject) => {
270
+ file.delete_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
271
+ try {
272
+ file.delete_finish(res);
273
+ resolve();
274
+ } catch (err) {
275
+ reject(createNodeError(err, "unlink", pathStr));
276
+ }
277
+ });
278
+ });
225
279
  }
226
280
  async function open(path, flags, mode) {
227
- return new FileHandle({ path, flags, mode });
281
+ return new FileHandle({
282
+ path,
283
+ flags,
284
+ mode
285
+ });
228
286
  }
229
287
  async function write(fd, data, positionOrOffset, encodingOrLength, position) {
230
- if (typeof data === "string") {
231
- return _writeStr(fd, data, positionOrOffset, encodingOrLength);
232
- }
233
- return _writeBuf(fd, data, positionOrOffset, encodingOrLength, position);
288
+ if (typeof data === "string") {
289
+ return _writeStr(fd, data, positionOrOffset, encodingOrLength);
290
+ }
291
+ return _writeBuf(fd, data, positionOrOffset, encodingOrLength, position);
234
292
  }
235
293
  async function _writeBuf(fd, buffer, offset, length, position) {
236
- const fileHandle = FileHandle.getInstance(fd);
237
- const result = await fileHandle.write(buffer, offset, length, position);
238
- return { bytesWritten: result.bytesWritten, buffer };
294
+ const fileHandle = FileHandle.getInstance(fd);
295
+ const result = await fileHandle.write(buffer, offset, length, position);
296
+ return {
297
+ bytesWritten: result.bytesWritten,
298
+ buffer
299
+ };
239
300
  }
240
301
  async function _writeStr(fd, data, position, encoding) {
241
- const fileHandle = FileHandle.getInstance(fd);
242
- const result = await fileHandle.write(data, position, encoding);
243
- return { bytesWritten: result.bytesWritten, buffer: data };
302
+ const fileHandle = FileHandle.getInstance(fd);
303
+ const result = await fileHandle.write(data, position, encoding);
304
+ return {
305
+ bytesWritten: result.bytesWritten,
306
+ buffer: data
307
+ };
244
308
  }
245
309
  function queryInfoAsync(path, flags, syscall, options) {
246
- const pathStr = normalizePath(path);
247
- return new Promise((resolve, reject) => {
248
- const file = Gio.File.new_for_path(pathStr);
249
- file.query_info_async(STAT_ATTRIBUTES, flags, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
250
- try {
251
- const info = file.query_info_finish(res);
252
- resolve(options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr));
253
- } catch (err) {
254
- reject(createNodeError(err, syscall, pathStr));
255
- }
256
- });
257
- });
310
+ const pathStr = normalizePath(path);
311
+ return new Promise((resolve, reject) => {
312
+ const file = Gio.File.new_for_path(pathStr);
313
+ file.query_info_async(STAT_ATTRIBUTES, flags, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
314
+ try {
315
+ const info = file.query_info_finish(res);
316
+ resolve(options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr));
317
+ } catch (err) {
318
+ reject(createNodeError(err, syscall, pathStr));
319
+ }
320
+ });
321
+ });
258
322
  }
259
323
  async function stat(path, options) {
260
- return queryInfoAsync(path, Gio.FileQueryInfoFlags.NONE, "stat", options);
324
+ return queryInfoAsync(path, Gio.FileQueryInfoFlags.NONE, "stat", options);
261
325
  }
262
326
  async function lstat(path, options) {
263
- return queryInfoAsync(path, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, "lstat", options);
327
+ return queryInfoAsync(path, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, "lstat", options);
264
328
  }
265
329
  async function readdir(path, options) {
266
- try {
267
- return readdirSyncFn(path, options);
268
- } catch (error) {
269
- throw createNodeError(error, "scandir", path);
270
- }
330
+ try {
331
+ return readdirSync(path, options);
332
+ } catch (error) {
333
+ throw createNodeError(error, "scandir", path);
334
+ }
271
335
  }
272
336
  async function realpath(path) {
273
- return realpathSync(path);
337
+ return realpathSync(path);
274
338
  }
275
339
  async function symlink(target, path, _type) {
276
- const pathStr = normalizePath(path);
277
- const targetStr = normalizePath(target);
278
- return new Promise((resolve, reject) => {
279
- const file = Gio.File.new_for_path(pathStr);
280
- file.make_symbolic_link_async(targetStr, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
281
- try {
282
- file.make_symbolic_link_finish(res);
283
- resolve();
284
- } catch (err) {
285
- reject(createNodeError(err, "symlink", targetStr, pathStr));
286
- }
287
- });
288
- });
340
+ const pathStr = normalizePath(path);
341
+ const targetStr = normalizePath(target);
342
+ return new Promise((resolve, reject) => {
343
+ const file = Gio.File.new_for_path(pathStr);
344
+ file.make_symbolic_link_async(targetStr, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
345
+ try {
346
+ file.make_symbolic_link_finish(res);
347
+ resolve();
348
+ } catch (err) {
349
+ reject(createNodeError(err, "symlink", targetStr, pathStr));
350
+ }
351
+ });
352
+ });
289
353
  }
354
+ /**
355
+ * Removes files and directories (modeled on the standard POSIX `rm` utility).
356
+ * @since v14.14.0
357
+ * @return Fulfills with `undefined` upon success.
358
+ */
290
359
  async function rm(path, options) {
291
- const pathStr = normalizePath(path);
292
- const file = Gio.File.new_for_path(pathStr);
293
- const recursive = options?.recursive || false;
294
- const force = options?.force || false;
295
- let dirent;
296
- try {
297
- dirent = new Dirent(pathStr);
298
- } catch (err) {
299
- if (force) return;
300
- throw createNodeError(err, "rm", path);
301
- }
302
- if (dirent.isDirectory()) {
303
- const childFiles = await readdir(path, { withFileTypes: true });
304
- if (!recursive && childFiles.length) {
305
- const err = Object.assign(new Error(), { code: 5 });
306
- throw createNodeError(err, "rm", path);
307
- }
308
- for (const childFile of childFiles) {
309
- if (typeof childFile !== "string") {
310
- await rm(join(pathStr, childFile.name), options);
311
- }
312
- }
313
- }
314
- await new Promise((resolve, reject) => {
315
- file.delete_async(GLib.PRIORITY_DEFAULT, null, (_self, res) => {
316
- try {
317
- file.delete_finish(res);
318
- resolve();
319
- } catch (err) {
320
- if (force) {
321
- resolve();
322
- return;
323
- }
324
- reject(createNodeError(err, "rm", path));
325
- }
326
- });
327
- });
360
+ const pathStr = normalizePath(path);
361
+ const file = Gio.File.new_for_path(pathStr);
362
+ const recursive = options?.recursive || false;
363
+ const force = options?.force || false;
364
+ let dirent;
365
+ try {
366
+ dirent = new Dirent(pathStr);
367
+ } catch (err) {
368
+ if (force) return;
369
+ throw createNodeError(err, "rm", path);
370
+ }
371
+ if (dirent.isDirectory()) {
372
+ const childFiles = await readdir(path, { withFileTypes: true });
373
+ if (!recursive && childFiles.length) {
374
+ const err = Object.assign(new Error(), { code: 5 });
375
+ throw createNodeError(err, "rm", path);
376
+ }
377
+ for (const childFile of childFiles) {
378
+ if (typeof childFile !== "string") {
379
+ await rm(join(pathStr, childFile.name), options);
380
+ }
381
+ }
382
+ }
383
+ await new Promise((resolve, reject) => {
384
+ file.delete_async(GLib.PRIORITY_DEFAULT, null, (_self, res) => {
385
+ try {
386
+ file.delete_finish(res);
387
+ resolve();
388
+ } catch (err) {
389
+ if (force) {
390
+ resolve();
391
+ return;
392
+ }
393
+ reject(createNodeError(err, "rm", path));
394
+ }
395
+ });
396
+ });
328
397
  }
329
398
  async function rename(oldPath, newPath) {
330
- renameSync(oldPath, newPath);
399
+ renameSync(oldPath, newPath);
331
400
  }
332
401
  async function copyFile(src, dest, mode) {
333
- copyFileSync(src, dest, mode);
402
+ copyFileSync(src, dest, mode);
334
403
  }
335
404
  async function access(path, mode) {
336
- accessSync(path, mode);
405
+ accessSync(path, mode);
337
406
  }
338
407
  async function appendFile(path, data, options) {
339
- appendFileSync(path, data, options);
408
+ appendFileSync(path, data, options);
340
409
  }
341
410
  async function readlink(path, options) {
342
- return readlinkSync(path, options);
411
+ return readlinkSync(path, options);
343
412
  }
344
413
  async function truncate(path, len) {
345
- truncateSync(path, len);
414
+ truncateSync(path, len);
346
415
  }
347
416
  async function chmod(path, mode) {
348
- chmodSync(path, mode);
417
+ chmodSync(path, mode);
349
418
  }
350
419
  async function chown(path, uid, gid) {
351
- chownSync(path, uid, gid);
420
+ chownSync(path, uid, gid);
352
421
  }
353
422
  async function link(existingPath, newPath) {
354
- linkSync(existingPath, newPath);
423
+ linkSync(existingPath, newPath);
355
424
  }
356
425
  var promises_default = {
357
- readFile,
358
- mkdir,
359
- mkdtemp,
360
- realpath,
361
- readdir,
362
- writeFile,
363
- rmdir,
364
- unlink,
365
- open,
366
- write,
367
- rm,
368
- lstat,
369
- symlink,
370
- stat,
371
- rename,
372
- copyFile,
373
- access,
374
- appendFile,
375
- readlink,
376
- truncate,
377
- chmod,
378
- chown,
379
- link,
380
- cp: cpAsync,
381
- opendir: opendirAsync,
382
- glob: globAsync,
383
- watch: watchAsync,
384
- statfs: statfsAsync,
385
- utimes: utimesAsync,
386
- lutimes: lutimesAsync,
387
- lchown: lchownAsync,
388
- lchmod: lchmodAsync,
389
- fstat: fstatAsync,
390
- ftruncate: ftruncateAsync,
391
- fdatasync: fdatasyncAsync,
392
- fsync: fsyncAsync,
393
- fchmod: fchmodAsync,
394
- fchown: fchownAsync,
395
- futimes: futimesAsync,
396
- readv: readvAsync,
397
- writev: writevAsync,
398
- openAsBlob
399
- };
400
- export {
401
- access,
402
- appendFile,
403
- chmod,
404
- chown,
405
- copyFile,
406
- cpAsync as cp,
407
- promises_default as default,
408
- fchmodAsync as fchmod,
409
- fchownAsync as fchown,
410
- fdatasyncAsync as fdatasync,
411
- fstatAsync as fstat,
412
- fsyncAsync as fsync,
413
- ftruncateAsync as ftruncate,
414
- futimesAsync as futimes,
415
- globAsync as glob,
416
- lchmodAsync as lchmod,
417
- lchownAsync as lchown,
418
- link,
419
- lstat,
420
- lutimesAsync as lutimes,
421
- mkdir,
422
- mkdtemp,
423
- open,
424
- openAsBlob,
425
- opendirAsync as opendir,
426
- readFile,
427
- readdir,
428
- readlink,
429
- readvAsync as readv,
430
- realpath,
431
- rename,
432
- rm,
433
- rmdir,
434
- stat,
435
- statfsAsync as statfs,
436
- symlink,
437
- truncate,
438
- unlink,
439
- utimesAsync as utimes,
440
- watchAsync as watch,
441
- write,
442
- writeFile,
443
- writevAsync as writev
426
+ readFile,
427
+ mkdir,
428
+ mkdtemp,
429
+ realpath,
430
+ readdir,
431
+ writeFile,
432
+ rmdir,
433
+ unlink,
434
+ open,
435
+ write,
436
+ rm,
437
+ lstat,
438
+ symlink,
439
+ stat,
440
+ rename,
441
+ copyFile,
442
+ access,
443
+ appendFile,
444
+ readlink,
445
+ truncate,
446
+ chmod,
447
+ chown,
448
+ link,
449
+ cp: cpPromises,
450
+ opendir: opendirAsync,
451
+ glob: globAsync,
452
+ watch: watchAsync,
453
+ statfs: statfsAsync,
454
+ utimes: utimesAsync,
455
+ lutimes: lutimesAsync,
456
+ lchown: lchownAsync,
457
+ lchmod: lchmodAsync,
458
+ fstat: fstatAsync,
459
+ ftruncate: ftruncateAsync,
460
+ fdatasync: fdatasyncAsync,
461
+ fsync: fsyncAsync,
462
+ fchmod: fchmodAsync,
463
+ fchown: fchownAsync,
464
+ futimes: futimesAsync,
465
+ readv: readvAsync,
466
+ writev: writevAsync,
467
+ openAsBlob
444
468
  };
469
+
470
+ //#endregion
471
+ export { access, appendFile, chmod, chown, copyFile, cpPromises as cp, promises_default as default, fchmodAsync as fchmod, fchownAsync as fchown, fdatasyncAsync as fdatasync, fstatAsync as fstat, fsyncAsync as fsync, ftruncateAsync as ftruncate, futimesAsync as futimes, globAsync as glob, lchmodAsync as lchmod, lchownAsync as lchown, link, lstat, lutimesAsync as lutimes, mkdir, mkdtemp, open, openAsBlob, opendirAsync as opendir, promises_exports, readFile, readdir, readlink, readvAsync as readv, realpath, rename, rm, rmdir, stat, statfsAsync as statfs, symlink, truncate, unlink, utimesAsync as utimes, watchAsync as watch, write, writeFile, writevAsync as writev };