Skip to content

Commit

Permalink
prevent broken uploads that create files with 0 bytes
Browse files Browse the repository at this point in the history
resolves: AndiDittrich#83
  • Loading branch information
czenker committed Feb 24, 2021
1 parent 9499957 commit 45a16c1
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions lib/connector/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const _luaCommandBuilder = require('../lua/command-builder');
const _logger = require('logging-facility').getLogger('connector');
const _luaMinifier = require('../lua/minifier');

// hex write helper already uploaded within current session ?
let _isTransferWriteHelperUploaded = false;
let _transferEncoding = null;

// utility function to handle the file transfer
Expand Down Expand Up @@ -85,34 +83,27 @@ async function startTransfer(rawContent, localName, remoteName, progressCb){

// utility function to upload file transfer helper
async function requireTransferHelper(){
// hex write helper already uploaded within current session ?
// otherwise upload helper
if (_isTransferWriteHelperUploaded !== true){
let response = null;

try{
({response} = await _virtualTerminal.executeCommand(_luaCommandBuilder.command.transferWriteHelper));

}catch(e){
_logger.debug(e);
throw new Error('cannot upload transfer helper function');
}
let response = null;

// get transfer encoding
if (response == 'b'){
_transferEncoding = 'base64'
}else if (response == 'h'){
_transferEncoding = 'hex'
}else{
throw new Error('unknown transfer encoding - ' + response);
}
try{
({response} = await _virtualTerminal.executeCommand(_luaCommandBuilder.command.transferWriteHelper));

// show encoding
_logger.log('Transfer-Mode: ' + _transferEncoding);
}catch(e){
_logger.debug(e);
throw new Error('cannot upload transfer helper function');
}

// set flag
_isTransferWriteHelperUploaded = true;
// get transfer encoding
if (response == 'b'){
_transferEncoding = 'base64'
}else if (response == 'h'){
_transferEncoding = 'hex'
}else{
throw new Error('unknown transfer encoding - ' + response);
}

// show encoding
_logger.log('Transfer-Mode: ' + _transferEncoding);
}

async function upload(localName, remoteName, options, progressCb){
Expand Down

0 comments on commit 45a16c1

Please sign in to comment.