bdy 1.20.4-stage → 1.20.5-beta
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/distTs/package.json +1 -1
- package/distTs/src/tunnel/server/sftp.js +49 -28
- package/package.json +1 -1
package/distTs/package.json
CHANGED
|
@@ -12,12 +12,14 @@ const { flagsToString, STATUS_CODE } = ssh2_1.default.utils.sftp;
|
|
|
12
12
|
class ServerSftp {
|
|
13
13
|
openHandlers;
|
|
14
14
|
count;
|
|
15
|
+
home;
|
|
15
16
|
sftp;
|
|
16
17
|
constructor(sftp) {
|
|
17
18
|
logger_1.default.debug('Creating sftp server');
|
|
18
19
|
this.openHandlers = new Map();
|
|
19
20
|
this.count = 0;
|
|
20
21
|
this.sftp = sftp;
|
|
22
|
+
this.home = (0, node_os_1.homedir)();
|
|
21
23
|
this.sftp.on('OPEN', (reqId, fileName, flags, attrs) => this.open(reqId, fileName, flags, attrs));
|
|
22
24
|
this.sftp.on('READ', (reqId, handle, offset, length) => this.read(reqId, handle, offset, length));
|
|
23
25
|
this.sftp.on('WRITE', (reqId, handle, offset, data) => this.write(reqId, handle, offset, data));
|
|
@@ -48,8 +50,18 @@ class ServerSftp {
|
|
|
48
50
|
if (err)
|
|
49
51
|
logger_1.default.debug(err);
|
|
50
52
|
}
|
|
53
|
+
fixPath(p) {
|
|
54
|
+
if (!p)
|
|
55
|
+
p = '';
|
|
56
|
+
if (p.startsWith('~/') || p === '~')
|
|
57
|
+
p = p.replace('~', this.home);
|
|
58
|
+
if (!p.startsWith('/'))
|
|
59
|
+
p = `${this.home}/${p}`;
|
|
60
|
+
return p;
|
|
61
|
+
}
|
|
51
62
|
async open(reqId, fileName, flags, attrs) {
|
|
52
|
-
const
|
|
63
|
+
const p = this.fixPath(fileName);
|
|
64
|
+
const s = this.debugStart(`SFTP want to open file ${p}`);
|
|
53
65
|
try {
|
|
54
66
|
const flag = flagsToString(flags);
|
|
55
67
|
if (!flag) {
|
|
@@ -60,7 +72,7 @@ class ServerSftp {
|
|
|
60
72
|
const id = ++this.count;
|
|
61
73
|
const handle = Buffer.alloc(4);
|
|
62
74
|
handle.writeUint32BE(id, 0);
|
|
63
|
-
const fd = await promises_1.default.open(
|
|
75
|
+
const fd = await promises_1.default.open(p, flag);
|
|
64
76
|
this.openHandlers.set(id, fd);
|
|
65
77
|
await this._fsetstat(fd, attrs);
|
|
66
78
|
this.sftp.handle(reqId, handle);
|
|
@@ -222,12 +234,13 @@ class ServerSftp {
|
|
|
222
234
|
}
|
|
223
235
|
}
|
|
224
236
|
async opendir(reqId, path) {
|
|
225
|
-
const
|
|
237
|
+
const p = this.fixPath(path);
|
|
238
|
+
const s = this.debugStart(`SFTP want to open directory ${p}`);
|
|
226
239
|
try {
|
|
227
240
|
const id = ++this.count;
|
|
228
241
|
const handle = Buffer.alloc(4);
|
|
229
242
|
handle.writeUint32BE(id, 0);
|
|
230
|
-
const fd = await promises_1.default.opendir(
|
|
243
|
+
const fd = await promises_1.default.opendir(p);
|
|
231
244
|
this.openHandlers.set(id, fd);
|
|
232
245
|
this.sftp.handle(reqId, handle);
|
|
233
246
|
this.debugEnd('SFTP open directory succeed', s);
|
|
@@ -316,9 +329,10 @@ class ServerSftp {
|
|
|
316
329
|
}
|
|
317
330
|
}
|
|
318
331
|
async stat(reqId, path) {
|
|
319
|
-
const
|
|
332
|
+
const p = this.fixPath(path);
|
|
333
|
+
const s = this.debugStart(`SFTP want to stat ${p}`);
|
|
320
334
|
try {
|
|
321
|
-
const attrs = await promises_1.default.stat(
|
|
335
|
+
const attrs = await promises_1.default.stat(p);
|
|
322
336
|
this.sftp.attrs(reqId, this.stats2attributes(attrs));
|
|
323
337
|
this.debugEnd('SFTP stat path succeed', s);
|
|
324
338
|
}
|
|
@@ -328,9 +342,10 @@ class ServerSftp {
|
|
|
328
342
|
}
|
|
329
343
|
}
|
|
330
344
|
async remove(reqId, path) {
|
|
331
|
-
const
|
|
345
|
+
const p = this.fixPath(path);
|
|
346
|
+
const s = this.debugStart(`SFTP want to remove file ${p}`);
|
|
332
347
|
try {
|
|
333
|
-
await promises_1.default.rm(
|
|
348
|
+
await promises_1.default.rm(p);
|
|
334
349
|
this.sftp.status(reqId, STATUS_CODE.OK);
|
|
335
350
|
this.debugEnd('SFTP removed file succeed', s);
|
|
336
351
|
}
|
|
@@ -340,9 +355,10 @@ class ServerSftp {
|
|
|
340
355
|
}
|
|
341
356
|
}
|
|
342
357
|
async rmdir(reqId, path) {
|
|
343
|
-
const
|
|
358
|
+
const p = this.fixPath(path);
|
|
359
|
+
const s = this.debugStart(`SFTP want to remove directory ${p}`);
|
|
344
360
|
try {
|
|
345
|
-
await promises_1.default.rm(
|
|
361
|
+
await promises_1.default.rm(p, {
|
|
346
362
|
recursive: true,
|
|
347
363
|
force: true
|
|
348
364
|
});
|
|
@@ -355,12 +371,9 @@ class ServerSftp {
|
|
|
355
371
|
}
|
|
356
372
|
}
|
|
357
373
|
async realpath(reqId, path) {
|
|
358
|
-
const
|
|
374
|
+
const p = this.fixPath(path);
|
|
375
|
+
const s = this.debugStart(`SFTP want realpath ${p}`);
|
|
359
376
|
try {
|
|
360
|
-
let p = path || '~/';
|
|
361
|
-
if (p.includes('~')) {
|
|
362
|
-
p = p.replaceAll('~', (0, node_os_1.homedir)());
|
|
363
|
-
}
|
|
364
377
|
const realPath = await promises_1.default.realpath(p);
|
|
365
378
|
const name = (0, path_1.basename)(realPath);
|
|
366
379
|
const stat = await promises_1.default.lstat(realPath);
|
|
@@ -380,9 +393,10 @@ class ServerSftp {
|
|
|
380
393
|
}
|
|
381
394
|
}
|
|
382
395
|
async readlink(reqId, path) {
|
|
383
|
-
const
|
|
396
|
+
const p = this.fixPath(path);
|
|
397
|
+
const s = this.debugStart(`SFTP want readlink ${p}`);
|
|
384
398
|
try {
|
|
385
|
-
const realPath = await promises_1.default.readlink(
|
|
399
|
+
const realPath = await promises_1.default.readlink(p);
|
|
386
400
|
const name = (0, path_1.basename)(realPath);
|
|
387
401
|
const stats = await promises_1.default.lstat(realPath);
|
|
388
402
|
const longname = await this.longname(realPath, name, stats);
|
|
@@ -433,9 +447,10 @@ class ServerSftp {
|
|
|
433
447
|
}
|
|
434
448
|
}
|
|
435
449
|
async setstat(reqId, path, attrs) {
|
|
436
|
-
const
|
|
450
|
+
const p = this.fixPath(path);
|
|
451
|
+
const s = this.debugStart(`SFTP want to set attrs ${p}`);
|
|
437
452
|
try {
|
|
438
|
-
await this._setstat(
|
|
453
|
+
await this._setstat(p, attrs);
|
|
439
454
|
this.sftp.status(reqId, STATUS_CODE.OK);
|
|
440
455
|
this.debugEnd('SFTP set attrs succeed', s);
|
|
441
456
|
}
|
|
@@ -445,10 +460,11 @@ class ServerSftp {
|
|
|
445
460
|
}
|
|
446
461
|
}
|
|
447
462
|
async mkdir(reqId, path, attrs) {
|
|
448
|
-
const
|
|
463
|
+
const p = this.fixPath(path);
|
|
464
|
+
const s = this.debugStart(`SFTP want to create directory ${p}`);
|
|
449
465
|
try {
|
|
450
|
-
await promises_1.default.mkdir(
|
|
451
|
-
await this._setstat(
|
|
466
|
+
await promises_1.default.mkdir(p);
|
|
467
|
+
await this._setstat(p, attrs);
|
|
452
468
|
this.sftp.status(reqId, STATUS_CODE.OK);
|
|
453
469
|
this.debugEnd('SFTP create directory succeed', s);
|
|
454
470
|
}
|
|
@@ -458,9 +474,11 @@ class ServerSftp {
|
|
|
458
474
|
}
|
|
459
475
|
}
|
|
460
476
|
async rename(reqId, oldPath, newPath) {
|
|
461
|
-
const
|
|
477
|
+
const p1 = this.fixPath(oldPath);
|
|
478
|
+
const p2 = this.fixPath(newPath);
|
|
479
|
+
const s = this.debugStart(`SFTP want to rename path ${p1} to ${p2}`);
|
|
462
480
|
try {
|
|
463
|
-
await promises_1.default.rename(
|
|
481
|
+
await promises_1.default.rename(p1, p2);
|
|
464
482
|
this.sftp.status(reqId, STATUS_CODE.OK);
|
|
465
483
|
this.debugEnd('SFTP rename path succeed', s);
|
|
466
484
|
}
|
|
@@ -470,9 +488,11 @@ class ServerSftp {
|
|
|
470
488
|
}
|
|
471
489
|
}
|
|
472
490
|
async symlink(reqId, linkPath, targetPath) {
|
|
473
|
-
const
|
|
491
|
+
const lp = this.fixPath(linkPath);
|
|
492
|
+
const tp = this.fixPath(targetPath);
|
|
493
|
+
const s = this.debugStart(`SFTP want to symlink ${tp} at ${lp}`);
|
|
474
494
|
try {
|
|
475
|
-
await promises_1.default.symlink(
|
|
495
|
+
await promises_1.default.symlink(tp, lp);
|
|
476
496
|
this.sftp.status(reqId, STATUS_CODE.OK);
|
|
477
497
|
this.debugEnd('SFTP symlink succeed', s);
|
|
478
498
|
}
|
|
@@ -482,9 +502,10 @@ class ServerSftp {
|
|
|
482
502
|
}
|
|
483
503
|
}
|
|
484
504
|
async lstat(reqId, path) {
|
|
485
|
-
const
|
|
505
|
+
const p = this.fixPath(path);
|
|
506
|
+
const s = this.debugStart(`SFTP want to lstat ${p}`);
|
|
486
507
|
try {
|
|
487
|
-
const attrs = await promises_1.default.lstat(
|
|
508
|
+
const attrs = await promises_1.default.lstat(p);
|
|
488
509
|
this.sftp.attrs(reqId, this.stats2attributes(attrs));
|
|
489
510
|
this.debugEnd('SFTP lstat path succeed', s);
|
|
490
511
|
}
|