@gjsify/fs 0.1.13 → 0.2.0
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/callback.js +22 -13
- package/lib/esm/cp.js +253 -0
- package/lib/esm/dir.js +160 -0
- package/lib/esm/fd-ops.js +189 -0
- package/lib/esm/file-handle.js +263 -84
- package/lib/esm/fs-watcher.js +88 -4
- package/lib/esm/glob.js +164 -0
- package/lib/esm/index.js +128 -2
- package/lib/esm/promises.js +90 -27
- package/lib/esm/read-stream.js +53 -43
- package/lib/esm/stat-watcher.js +121 -0
- package/lib/esm/statfs.js +57 -0
- package/lib/esm/sync.js +70 -52
- package/lib/esm/utils.js +7 -0
- package/lib/esm/utimes.js +62 -0
- package/lib/esm/write-stream.js +2 -5
- package/lib/types/cp.d.ts +18 -0
- package/lib/types/cp.spec.d.ts +2 -0
- package/lib/types/dir.d.ts +29 -0
- package/lib/types/dir.spec.d.ts +2 -0
- package/lib/types/fd-ops.d.ts +57 -0
- package/lib/types/fd-ops.spec.d.ts +2 -0
- package/lib/types/file-handle.d.ts +34 -4
- package/lib/types/fs-watcher.d.ts +9 -2
- package/lib/types/glob.d.ts +8 -0
- package/lib/types/glob.spec.d.ts +2 -0
- package/lib/types/index.d.ts +51 -1
- package/lib/types/promises.d.ts +31 -4
- package/lib/types/read-stream.d.ts +3 -1
- package/lib/types/stat-watcher.d.ts +21 -0
- package/lib/types/statfs.d.ts +35 -0
- package/lib/types/statfs.spec.d.ts +2 -0
- package/lib/types/sync.d.ts +4 -7
- package/lib/types/utils.d.ts +2 -0
- package/lib/types/utimes.d.ts +13 -0
- package/lib/types/utimes.spec.d.ts +2 -0
- package/lib/types/watch.spec.d.ts +2 -0
- package/lib/types/watchfile.spec.d.ts +2 -0
- package/lib/types/write-stream.d.ts +1 -2
- package/package.json +12 -12
- package/src/callback.ts +22 -13
- package/src/cp.spec.ts +181 -0
- package/src/cp.ts +328 -0
- package/src/dir.spec.ts +204 -0
- package/src/dir.ts +199 -0
- package/src/fd-ops.spec.ts +234 -0
- package/src/fd-ops.ts +251 -0
- package/src/file-handle.ts +264 -94
- package/src/fs-watcher.ts +101 -6
- package/src/glob.spec.ts +201 -0
- package/src/glob.ts +205 -0
- package/src/index.ts +74 -0
- package/src/promises.ts +94 -29
- package/src/read-stream.ts +49 -43
- package/src/stat-watcher.ts +116 -0
- package/src/statfs.spec.ts +67 -0
- package/src/statfs.ts +92 -0
- package/src/streams.spec.ts +58 -0
- package/src/sync.ts +75 -57
- package/src/test.mts +13 -2
- package/src/utils.ts +10 -0
- package/src/utimes.spec.ts +113 -0
- package/src/utimes.ts +97 -0
- package/src/watch.spec.ts +171 -0
- package/src/watchfile.spec.ts +185 -0
- package/src/write-stream.ts +5 -8
- package/tsconfig.tsbuildinfo +1 -1
package/lib/esm/glob.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { readdirSync } from "./sync.js";
|
|
2
|
+
import { normalizePath } from "./utils.js";
|
|
3
|
+
function segmentToRegexSrc(seg) {
|
|
4
|
+
const extglob = /^([!*+?@])\((.+)\)$/.exec(seg);
|
|
5
|
+
if (extglob) {
|
|
6
|
+
const [, type, inner] = extglob;
|
|
7
|
+
const parts = inner.split("|").map((p) => segmentToRegexSrc(p));
|
|
8
|
+
const group = "(?:" + parts.join("|") + ")";
|
|
9
|
+
switch (type) {
|
|
10
|
+
case "!":
|
|
11
|
+
return "(?!(?:" + parts.join("|") + "))[^/]*";
|
|
12
|
+
case "*":
|
|
13
|
+
return group + "*";
|
|
14
|
+
case "+":
|
|
15
|
+
return group + "+";
|
|
16
|
+
case "?":
|
|
17
|
+
return group + "?";
|
|
18
|
+
case "@":
|
|
19
|
+
return group;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let result = "";
|
|
23
|
+
let i = 0;
|
|
24
|
+
while (i < seg.length) {
|
|
25
|
+
const c = seg[i];
|
|
26
|
+
if (c === "*") {
|
|
27
|
+
result += "[^/]*";
|
|
28
|
+
i++;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (c === "?") {
|
|
32
|
+
result += "[^/]";
|
|
33
|
+
i++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (c === "[") {
|
|
37
|
+
const end = seg.indexOf("]", i + 1);
|
|
38
|
+
if (end === -1) {
|
|
39
|
+
result += "\\[";
|
|
40
|
+
i++;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
result += seg.slice(i, end + 1);
|
|
44
|
+
i = end + 1;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (c === "{") {
|
|
48
|
+
const end = seg.indexOf("}", i + 1);
|
|
49
|
+
if (end === -1) {
|
|
50
|
+
result += "\\{";
|
|
51
|
+
i++;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const alts = seg.slice(i + 1, end).split(",").map((a) => segmentToRegexSrc(a.trim()));
|
|
55
|
+
result += "(?:" + alts.join("|") + ")";
|
|
56
|
+
i = end + 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (".+^$|()[]{}".includes(c)) {
|
|
60
|
+
result += "\\" + c;
|
|
61
|
+
} else {
|
|
62
|
+
result += c;
|
|
63
|
+
}
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function globToRegex(pattern) {
|
|
69
|
+
pattern = pattern.replace(/\/+/g, "/").replace(/^\.\//, "");
|
|
70
|
+
const segments = pattern.split("/");
|
|
71
|
+
const parts = [];
|
|
72
|
+
for (let si = 0; si < segments.length; si++) {
|
|
73
|
+
const seg = segments[si];
|
|
74
|
+
const isLast = si === segments.length - 1;
|
|
75
|
+
if (seg === "**") {
|
|
76
|
+
if (isLast) {
|
|
77
|
+
if (parts.length > 0 && parts[parts.length - 1] === "/") {
|
|
78
|
+
parts.pop();
|
|
79
|
+
parts.push("(?:/.+)?");
|
|
80
|
+
} else {
|
|
81
|
+
parts.push("(?:.+)?");
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
parts.push("(?:[^/]+/)*");
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
parts.push(segmentToRegexSrc(seg));
|
|
88
|
+
if (!isLast) parts.push("/");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return new RegExp("^(?:" + parts.join("") + ")$");
|
|
92
|
+
}
|
|
93
|
+
function buildExcludePredicate(exclude) {
|
|
94
|
+
if (!exclude) return null;
|
|
95
|
+
if (typeof exclude === "function") return exclude;
|
|
96
|
+
const patterns = Array.isArray(exclude) ? exclude : [exclude];
|
|
97
|
+
const regexes = patterns.map((p) => globToRegex(p));
|
|
98
|
+
return (path) => regexes.some((rx) => rx.test(path));
|
|
99
|
+
}
|
|
100
|
+
function matchAll(pattern, cwd, exclude) {
|
|
101
|
+
const regex = globToRegex(pattern);
|
|
102
|
+
const isExcluded = buildExcludePredicate(exclude);
|
|
103
|
+
let allEntries;
|
|
104
|
+
try {
|
|
105
|
+
allEntries = readdirSync(cwd, { recursive: true });
|
|
106
|
+
} catch {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
const candidates = [".", ...allEntries];
|
|
110
|
+
const results = [];
|
|
111
|
+
for (const entry of candidates) {
|
|
112
|
+
const normalized = entry.replace(/\\/g, "/");
|
|
113
|
+
if (!regex.test(normalized)) continue;
|
|
114
|
+
if (isExcluded && isExcluded(normalized)) continue;
|
|
115
|
+
results.push(entry);
|
|
116
|
+
}
|
|
117
|
+
return results;
|
|
118
|
+
}
|
|
119
|
+
function globSync(pattern, options) {
|
|
120
|
+
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
121
|
+
const cwd = options?.cwd ? normalizePath(options.cwd) : globalThis.process?.cwd?.() ?? "/";
|
|
122
|
+
const exclude = options?.exclude;
|
|
123
|
+
const seen = /* @__PURE__ */ new Set();
|
|
124
|
+
const results = [];
|
|
125
|
+
for (const p of patterns) {
|
|
126
|
+
for (const match of matchAll(p, cwd, exclude)) {
|
|
127
|
+
if (!seen.has(match)) {
|
|
128
|
+
seen.add(match);
|
|
129
|
+
results.push(match);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return results;
|
|
134
|
+
}
|
|
135
|
+
function glob(pattern, options, callback) {
|
|
136
|
+
let opts;
|
|
137
|
+
let cb;
|
|
138
|
+
if (typeof options === "function") {
|
|
139
|
+
cb = options;
|
|
140
|
+
opts = {};
|
|
141
|
+
} else {
|
|
142
|
+
cb = callback;
|
|
143
|
+
opts = options || {};
|
|
144
|
+
}
|
|
145
|
+
Promise.resolve().then(() => {
|
|
146
|
+
try {
|
|
147
|
+
const matches = globSync(pattern, opts);
|
|
148
|
+
cb(null, matches);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
cb(err, []);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async function* globAsync(pattern, options) {
|
|
155
|
+
const matches = globSync(pattern, options);
|
|
156
|
+
for (const m of matches) {
|
|
157
|
+
yield m;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export {
|
|
161
|
+
glob,
|
|
162
|
+
globAsync,
|
|
163
|
+
globSync
|
|
164
|
+
};
|
package/lib/esm/index.js
CHANGED
|
@@ -60,8 +60,48 @@ import {
|
|
|
60
60
|
WriteStream
|
|
61
61
|
} from "./write-stream.js";
|
|
62
62
|
import * as promises from "./promises.js";
|
|
63
|
+
import { cpSync, cp } from "./cp.js";
|
|
64
|
+
import { Dir, opendir, opendirSync } from "./dir.js";
|
|
65
|
+
import { glob, globSync } from "./glob.js";
|
|
66
|
+
import { StatWatcher, watchFile, unwatchFile } from "./stat-watcher.js";
|
|
67
|
+
import { statfsSync, statfs } from "./statfs.js";
|
|
63
68
|
import { Stats, BigIntStats } from "./stats.js";
|
|
64
69
|
import { Dirent } from "./dirent.js";
|
|
70
|
+
import {
|
|
71
|
+
utimesSync,
|
|
72
|
+
utimes,
|
|
73
|
+
lutimesSync,
|
|
74
|
+
lutimes,
|
|
75
|
+
lchownSync,
|
|
76
|
+
lchown,
|
|
77
|
+
lchmodSync,
|
|
78
|
+
lchmod
|
|
79
|
+
} from "./utimes.js";
|
|
80
|
+
import {
|
|
81
|
+
fstatSync,
|
|
82
|
+
fstat,
|
|
83
|
+
ftruncateSync,
|
|
84
|
+
ftruncate,
|
|
85
|
+
fdatasyncSync,
|
|
86
|
+
fdatasync,
|
|
87
|
+
fsyncSync,
|
|
88
|
+
fsync,
|
|
89
|
+
fchmodSync,
|
|
90
|
+
fchmod,
|
|
91
|
+
fchownSync,
|
|
92
|
+
fchown,
|
|
93
|
+
futimesSync,
|
|
94
|
+
futimes,
|
|
95
|
+
closeSync,
|
|
96
|
+
readSync,
|
|
97
|
+
writeSync,
|
|
98
|
+
readvSync,
|
|
99
|
+
readv,
|
|
100
|
+
writevSync,
|
|
101
|
+
writev,
|
|
102
|
+
exists,
|
|
103
|
+
openAsBlob
|
|
104
|
+
} from "./fd-ops.js";
|
|
65
105
|
const constants = {
|
|
66
106
|
// File access constants
|
|
67
107
|
F_OK: 0,
|
|
@@ -109,9 +149,11 @@ const constants = {
|
|
|
109
149
|
};
|
|
110
150
|
var index_default = {
|
|
111
151
|
FSWatcher,
|
|
152
|
+
StatWatcher,
|
|
112
153
|
Stats,
|
|
113
154
|
BigIntStats,
|
|
114
155
|
Dirent,
|
|
156
|
+
Dir,
|
|
115
157
|
constants,
|
|
116
158
|
existsSync,
|
|
117
159
|
readdirSync,
|
|
@@ -136,7 +178,46 @@ var index_default = {
|
|
|
136
178
|
truncateSync,
|
|
137
179
|
chmodSync,
|
|
138
180
|
chownSync,
|
|
181
|
+
cpSync,
|
|
182
|
+
opendirSync,
|
|
183
|
+
globSync,
|
|
184
|
+
glob,
|
|
139
185
|
watch,
|
|
186
|
+
watchFile,
|
|
187
|
+
unwatchFile,
|
|
188
|
+
statfsSync,
|
|
189
|
+
statfs,
|
|
190
|
+
utimesSync,
|
|
191
|
+
utimes,
|
|
192
|
+
lutimesSync,
|
|
193
|
+
lutimes,
|
|
194
|
+
lchownSync,
|
|
195
|
+
lchown,
|
|
196
|
+
lchmodSync,
|
|
197
|
+
lchmod,
|
|
198
|
+
fstatSync,
|
|
199
|
+
fstat,
|
|
200
|
+
ftruncateSync,
|
|
201
|
+
ftruncate,
|
|
202
|
+
fdatasyncSync,
|
|
203
|
+
fdatasync,
|
|
204
|
+
fsyncSync,
|
|
205
|
+
fsync,
|
|
206
|
+
fchmodSync,
|
|
207
|
+
fchmod,
|
|
208
|
+
fchownSync,
|
|
209
|
+
fchown,
|
|
210
|
+
futimesSync,
|
|
211
|
+
futimes,
|
|
212
|
+
closeSync,
|
|
213
|
+
readSync,
|
|
214
|
+
writeSync,
|
|
215
|
+
readvSync,
|
|
216
|
+
readv,
|
|
217
|
+
writevSync,
|
|
218
|
+
writev,
|
|
219
|
+
exists,
|
|
220
|
+
openAsBlob,
|
|
140
221
|
createReadStream,
|
|
141
222
|
ReadStream,
|
|
142
223
|
createWriteStream,
|
|
@@ -154,6 +235,7 @@ var index_default = {
|
|
|
154
235
|
stat,
|
|
155
236
|
rename,
|
|
156
237
|
copyFile,
|
|
238
|
+
cp,
|
|
157
239
|
access,
|
|
158
240
|
appendFile,
|
|
159
241
|
readlink,
|
|
@@ -165,13 +247,16 @@ var index_default = {
|
|
|
165
247
|
readFile,
|
|
166
248
|
writeFile,
|
|
167
249
|
unlink,
|
|
168
|
-
link
|
|
250
|
+
link,
|
|
251
|
+
opendir
|
|
169
252
|
};
|
|
170
253
|
export {
|
|
171
254
|
BigIntStats,
|
|
255
|
+
Dir,
|
|
172
256
|
Dirent,
|
|
173
257
|
FSWatcher,
|
|
174
258
|
ReadStream,
|
|
259
|
+
StatWatcher,
|
|
175
260
|
Stats,
|
|
176
261
|
WriteStream,
|
|
177
262
|
access,
|
|
@@ -183,30 +268,62 @@ export {
|
|
|
183
268
|
chown,
|
|
184
269
|
chownSync,
|
|
185
270
|
close,
|
|
271
|
+
closeSync,
|
|
186
272
|
constants,
|
|
187
273
|
copyFile,
|
|
188
274
|
copyFileSync,
|
|
275
|
+
cp,
|
|
276
|
+
cpSync,
|
|
189
277
|
createReadStream,
|
|
190
278
|
createWriteStream,
|
|
191
279
|
index_default as default,
|
|
280
|
+
exists,
|
|
192
281
|
existsSync,
|
|
282
|
+
fchmod,
|
|
283
|
+
fchmodSync,
|
|
284
|
+
fchown,
|
|
285
|
+
fchownSync,
|
|
286
|
+
fdatasync,
|
|
287
|
+
fdatasyncSync,
|
|
288
|
+
fstat,
|
|
289
|
+
fstatSync,
|
|
290
|
+
fsync,
|
|
291
|
+
fsyncSync,
|
|
292
|
+
ftruncate,
|
|
293
|
+
ftruncateSync,
|
|
294
|
+
futimes,
|
|
295
|
+
futimesSync,
|
|
296
|
+
glob,
|
|
297
|
+
globSync,
|
|
298
|
+
lchmod,
|
|
299
|
+
lchmodSync,
|
|
300
|
+
lchown,
|
|
301
|
+
lchownSync,
|
|
193
302
|
link,
|
|
194
303
|
linkSync,
|
|
195
304
|
lstat,
|
|
196
305
|
lstatSync,
|
|
306
|
+
lutimes,
|
|
307
|
+
lutimesSync,
|
|
197
308
|
mkdir,
|
|
198
309
|
mkdirSync,
|
|
199
310
|
mkdtempSync,
|
|
200
311
|
open,
|
|
312
|
+
openAsBlob,
|
|
201
313
|
openSync,
|
|
314
|
+
opendir,
|
|
315
|
+
opendirSync,
|
|
202
316
|
promises,
|
|
203
317
|
read,
|
|
204
318
|
readFile,
|
|
205
319
|
readFileSync,
|
|
320
|
+
readSync,
|
|
206
321
|
readdir,
|
|
207
322
|
readdirSync,
|
|
208
323
|
readlink,
|
|
209
324
|
readlinkSync,
|
|
325
|
+
readv,
|
|
326
|
+
readvSync,
|
|
210
327
|
realpath,
|
|
211
328
|
realpathSync,
|
|
212
329
|
rename,
|
|
@@ -217,14 +334,23 @@ export {
|
|
|
217
334
|
rmdirSync,
|
|
218
335
|
stat,
|
|
219
336
|
statSync,
|
|
337
|
+
statfs,
|
|
338
|
+
statfsSync,
|
|
220
339
|
symlink,
|
|
221
340
|
symlinkSync,
|
|
222
341
|
truncate,
|
|
223
342
|
truncateSync,
|
|
224
343
|
unlink,
|
|
225
344
|
unlinkSync,
|
|
345
|
+
unwatchFile,
|
|
346
|
+
utimes,
|
|
347
|
+
utimesSync,
|
|
226
348
|
watch,
|
|
349
|
+
watchFile,
|
|
227
350
|
write,
|
|
228
351
|
writeFile,
|
|
229
|
-
writeFileSync
|
|
352
|
+
writeFileSync,
|
|
353
|
+
writeSync,
|
|
354
|
+
writev,
|
|
355
|
+
writevSync
|
|
230
356
|
};
|
package/lib/esm/promises.js
CHANGED
|
@@ -3,8 +3,26 @@ import GLib from "@girs/glib-2.0";
|
|
|
3
3
|
import { join, dirname } from "node:path";
|
|
4
4
|
import { getEncodingFromOptions, encodeUint8Array, decode } from "./encoding.js";
|
|
5
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";
|
|
9
|
+
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";
|
|
6
24
|
import { FileHandle } from "./file-handle.js";
|
|
7
|
-
import { tempDirPath } from "./utils.js";
|
|
25
|
+
import { tempDirPath, normalizePath } from "./utils.js";
|
|
8
26
|
import { Dirent } from "./dirent.js";
|
|
9
27
|
import { Stats, BigIntStats, STAT_ATTRIBUTES } from "./stats.js";
|
|
10
28
|
import { createNodeError } from "./errors.js";
|
|
@@ -17,7 +35,7 @@ async function mkdir(path, options) {
|
|
|
17
35
|
} else {
|
|
18
36
|
_mode = options;
|
|
19
37
|
}
|
|
20
|
-
const pathStr = path
|
|
38
|
+
const pathStr = normalizePath(path);
|
|
21
39
|
if (recursive) {
|
|
22
40
|
return mkdirRecursiveAsync(pathStr);
|
|
23
41
|
}
|
|
@@ -28,7 +46,7 @@ async function mkdir(path, options) {
|
|
|
28
46
|
file.make_directory_finish(res);
|
|
29
47
|
resolve(void 0);
|
|
30
48
|
} catch (err) {
|
|
31
|
-
reject(createNodeError(err, "mkdir",
|
|
49
|
+
reject(createNodeError(err, "mkdir", pathStr));
|
|
32
50
|
}
|
|
33
51
|
});
|
|
34
52
|
});
|
|
@@ -75,7 +93,8 @@ async function mkdirRecursiveAsync(pathStr) {
|
|
|
75
93
|
}
|
|
76
94
|
}
|
|
77
95
|
async function readFile(path, options = { encoding: null, flag: "r" }) {
|
|
78
|
-
const
|
|
96
|
+
const pathStr = normalizePath(path);
|
|
97
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
79
98
|
let ok;
|
|
80
99
|
let data;
|
|
81
100
|
try {
|
|
@@ -89,10 +108,10 @@ async function readFile(path, options = { encoding: null, flag: "r" }) {
|
|
|
89
108
|
});
|
|
90
109
|
});
|
|
91
110
|
} catch (error) {
|
|
92
|
-
throw createNodeError(error, "open",
|
|
111
|
+
throw createNodeError(error, "open", pathStr);
|
|
93
112
|
}
|
|
94
113
|
if (!ok) {
|
|
95
|
-
throw createNodeError(new Error("failed to read file"), "open",
|
|
114
|
+
throw createNodeError(new Error("failed to read file"), "open", pathStr);
|
|
96
115
|
}
|
|
97
116
|
return encodeUint8Array(getEncodingFromOptions(options, "buffer"), data);
|
|
98
117
|
}
|
|
@@ -106,7 +125,8 @@ async function mkdtemp(prefix, options) {
|
|
|
106
125
|
return decode(path, encoding);
|
|
107
126
|
}
|
|
108
127
|
async function writeFile(path, data) {
|
|
109
|
-
const
|
|
128
|
+
const pathStr = normalizePath(path);
|
|
129
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
110
130
|
let bytes;
|
|
111
131
|
if (typeof data === "string") {
|
|
112
132
|
bytes = new TextEncoder().encode(data);
|
|
@@ -120,7 +140,7 @@ async function writeFile(path, data) {
|
|
|
120
140
|
try {
|
|
121
141
|
resolve(file.replace_finish(res));
|
|
122
142
|
} catch (err) {
|
|
123
|
-
reject(createNodeError(err, "open",
|
|
143
|
+
reject(createNodeError(err, "open", pathStr));
|
|
124
144
|
}
|
|
125
145
|
});
|
|
126
146
|
});
|
|
@@ -132,7 +152,7 @@ async function writeFile(path, data) {
|
|
|
132
152
|
outputStream.write_bytes_finish(res);
|
|
133
153
|
resolve();
|
|
134
154
|
} catch (err) {
|
|
135
|
-
reject(createNodeError(err, "write",
|
|
155
|
+
reject(createNodeError(err, "write", pathStr));
|
|
136
156
|
}
|
|
137
157
|
});
|
|
138
158
|
});
|
|
@@ -143,39 +163,40 @@ async function writeFile(path, data) {
|
|
|
143
163
|
outputStream.close_finish(res);
|
|
144
164
|
resolve();
|
|
145
165
|
} catch (err) {
|
|
146
|
-
reject(createNodeError(err, "close",
|
|
166
|
+
reject(createNodeError(err, "close", pathStr));
|
|
147
167
|
}
|
|
148
168
|
});
|
|
149
169
|
});
|
|
150
170
|
}
|
|
151
171
|
async function rmdir(path, _options) {
|
|
152
|
-
const
|
|
172
|
+
const pathStr = normalizePath(path);
|
|
173
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
153
174
|
const info = await new Promise((resolve, reject) => {
|
|
154
175
|
file.query_info_async("standard::type", Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
155
176
|
try {
|
|
156
177
|
resolve(file.query_info_finish(res));
|
|
157
178
|
} catch (err) {
|
|
158
|
-
reject(createNodeError(err, "rmdir",
|
|
179
|
+
reject(createNodeError(err, "rmdir", pathStr));
|
|
159
180
|
}
|
|
160
181
|
});
|
|
161
182
|
});
|
|
162
183
|
if (info.get_file_type() !== Gio.FileType.DIRECTORY) {
|
|
163
184
|
const err = Object.assign(new Error(), { code: 4 });
|
|
164
|
-
throw createNodeError(err, "rmdir",
|
|
185
|
+
throw createNodeError(err, "rmdir", pathStr);
|
|
165
186
|
}
|
|
166
187
|
const children = await new Promise((resolve, reject) => {
|
|
167
188
|
file.enumerate_children_async("standard::name", Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
168
189
|
try {
|
|
169
190
|
resolve(file.enumerate_children_finish(res));
|
|
170
191
|
} catch (err) {
|
|
171
|
-
reject(createNodeError(err, "rmdir",
|
|
192
|
+
reject(createNodeError(err, "rmdir", pathStr));
|
|
172
193
|
}
|
|
173
194
|
});
|
|
174
195
|
});
|
|
175
196
|
const firstChild = children.next_file(null);
|
|
176
197
|
if (firstChild !== null) {
|
|
177
198
|
const err = Object.assign(new Error(), { code: 5 });
|
|
178
|
-
throw createNodeError(err, "rmdir",
|
|
199
|
+
throw createNodeError(err, "rmdir", pathStr);
|
|
179
200
|
}
|
|
180
201
|
await new Promise((resolve, reject) => {
|
|
181
202
|
file.delete_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
@@ -183,20 +204,21 @@ async function rmdir(path, _options) {
|
|
|
183
204
|
file.delete_finish(res);
|
|
184
205
|
resolve();
|
|
185
206
|
} catch (err) {
|
|
186
|
-
reject(createNodeError(err, "rmdir",
|
|
207
|
+
reject(createNodeError(err, "rmdir", pathStr));
|
|
187
208
|
}
|
|
188
209
|
});
|
|
189
210
|
});
|
|
190
211
|
}
|
|
191
212
|
async function unlink(path) {
|
|
192
|
-
const
|
|
213
|
+
const pathStr = normalizePath(path);
|
|
214
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
193
215
|
await new Promise((resolve, reject) => {
|
|
194
216
|
file.delete_async(GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
195
217
|
try {
|
|
196
218
|
file.delete_finish(res);
|
|
197
219
|
resolve();
|
|
198
220
|
} catch (err) {
|
|
199
|
-
reject(createNodeError(err, "unlink",
|
|
221
|
+
reject(createNodeError(err, "unlink", pathStr));
|
|
200
222
|
}
|
|
201
223
|
});
|
|
202
224
|
});
|
|
@@ -221,14 +243,15 @@ async function _writeStr(fd, data, position, encoding) {
|
|
|
221
243
|
return { bytesWritten: result.bytesWritten, buffer: data };
|
|
222
244
|
}
|
|
223
245
|
function queryInfoAsync(path, flags, syscall, options) {
|
|
246
|
+
const pathStr = normalizePath(path);
|
|
224
247
|
return new Promise((resolve, reject) => {
|
|
225
|
-
const file = Gio.File.new_for_path(
|
|
248
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
226
249
|
file.query_info_async(STAT_ATTRIBUTES, flags, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
227
250
|
try {
|
|
228
251
|
const info = file.query_info_finish(res);
|
|
229
|
-
resolve(options?.bigint ? new BigIntStats(info,
|
|
252
|
+
resolve(options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr));
|
|
230
253
|
} catch (err) {
|
|
231
|
-
reject(createNodeError(err, syscall,
|
|
254
|
+
reject(createNodeError(err, syscall, pathStr));
|
|
232
255
|
}
|
|
233
256
|
});
|
|
234
257
|
});
|
|
@@ -250,20 +273,22 @@ async function realpath(path) {
|
|
|
250
273
|
return realpathSync(path);
|
|
251
274
|
}
|
|
252
275
|
async function symlink(target, path, _type) {
|
|
276
|
+
const pathStr = normalizePath(path);
|
|
277
|
+
const targetStr = normalizePath(target);
|
|
253
278
|
return new Promise((resolve, reject) => {
|
|
254
|
-
const file = Gio.File.new_for_path(
|
|
255
|
-
file.make_symbolic_link_async(
|
|
279
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
280
|
+
file.make_symbolic_link_async(targetStr, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
256
281
|
try {
|
|
257
282
|
file.make_symbolic_link_finish(res);
|
|
258
283
|
resolve();
|
|
259
284
|
} catch (err) {
|
|
260
|
-
reject(createNodeError(err, "symlink",
|
|
285
|
+
reject(createNodeError(err, "symlink", targetStr, pathStr));
|
|
261
286
|
}
|
|
262
287
|
});
|
|
263
288
|
});
|
|
264
289
|
}
|
|
265
290
|
async function rm(path, options) {
|
|
266
|
-
const pathStr = path
|
|
291
|
+
const pathStr = normalizePath(path);
|
|
267
292
|
const file = Gio.File.new_for_path(pathStr);
|
|
268
293
|
const recursive = options?.recursive || false;
|
|
269
294
|
const force = options?.force || false;
|
|
@@ -351,7 +376,26 @@ var promises_default = {
|
|
|
351
376
|
truncate,
|
|
352
377
|
chmod,
|
|
353
378
|
chown,
|
|
354
|
-
link
|
|
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
|
|
355
399
|
};
|
|
356
400
|
export {
|
|
357
401
|
access,
|
|
@@ -359,23 +403,42 @@ export {
|
|
|
359
403
|
chmod,
|
|
360
404
|
chown,
|
|
361
405
|
copyFile,
|
|
406
|
+
cpAsync as cp,
|
|
362
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,
|
|
363
418
|
link,
|
|
364
419
|
lstat,
|
|
420
|
+
lutimesAsync as lutimes,
|
|
365
421
|
mkdir,
|
|
366
422
|
mkdtemp,
|
|
367
423
|
open,
|
|
424
|
+
openAsBlob,
|
|
425
|
+
opendirAsync as opendir,
|
|
368
426
|
readFile,
|
|
369
427
|
readdir,
|
|
370
428
|
readlink,
|
|
429
|
+
readvAsync as readv,
|
|
371
430
|
realpath,
|
|
372
431
|
rename,
|
|
373
432
|
rm,
|
|
374
433
|
rmdir,
|
|
375
434
|
stat,
|
|
435
|
+
statfsAsync as statfs,
|
|
376
436
|
symlink,
|
|
377
437
|
truncate,
|
|
378
438
|
unlink,
|
|
439
|
+
utimesAsync as utimes,
|
|
440
|
+
watchAsync as watch,
|
|
379
441
|
write,
|
|
380
|
-
writeFile
|
|
442
|
+
writeFile,
|
|
443
|
+
writevAsync as writev
|
|
381
444
|
};
|