bdy 1.23.7-dev → 1.23.8-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.23.7-dev",
4
+ "version": "1.23.8-beta",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -20,6 +20,29 @@ var SftpOpenFlag;
20
20
  SftpOpenFlag[SftpOpenFlag["TRUNC"] = 16] = "TRUNC";
21
21
  SftpOpenFlag[SftpOpenFlag["EXCL"] = 32] = "EXCL";
22
22
  })(SftpOpenFlag || (SftpOpenFlag = {}));
23
+ // map node errno codes to sftp v3 status codes the same way openssh's
24
+ // errno_to_portable() does - clients treat a generic FAILURE as fatal and abort
25
+ // the transfer, e.g. on a REMOVE of a file that isn't there yet
26
+ function errToStatus(err) {
27
+ switch (err?.code) {
28
+ case 'ENOENT':
29
+ case 'ENOTDIR':
30
+ case 'EBADF':
31
+ case 'ELOOP':
32
+ return STATUS_CODE.NO_SUCH_FILE;
33
+ case 'EPERM':
34
+ case 'EACCES':
35
+ case 'EFAULT':
36
+ return STATUS_CODE.PERMISSION_DENIED;
37
+ case 'ENAMETOOLONG':
38
+ case 'EINVAL':
39
+ return STATUS_CODE.BAD_MESSAGE;
40
+ case 'ENOSYS':
41
+ return STATUS_CODE.OP_UNSUPPORTED;
42
+ default:
43
+ return STATUS_CODE.FAILURE;
44
+ }
45
+ }
23
46
  function sftpFlagsToPosix(flags) {
24
47
  const read = !!(flags & SftpOpenFlag.READ);
25
48
  const write = !!(flags & SftpOpenFlag.WRITE);
@@ -102,8 +125,8 @@ class ServerSftp {
102
125
  p = this.home.replace(/\\/g, '/') + p.slice(1);
103
126
  }
104
127
  if (this.isWindows) {
105
- // SFTP-on-Windows convention: /C:/foo -> C:/foo
106
- if (/^\/[A-Za-z]:\//.test(p))
128
+ // SFTP-on-Windows convention: /C:/foo -> C:/foo (clients also send /C:\foo)
129
+ if (/^\/[A-Za-z]:[\\/]/.test(p))
107
130
  p = p.slice(1);
108
131
  // Drive-absolute: normalize to native
109
132
  if (/^[A-Za-z]:[\\/]/.test(p))
@@ -143,7 +166,7 @@ class ServerSftp {
143
166
  this.debugEnd('SFTP open file succeed', s);
144
167
  }
145
168
  catch (err) {
146
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
169
+ this.sftp.status(reqId, errToStatus(err));
147
170
  this.debugEnd('SFTP open file failed', s, err);
148
171
  }
149
172
  }
@@ -174,7 +197,7 @@ class ServerSftp {
174
197
  this.debugEnd('SFTP read file succeed', s);
175
198
  }
176
199
  catch (err) {
177
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
200
+ this.sftp.status(reqId, errToStatus(err));
178
201
  this.debugEnd('SFTP read file failed', s, err);
179
202
  }
180
203
  }
@@ -193,7 +216,7 @@ class ServerSftp {
193
216
  this.debugEnd('SFTP write file succeed', s);
194
217
  }
195
218
  catch (err) {
196
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
219
+ this.sftp.status(reqId, errToStatus(err));
197
220
  this.debugEnd('SFTP write file failed', s, err);
198
221
  }
199
222
  }
@@ -213,7 +236,7 @@ class ServerSftp {
213
236
  this.debugEnd('SFTP closed handler succeed', s);
214
237
  }
215
238
  catch (err) {
216
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
239
+ this.sftp.status(reqId, errToStatus(err));
217
240
  this.debugEnd('SFTP close handler failed', s, err);
218
241
  }
219
242
  }
@@ -242,7 +265,7 @@ class ServerSftp {
242
265
  this.debugEnd('SFTP stat file succeed', s);
243
266
  }
244
267
  catch (err) {
245
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
268
+ this.sftp.status(reqId, errToStatus(err));
246
269
  this.debugEnd('SFTP stat file failed', s, err);
247
270
  }
248
271
  }
@@ -293,7 +316,7 @@ class ServerSftp {
293
316
  this.debugEnd('SFTP set attrs of file succeed', s);
294
317
  }
295
318
  catch (err) {
296
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
319
+ this.sftp.status(reqId, errToStatus(err));
297
320
  this.debugEnd('SFTP set attrs of file failed', s, err);
298
321
  }
299
322
  }
@@ -310,7 +333,7 @@ class ServerSftp {
310
333
  this.debugEnd('SFTP open directory succeed', s);
311
334
  }
312
335
  catch (err) {
313
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
336
+ this.sftp.status(reqId, errToStatus(err));
314
337
  this.debugEnd('SFTP open directory failed', s, err);
315
338
  }
316
339
  }
@@ -388,7 +411,7 @@ class ServerSftp {
388
411
  this.debugEnd(`SFTP read directory ${fd.path} succeed`, s);
389
412
  }
390
413
  catch (err) {
391
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
414
+ this.sftp.status(reqId, errToStatus(err));
392
415
  this.debugEnd('SFTP read directory failed', s, err);
393
416
  }
394
417
  }
@@ -401,7 +424,7 @@ class ServerSftp {
401
424
  this.debugEnd('SFTP stat path succeed', s);
402
425
  }
403
426
  catch (err) {
404
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
427
+ this.sftp.status(reqId, errToStatus(err));
405
428
  this.debugEnd('SFTP stat path failed', s, err);
406
429
  }
407
430
  }
@@ -414,7 +437,7 @@ class ServerSftp {
414
437
  this.debugEnd('SFTP removed file succeed', s);
415
438
  }
416
439
  catch (err) {
417
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
440
+ this.sftp.status(reqId, errToStatus(err));
418
441
  this.debugEnd('SFTP remove file failed', s, err);
419
442
  }
420
443
  }
@@ -430,7 +453,7 @@ class ServerSftp {
430
453
  this.debugEnd('SFTP remove directory succeed', s);
431
454
  }
432
455
  catch (err) {
433
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
456
+ this.sftp.status(reqId, errToStatus(err));
434
457
  this.debugEnd('SFTP remove directory failed', s, err);
435
458
  }
436
459
  }
@@ -452,7 +475,7 @@ class ServerSftp {
452
475
  this.debugEnd('SFTP realpath succeed', s);
453
476
  }
454
477
  catch (err) {
455
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
478
+ this.sftp.status(reqId, errToStatus(err));
456
479
  this.debugEnd('SFTP realpath failed', s, err);
457
480
  }
458
481
  }
@@ -475,7 +498,7 @@ class ServerSftp {
475
498
  this.debugEnd('SFTP readlink succeed', s);
476
499
  }
477
500
  catch (err) {
478
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
501
+ this.sftp.status(reqId, errToStatus(err));
479
502
  this.debugEnd('SFTP readlink failed', s, err);
480
503
  }
481
504
  }
@@ -520,7 +543,7 @@ class ServerSftp {
520
543
  this.debugEnd('SFTP set attrs succeed', s);
521
544
  }
522
545
  catch (err) {
523
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
546
+ this.sftp.status(reqId, errToStatus(err));
524
547
  this.debugEnd('SFTP set attrs failed', s, err);
525
548
  }
526
549
  }
@@ -534,7 +557,7 @@ class ServerSftp {
534
557
  this.debugEnd('SFTP create directory succeed', s);
535
558
  }
536
559
  catch (err) {
537
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
560
+ this.sftp.status(reqId, errToStatus(err));
538
561
  this.debugEnd('SFTP create directory failed', s, err);
539
562
  }
540
563
  }
@@ -548,7 +571,7 @@ class ServerSftp {
548
571
  this.debugEnd('SFTP rename path succeed', s);
549
572
  }
550
573
  catch (err) {
551
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
574
+ this.sftp.status(reqId, errToStatus(err));
552
575
  this.debugEnd('SFTP rename path failed', s, err);
553
576
  }
554
577
  }
@@ -562,7 +585,7 @@ class ServerSftp {
562
585
  this.debugEnd('SFTP symlink succeed', s);
563
586
  }
564
587
  catch (err) {
565
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
588
+ this.sftp.status(reqId, errToStatus(err));
566
589
  this.debugEnd('SFTP symlink failed', s, err);
567
590
  }
568
591
  }
@@ -575,7 +598,7 @@ class ServerSftp {
575
598
  this.debugEnd('SFTP lstat path succeed', s);
576
599
  }
577
600
  catch (err) {
578
- this.sftp.status(reqId, STATUS_CODE.FAILURE);
601
+ this.sftp.status(reqId, errToStatus(err));
579
602
  this.debugEnd('SFTP lstat path failed', s, err);
580
603
  }
581
604
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.23.7-dev",
4
+ "version": "1.23.8-beta",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",