From 27f909e94e7e2f7d0b2080d40af4fbe6104e8822 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Thu, 7 Dec 2023 14:56:52 +0000 Subject: [PATCH 1/2] Detect errors from stat and fail --- lib/commands/stack/scp.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/commands/stack/scp.js b/lib/commands/stack/scp.js index 21ce329..12dbd99 100644 --- a/lib/commands/stack/scp.js +++ b/lib/commands/stack/scp.js @@ -309,6 +309,9 @@ class Connection { // Begin transfer. const commands = [ + // Fail on error or pipe failure. + 'set -eo pipefail', + // Start the header. `echo -n \$'\\e${ HEADER_INDICATOR };'`, @@ -326,6 +329,17 @@ class Connection { ]; this.log( LEVELS.INFO, 'Sending commands' ); this.log( LEVELS.DEBUG, JSON.stringify( commands.join( '; ' ) ) ); + this.session.on( 'disconnect', () => { + if ( ! didStartFile ) { + // Some sort of error occurred, likely during stat. + // Ensure we're closed. + status.clear(); + + // Pass feedback directly to user. + this.log( LEVELS.INFO, 'Did not start file' ); + reject( new Error( header.substring( 1 ).trimEnd() ) ); + } + } ); this.session.write( commands.join( '; ' ) + '\n' ); }, 1000 ); } ); From 8a6a1ae98ae2fa717e1df3e174f2de2e0994c498 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Thu, 7 Dec 2023 15:00:04 +0000 Subject: [PATCH 2/2] Correct trim line --- lib/commands/stack/scp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/stack/scp.js b/lib/commands/stack/scp.js index 12dbd99..fbfbb26 100644 --- a/lib/commands/stack/scp.js +++ b/lib/commands/stack/scp.js @@ -316,7 +316,7 @@ class Connection { `echo -n \$'\\e${ HEADER_INDICATOR };'`, // Get size using stat. - `stat -c "size=%s" ${ srcPath } | tr -d '\n'`, + `stat -c 'size=%s' ${ srcPath } | tr -d '\\n'`, // End header, start file. "echo -n $'\\a'",