@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.
- package/lib/esm/_virtual/_rolldown/runtime.js +18 -0
- package/lib/esm/callback.js +301 -302
- package/lib/esm/cp.js +207 -227
- package/lib/esm/dir.js +140 -148
- package/lib/esm/dirent.js +137 -128
- package/lib/esm/encoding.js +30 -27
- package/lib/esm/errors.js +15 -11
- package/lib/esm/fd-ops.js +105 -122
- package/lib/esm/file-handle.js +648 -653
- package/lib/esm/fs-watcher.js +153 -161
- package/lib/esm/glob.js +148 -149
- package/lib/esm/index.js +158 -351
- package/lib/esm/promises.js +413 -386
- package/lib/esm/read-stream.js +104 -108
- package/lib/esm/stat-watcher.js +113 -114
- package/lib/esm/statfs.js +56 -43
- package/lib/esm/stats.js +166 -159
- package/lib/esm/sync.js +366 -341
- package/lib/esm/types/index.js +6 -6
- package/lib/esm/utils.js +15 -17
- package/lib/esm/utimes.js +26 -37
- package/lib/esm/write-stream.js +96 -108
- package/package.json +10 -10
package/lib/esm/callback.js
CHANGED
|
@@ -1,357 +1,356 @@
|
|
|
1
|
+
import { normalizePath } from "./utils.js";
|
|
2
|
+
import { BigIntStats, STAT_ATTRIBUTES, Stats } from "./stats.js";
|
|
3
|
+
import { FileHandle } from "./file-handle.js";
|
|
4
|
+
import { createNodeError } from "./errors.js";
|
|
5
|
+
import { accessSync, appendFileSync, chmodSync, chownSync, copyFileSync, mkdirSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmdirSync, truncateSync, writeFileSync } from "./sync.js";
|
|
6
|
+
import { open as open$1, rm as rm$1 } from "./promises.js";
|
|
1
7
|
import GLib from "@girs/glib-2.0";
|
|
2
8
|
import Gio from "@girs/gio-2.0";
|
|
3
|
-
import { open as openP, rm as rmP } from "./promises.js";
|
|
4
|
-
import { FileHandle } from "./file-handle.js";
|
|
5
9
|
import { Buffer } from "node:buffer";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { realpathSync, readdirSync, renameSync, copyFileSync, accessSync, appendFileSync, readlinkSync, truncateSync, chmodSync, chownSync, mkdirSync, rmdirSync, readFileSync, writeFileSync } from "./sync.js";
|
|
9
|
-
import { normalizePath } from "./utils.js";
|
|
10
|
+
|
|
11
|
+
//#region src/callback.ts
|
|
10
12
|
function parseOptsCb(optionsOrCallback, maybeCallback) {
|
|
11
|
-
|
|
13
|
+
return typeof optionsOrCallback === "function" ? {
|
|
14
|
+
options: {},
|
|
15
|
+
callback: optionsOrCallback
|
|
16
|
+
} : {
|
|
17
|
+
options: optionsOrCallback ?? {},
|
|
18
|
+
callback: maybeCallback
|
|
19
|
+
};
|
|
12
20
|
}
|
|
13
21
|
function statImpl(path, flags, syscall, options, callback) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const pathStr = normalizePath(path);
|
|
23
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
24
|
+
file.query_info_async(STAT_ATTRIBUTES, flags, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
25
|
+
try {
|
|
26
|
+
const info = file.query_info_finish(res);
|
|
27
|
+
callback(null, options?.bigint ? new BigIntStats(info, pathStr) : new Stats(info, pathStr));
|
|
28
|
+
} catch (err) {
|
|
29
|
+
callback(createNodeError(err, syscall, pathStr));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
24
32
|
}
|
|
25
33
|
function stat(path, optionsOrCallback, maybeCallback) {
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
const { options, callback } = parseOptsCb(optionsOrCallback, maybeCallback);
|
|
35
|
+
statImpl(path, Gio.FileQueryInfoFlags.NONE, "stat", options, callback);
|
|
28
36
|
}
|
|
29
37
|
function lstat(path, optionsOrCallback, maybeCallback) {
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
const { options, callback } = parseOptsCb(optionsOrCallback, maybeCallback);
|
|
39
|
+
statImpl(path, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, "lstat", options, callback);
|
|
32
40
|
}
|
|
33
41
|
function readdir(path, optionsOrCallback, maybeCallback) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
const { options, callback } = parseOptsCb(optionsOrCallback, maybeCallback);
|
|
43
|
+
Promise.resolve().then(() => {
|
|
44
|
+
try {
|
|
45
|
+
callback(null, readdirSync(path, options));
|
|
46
|
+
} catch (err) {
|
|
47
|
+
callback(createNodeError(err, "readdir", path));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
42
50
|
}
|
|
43
51
|
function realpath(path, optionsOrCallback, maybeCallback) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
const { callback } = parseOptsCb(optionsOrCallback, maybeCallback);
|
|
53
|
+
Promise.resolve().then(() => {
|
|
54
|
+
try {
|
|
55
|
+
callback(null, realpathSync(path));
|
|
56
|
+
} catch (err) {
|
|
57
|
+
callback(err);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
52
60
|
}
|
|
53
61
|
function symlink(target, path, typeOrCallback, maybeCallback) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const callback = typeof typeOrCallback === "function" ? typeOrCallback : maybeCallback;
|
|
63
|
+
if (typeof callback !== "function") {
|
|
64
|
+
throw new TypeError("Callback must be a function. Received " + typeof callback);
|
|
65
|
+
}
|
|
66
|
+
const pathStr = normalizePath(path);
|
|
67
|
+
const targetStr = normalizePath(target);
|
|
68
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
69
|
+
file.make_symbolic_link_async(targetStr, GLib.PRIORITY_DEFAULT, null, (_s, res) => {
|
|
70
|
+
try {
|
|
71
|
+
file.make_symbolic_link_finish(res);
|
|
72
|
+
callback(null);
|
|
73
|
+
} catch (err) {
|
|
74
|
+
callback(createNodeError(err, "symlink", targetStr, pathStr));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
69
77
|
}
|
|
70
78
|
function open(path, ...args) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
79
|
+
let flags;
|
|
80
|
+
let mode;
|
|
81
|
+
let callback;
|
|
82
|
+
switch (args.length) {
|
|
83
|
+
case 1:
|
|
84
|
+
callback = args[0];
|
|
85
|
+
break;
|
|
86
|
+
case 2:
|
|
87
|
+
flags = args[0];
|
|
88
|
+
callback = args[1];
|
|
89
|
+
break;
|
|
90
|
+
case 3:
|
|
91
|
+
flags = args[0];
|
|
92
|
+
mode = args[1];
|
|
93
|
+
callback = args[2];
|
|
94
|
+
break;
|
|
95
|
+
default: break;
|
|
96
|
+
}
|
|
97
|
+
open$1(path, flags, mode).then((fileHandle) => {
|
|
98
|
+
callback(null, fileHandle.fd);
|
|
99
|
+
}).catch((err) => {
|
|
100
|
+
callback(err, -1);
|
|
101
|
+
});
|
|
95
102
|
}
|
|
96
103
|
function write(fd, data, ...args) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
104
|
+
const fileHandle = FileHandle.getInstance(fd);
|
|
105
|
+
if (typeof data === "string") {
|
|
106
|
+
const callback = args.pop();
|
|
107
|
+
const position = args[0];
|
|
108
|
+
const encoding = args[1];
|
|
109
|
+
fileHandle.write(data, position, encoding).then((res) => {
|
|
110
|
+
callback(null, res.bytesWritten, res.buffer);
|
|
111
|
+
}).catch((err) => {
|
|
112
|
+
callback(err, 0, "");
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const callback = args[args.length - 1];
|
|
117
|
+
const offset = args[0];
|
|
118
|
+
const length = args[1];
|
|
119
|
+
const position = args[2];
|
|
120
|
+
fileHandle.write(data, offset, length, position).then((res) => {
|
|
121
|
+
callback(null, res.bytesWritten, res.buffer);
|
|
122
|
+
}).catch((err) => {
|
|
123
|
+
callback(err, 0, Buffer.from([]));
|
|
124
|
+
});
|
|
118
125
|
}
|
|
119
126
|
function read(fd, ...args) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
127
|
+
const fileHandle = FileHandle.getInstance(fd);
|
|
128
|
+
const callback = args[args.length - 1];
|
|
129
|
+
let buffer;
|
|
130
|
+
let offset;
|
|
131
|
+
let length;
|
|
132
|
+
let position;
|
|
133
|
+
if (args.length <= 1) {} else if (typeof args[0] === "object" && !ArrayBuffer.isView(args[0])) {
|
|
134
|
+
const options = args[0];
|
|
135
|
+
buffer = options.buffer;
|
|
136
|
+
offset = options.offset;
|
|
137
|
+
length = options.length;
|
|
138
|
+
position = options.position;
|
|
139
|
+
} else {
|
|
140
|
+
buffer = args[0];
|
|
141
|
+
offset = args[1];
|
|
142
|
+
length = args[2];
|
|
143
|
+
position = args[3];
|
|
144
|
+
}
|
|
145
|
+
fileHandle.read(buffer, offset, length, position).then((res) => {
|
|
146
|
+
callback(null, res.bytesRead, res.buffer);
|
|
147
|
+
}).catch((err) => {
|
|
148
|
+
callback(err, 0, Buffer.from([]));
|
|
149
|
+
});
|
|
144
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Closes the file descriptor. No arguments other than a possible exception are
|
|
153
|
+
* given to the completion callback.
|
|
154
|
+
*
|
|
155
|
+
* Calling `fs.close()` on any file descriptor (`fd`) that is currently in use
|
|
156
|
+
* through any other `fs` operation may lead to undefined behavior.
|
|
157
|
+
*
|
|
158
|
+
* See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
|
|
159
|
+
* @since v0.0.2
|
|
160
|
+
*/
|
|
145
161
|
function close(fd, callback) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
162
|
+
FileHandle.getInstance(fd).close().then(() => {
|
|
163
|
+
callback(null);
|
|
164
|
+
}).catch((err) => callback(err));
|
|
149
165
|
}
|
|
150
166
|
function rm(path, ...args) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
let options = {};
|
|
168
|
+
let callback = args[args.length - 1];
|
|
169
|
+
if (args.length >= 2) {
|
|
170
|
+
options = args[0];
|
|
171
|
+
}
|
|
172
|
+
rm$1(path, options).then(() => {
|
|
173
|
+
callback(null);
|
|
174
|
+
}).catch((err) => {
|
|
175
|
+
callback(err);
|
|
176
|
+
});
|
|
161
177
|
}
|
|
162
178
|
function rename(oldPath, newPath, callback) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
179
|
+
Promise.resolve().then(() => {
|
|
180
|
+
try {
|
|
181
|
+
renameSync(oldPath, newPath);
|
|
182
|
+
callback(null);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
callback(err);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
171
187
|
}
|
|
172
188
|
function copyFile(src, dest, modeOrCb, maybeCb) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
const mode = typeof modeOrCb === "function" ? 0 : modeOrCb;
|
|
190
|
+
const callback = typeof modeOrCb === "function" ? modeOrCb : maybeCb;
|
|
191
|
+
Promise.resolve().then(() => {
|
|
192
|
+
try {
|
|
193
|
+
copyFileSync(src, dest, mode);
|
|
194
|
+
callback(null);
|
|
195
|
+
} catch (err) {
|
|
196
|
+
callback(err);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
183
199
|
}
|
|
184
200
|
function access(path, modeOrCb, maybeCb) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
201
|
+
const mode = typeof modeOrCb === "function" ? undefined : modeOrCb;
|
|
202
|
+
const callback = typeof modeOrCb === "function" ? modeOrCb : maybeCb;
|
|
203
|
+
Promise.resolve().then(() => {
|
|
204
|
+
try {
|
|
205
|
+
accessSync(path, mode);
|
|
206
|
+
callback(null);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
callback(err);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
195
211
|
}
|
|
196
212
|
function appendFile(path, data, optsOrCb, maybeCb) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
213
|
+
const callback = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
|
|
214
|
+
const options = typeof optsOrCb === "function" ? undefined : optsOrCb;
|
|
215
|
+
Promise.resolve().then(() => {
|
|
216
|
+
try {
|
|
217
|
+
appendFileSync(path, data, options);
|
|
218
|
+
callback(null);
|
|
219
|
+
} catch (err) {
|
|
220
|
+
callback(err);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
207
223
|
}
|
|
208
224
|
function readlink(path, optsOrCb, maybeCb) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
225
|
+
const callback = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
|
|
226
|
+
const options = typeof optsOrCb === "function" ? undefined : optsOrCb;
|
|
227
|
+
Promise.resolve().then(() => {
|
|
228
|
+
try {
|
|
229
|
+
callback(null, readlinkSync(path, options));
|
|
230
|
+
} catch (err) {
|
|
231
|
+
callback(err, "");
|
|
232
|
+
}
|
|
233
|
+
});
|
|
218
234
|
}
|
|
219
235
|
function truncate(path, lenOrCb, maybeCb) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
236
|
+
const len = typeof lenOrCb === "function" ? 0 : lenOrCb;
|
|
237
|
+
const callback = typeof lenOrCb === "function" ? lenOrCb : maybeCb;
|
|
238
|
+
Promise.resolve().then(() => {
|
|
239
|
+
try {
|
|
240
|
+
truncateSync(path, len);
|
|
241
|
+
callback(null);
|
|
242
|
+
} catch (err) {
|
|
243
|
+
callback(err);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
230
246
|
}
|
|
231
247
|
function chmod(path, mode, callback) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
248
|
+
Promise.resolve().then(() => {
|
|
249
|
+
try {
|
|
250
|
+
chmodSync(path, mode);
|
|
251
|
+
callback(null);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
callback(err);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
240
256
|
}
|
|
241
257
|
function chown(path, uid, gid, callback) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
258
|
+
Promise.resolve().then(() => {
|
|
259
|
+
try {
|
|
260
|
+
chownSync(path, uid, gid);
|
|
261
|
+
callback(null);
|
|
262
|
+
} catch (err) {
|
|
263
|
+
callback(err);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
250
266
|
}
|
|
251
267
|
function mkdir(path, optsOrCb, maybeCb) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
268
|
+
const callback = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
|
|
269
|
+
const options = typeof optsOrCb === "function" ? undefined : optsOrCb;
|
|
270
|
+
Promise.resolve().then(() => {
|
|
271
|
+
try {
|
|
272
|
+
mkdirSync(path, options);
|
|
273
|
+
callback(null);
|
|
274
|
+
} catch (err) {
|
|
275
|
+
callback(err);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
262
278
|
}
|
|
263
279
|
function rmdir(path, optsOrCb, maybeCb) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
const callback = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
|
|
281
|
+
const options = typeof optsOrCb === "function" ? undefined : optsOrCb;
|
|
282
|
+
Promise.resolve().then(() => {
|
|
283
|
+
try {
|
|
284
|
+
rmdirSync(path, options);
|
|
285
|
+
callback(null);
|
|
286
|
+
} catch (err) {
|
|
287
|
+
callback(err);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
274
290
|
}
|
|
275
291
|
function readFile(path, optsOrCb, maybeCb) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
292
|
+
const callback = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
|
|
293
|
+
const options = typeof optsOrCb === "function" ? undefined : optsOrCb;
|
|
294
|
+
const pathStr = normalizePath(path);
|
|
295
|
+
Promise.resolve().then(() => {
|
|
296
|
+
try {
|
|
297
|
+
const readOpts = typeof options === "string" ? {
|
|
298
|
+
encoding: options,
|
|
299
|
+
flag: "r"
|
|
300
|
+
} : {
|
|
301
|
+
encoding: options?.encoding ?? null,
|
|
302
|
+
flag: options?.flag ?? "r"
|
|
303
|
+
};
|
|
304
|
+
callback(null, readFileSync(pathStr, readOpts));
|
|
305
|
+
} catch (err) {
|
|
306
|
+
callback(err, null);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
287
309
|
}
|
|
288
310
|
function writeFile(path, data, optsOrCb, maybeCb) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
311
|
+
const callback = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
|
|
312
|
+
const pathStr = normalizePath(path);
|
|
313
|
+
Promise.resolve().then(() => {
|
|
314
|
+
try {
|
|
315
|
+
writeFileSync(pathStr, data);
|
|
316
|
+
callback(null);
|
|
317
|
+
} catch (err) {
|
|
318
|
+
callback(err);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
299
321
|
}
|
|
300
322
|
function link(existingPath, newPath, callback) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
323
|
+
const existingStr = normalizePath(existingPath);
|
|
324
|
+
const newStr = normalizePath(newPath);
|
|
325
|
+
Promise.resolve().then(() => {
|
|
326
|
+
try {
|
|
327
|
+
const result = GLib.spawn_command_line_sync(`ln ${existingStr} ${newStr}`);
|
|
328
|
+
if (!result[0]) {
|
|
329
|
+
throw Object.assign(new Error(`EPERM: operation not permitted, link '${existingStr}' -> '${newStr}'`), {
|
|
330
|
+
code: "EPERM",
|
|
331
|
+
errno: -1,
|
|
332
|
+
syscall: "link",
|
|
333
|
+
path: existingStr,
|
|
334
|
+
dest: newStr
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
callback(null);
|
|
338
|
+
} catch (err) {
|
|
339
|
+
callback(err);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
320
342
|
}
|
|
321
343
|
function unlink(path, callback) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
344
|
+
const pathStr = normalizePath(path);
|
|
345
|
+
Promise.resolve().then(() => {
|
|
346
|
+
try {
|
|
347
|
+
GLib.unlink(pathStr);
|
|
348
|
+
callback(null);
|
|
349
|
+
} catch (err) {
|
|
350
|
+
callback(err);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
331
353
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
chmod,
|
|
336
|
-
chown,
|
|
337
|
-
close,
|
|
338
|
-
copyFile,
|
|
339
|
-
link,
|
|
340
|
-
lstat,
|
|
341
|
-
mkdir,
|
|
342
|
-
open,
|
|
343
|
-
read,
|
|
344
|
-
readFile,
|
|
345
|
-
readdir,
|
|
346
|
-
readlink,
|
|
347
|
-
realpath,
|
|
348
|
-
rename,
|
|
349
|
-
rm,
|
|
350
|
-
rmdir,
|
|
351
|
-
stat,
|
|
352
|
-
symlink,
|
|
353
|
-
truncate,
|
|
354
|
-
unlink,
|
|
355
|
-
write,
|
|
356
|
-
writeFile
|
|
357
|
-
};
|
|
354
|
+
|
|
355
|
+
//#endregion
|
|
356
|
+
export { access, appendFile, chmod, chown, close, copyFile, link, lstat, mkdir, open, read, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, symlink, truncate, unlink, write, writeFile };
|