bdy 1.22.34-dev → 1.22.35-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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.22.34-dev",
4
+ "version": "1.22.35-beta",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -9,6 +9,7 @@ const promises_1 = __importDefault(require("fs/promises"));
9
9
  const fs_1 = require("fs");
10
10
  const path_1 = require("path");
11
11
  const node_os_1 = require("node:os");
12
+ const utils_1 = require("../../utils");
12
13
  const { STATUS_CODE } = ssh2_1.default.utils.sftp;
13
14
  var SftpOpenFlag;
14
15
  (function (SftpOpenFlag) {
@@ -39,6 +40,7 @@ class ServerSftp {
39
40
  openHandlers;
40
41
  count;
41
42
  home;
43
+ isWindows;
42
44
  sftp;
43
45
  constructor(sftp) {
44
46
  logger_1.default.debug('Creating sftp server');
@@ -46,6 +48,7 @@ class ServerSftp {
46
48
  this.count = 0;
47
49
  this.sftp = sftp;
48
50
  this.home = (0, node_os_1.homedir)();
51
+ this.isWindows = (0, utils_1.isWindows)();
49
52
  // fix for sftp/scp exit status -1: send exit-status and EOF before channel close
50
53
  // https://github.com/mscdex/ssh2/pull/1492
51
54
  const s = sftp;
@@ -95,12 +98,37 @@ class ServerSftp {
95
98
  fixPath(p) {
96
99
  if (!p)
97
100
  p = '';
98
- if (p.startsWith('~/') || p === '~')
99
- p = p.replace('~', this.home);
101
+ if (p === '~' || p.startsWith('~/')) {
102
+ p = this.home.replace(/\\/g, '/') + p.slice(1);
103
+ }
104
+ if (this.isWindows) {
105
+ // SFTP-on-Windows convention: /C:/foo -> C:/foo
106
+ if (/^\/[A-Za-z]:\//.test(p))
107
+ p = p.slice(1);
108
+ // Drive-absolute: normalize to native
109
+ if (/^[A-Za-z]:[\\/]/.test(p))
110
+ return (0, path_1.normalize)(p);
111
+ // UNC: //server/share/... or \\server\share\... -> native UNC
112
+ if (/^[\\/]{2}[^\\/?.]/.test(p))
113
+ return (0, path_1.normalize)(p);
114
+ // Extended-length / UNC-extended: \\?\C:\... or \\?\UNC\server\...
115
+ if (/^[\\/]{2}\?[\\/]/.test(p))
116
+ return (0, path_1.normalize)(p);
117
+ // POSIX-absolute on Windows has no real meaning — anchor to home
118
+ if (p.startsWith('/'))
119
+ p = p.slice(1);
120
+ return (0, path_1.normalize)((0, path_1.join)(this.home, p));
121
+ }
100
122
  if (!p.startsWith('/'))
101
123
  p = `${this.home}/${p}`;
102
124
  return p;
103
125
  }
126
+ toSftpPath(p) {
127
+ if (!this.isWindows)
128
+ return p;
129
+ const fwd = p.replace(/\\/g, '/');
130
+ return /^[A-Za-z]:\//.test(fwd) ? `/${fwd}` : fwd;
131
+ }
104
132
  async open(reqId, fileName, flags, attrs) {
105
133
  const p = this.fixPath(fileName);
106
134
  const s = this.debugStart(`SFTP want to open file ${p}`);
@@ -301,7 +329,7 @@ class ServerSftp {
301
329
  let displayName = name;
302
330
  if (isLink) {
303
331
  const link = await promises_1.default.readlink(fullPath);
304
- displayName = `${name} -> ${link}`;
332
+ displayName = `${name} -> ${this.toSftpPath(link)}`;
305
333
  }
306
334
  return [
307
335
  isDir ? 'd' : isLink ? 'l' : '-',
@@ -416,7 +444,7 @@ class ServerSftp {
416
444
  const longname = await this.longname(realPath, name, stat);
417
445
  this.sftp.name(reqId, [
418
446
  {
419
- filename: realPath,
447
+ filename: this.toSftpPath(realPath),
420
448
  longname,
421
449
  attrs: this.stats2attributes(stat)
422
450
  },
@@ -432,13 +460,14 @@ class ServerSftp {
432
460
  const p = this.fixPath(path);
433
461
  const s = this.debugStart(`SFTP want readlink ${p}`);
434
462
  try {
435
- const realPath = await promises_1.default.readlink(p);
436
- const name = (0, path_1.basename)(realPath);
437
- const stats = await promises_1.default.lstat(realPath);
438
- const longname = await this.longname(realPath, name, stats);
463
+ const target = await promises_1.default.readlink(p);
464
+ const absTarget = (0, path_1.isAbsolute)(target) ? target : (0, path_1.join)((0, path_1.dirname)(p), target);
465
+ const name = (0, path_1.basename)(target);
466
+ const stats = await promises_1.default.lstat(absTarget);
467
+ const longname = await this.longname(absTarget, name, stats);
439
468
  this.sftp.name(reqId, [
440
469
  {
441
- filename: realPath,
470
+ filename: this.toSftpPath(target),
442
471
  longname,
443
472
  attrs: this.stats2attributes(stats)
444
473
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.22.34-dev",
4
+ "version": "1.22.35-beta",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {