ssh2-sftp-client 5.1.1 → 5.2.1
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/README.md +1076 -1561
- package/README.org +133 -48
- package/package.json +6 -9
- package/src/index.js +118 -40
- package/src/utils.js +41 -15
package/src/utils.js
CHANGED
|
@@ -98,7 +98,7 @@ function handleError(err, name, reject) {
|
|
|
98
98
|
*/
|
|
99
99
|
function removeListeners(emitter) {
|
|
100
100
|
let listeners = emitter.eventNames();
|
|
101
|
-
listeners.forEach(name => {
|
|
101
|
+
listeners.forEach((name) => {
|
|
102
102
|
emitter.removeAllListeners(name);
|
|
103
103
|
});
|
|
104
104
|
}
|
|
@@ -111,14 +111,14 @@ function removeListeners(emitter) {
|
|
|
111
111
|
* @throws {Error} Throws new error
|
|
112
112
|
*/
|
|
113
113
|
function makeErrorListener(reject, self, name) {
|
|
114
|
-
return function(err) {
|
|
114
|
+
return function (err) {
|
|
115
115
|
self.errorHandled = true;
|
|
116
116
|
reject(formatError(err, name));
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
function makeEndListener(client) {
|
|
121
|
-
return function() {
|
|
121
|
+
return function () {
|
|
122
122
|
if (!client.endCalled) {
|
|
123
123
|
console.error(
|
|
124
124
|
`${client.clientName} End Listener: Connection ended unexpectedly`
|
|
@@ -128,7 +128,7 @@ function makeEndListener(client) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
function makeCloseListener(client, reject, name) {
|
|
131
|
-
return function() {
|
|
131
|
+
return function () {
|
|
132
132
|
if (!client.endCalled) {
|
|
133
133
|
if (reject) {
|
|
134
134
|
reject(formatError('Connection closed unepectedly', name));
|
|
@@ -208,8 +208,8 @@ function classifyError(err, testPath) {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
function localAccess(localPath, mode) {
|
|
211
|
-
return new Promise(resolve => {
|
|
212
|
-
fs.access(localPath, mode, err => {
|
|
211
|
+
return new Promise((resolve) => {
|
|
212
|
+
fs.access(localPath, mode, (err) => {
|
|
213
213
|
if (err) {
|
|
214
214
|
let {msg, code} = classifyError(err, localPath);
|
|
215
215
|
resolve({
|
|
@@ -481,8 +481,9 @@ async function checkWriteFile(client, aPath, type) {
|
|
|
481
481
|
code: errorCode.badPath
|
|
482
482
|
};
|
|
483
483
|
} else if (!type) {
|
|
484
|
-
let
|
|
485
|
-
|
|
484
|
+
let {root, dir} = path.parse(aPath);
|
|
485
|
+
//let parentDir = path.parse(aPath).dir;
|
|
486
|
+
if (!dir) {
|
|
486
487
|
return {
|
|
487
488
|
path: aPath,
|
|
488
489
|
type: false,
|
|
@@ -491,13 +492,20 @@ async function checkWriteFile(client, aPath, type) {
|
|
|
491
492
|
code: errorCode.badPath
|
|
492
493
|
};
|
|
493
494
|
}
|
|
494
|
-
|
|
495
|
+
if (root === dir) {
|
|
496
|
+
return {
|
|
497
|
+
path: aPath,
|
|
498
|
+
type: type,
|
|
499
|
+
valid: true
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
let parentType = await client.exists(dir);
|
|
495
503
|
if (!parentType) {
|
|
496
504
|
return {
|
|
497
505
|
path: aPath,
|
|
498
506
|
type: type,
|
|
499
507
|
valid: false,
|
|
500
|
-
msg: `Bad path: ${
|
|
508
|
+
msg: `Bad path: ${dir} parent not exist`,
|
|
501
509
|
code: errorCode.badPath
|
|
502
510
|
};
|
|
503
511
|
} else if (parentType !== 'd') {
|
|
@@ -505,7 +513,7 @@ async function checkWriteFile(client, aPath, type) {
|
|
|
505
513
|
path: aPath,
|
|
506
514
|
type: type,
|
|
507
515
|
valid: false,
|
|
508
|
-
msg: `Bad path: ${
|
|
516
|
+
msg: `Bad path: ${dir} must be a directory`,
|
|
509
517
|
code: errorCode.badPath
|
|
510
518
|
};
|
|
511
519
|
}
|
|
@@ -532,8 +540,15 @@ async function checkWriteDir(client, aPath, type) {
|
|
|
532
540
|
code: errorCode.badPath
|
|
533
541
|
};
|
|
534
542
|
} else if (!type) {
|
|
535
|
-
let
|
|
536
|
-
if (
|
|
543
|
+
let {root, dir} = path.parse(aPath);
|
|
544
|
+
if (root === dir) {
|
|
545
|
+
return {
|
|
546
|
+
path: aPath,
|
|
547
|
+
type: type,
|
|
548
|
+
valid: true
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
if (!dir) {
|
|
537
552
|
return {
|
|
538
553
|
path: aPath,
|
|
539
554
|
type: false,
|
|
@@ -542,7 +557,7 @@ async function checkWriteDir(client, aPath, type) {
|
|
|
542
557
|
code: errorCode.badPath
|
|
543
558
|
};
|
|
544
559
|
}
|
|
545
|
-
let parentType = await client.exists(
|
|
560
|
+
let parentType = await client.exists(dir);
|
|
546
561
|
if (parentType && parentType !== 'd') {
|
|
547
562
|
return {
|
|
548
563
|
path: aPath,
|
|
@@ -624,6 +639,16 @@ function haveConnection(client, name, reject) {
|
|
|
624
639
|
return true;
|
|
625
640
|
}
|
|
626
641
|
|
|
642
|
+
function dumpListeners(emitter) {
|
|
643
|
+
let eventNames = emitter.eventNames();
|
|
644
|
+
if (eventNames.length) {
|
|
645
|
+
console.log('Listener Data');
|
|
646
|
+
eventNames.map((n) => {
|
|
647
|
+
console.log(`${n}: ${emitter.listenerCount(n)}`);
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
627
652
|
module.exports = {
|
|
628
653
|
formatError,
|
|
629
654
|
handleError,
|
|
@@ -635,5 +660,6 @@ module.exports = {
|
|
|
635
660
|
checkLocalPath,
|
|
636
661
|
normalizeRemotePath,
|
|
637
662
|
checkRemotePath,
|
|
638
|
-
haveConnection
|
|
663
|
+
haveConnection,
|
|
664
|
+
dumpListeners
|
|
639
665
|
};
|