Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/commands/stack/scp.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,14 @@ class Connection {

// Begin transfer.
const commands = [
// Fail on error or pipe failure.
'set -eo pipefail',

// Start the header.
`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'",
Expand All @@ -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 );
} );
Expand Down