Skip to content

Commit

Permalink
[CopyFilesOverSSH] Addressed code review points
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Dobrodeev committed Jul 22, 2020
1 parent bf58c19 commit 4a70555
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Tasks/CopyFilesOverSSHV0/copyfilesoverssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async function run() {
let targetPath = path.posix.join(targetFolder, relativePath);

if (!path.isAbsolute(targetPath)) {
targetPath = './' + targetPath
targetPath = `./${targetPath}`;
}

console.log(tl.loc('StartedFileCopy', fileToCopy, targetPath));
Expand Down
181 changes: 77 additions & 104 deletions Tasks/CopyFilesOverSSHV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions Tasks/CopyFilesOverSSHV0/sshhelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export class SshHelper {
await defer.promise;
}

/**
* Change path separator for Windows-based platforms
* See https://github.com/spmjs/node-scp2/blob/master/lib/client.js#L319
*
* @param filePath
*/
private unixyPath(filePath) {
if (process.platform === 'win32') {
return filePath.replace(/\\/g, '/');
}
return filePath;
}

/**
* Sets up the SSH connection
*/
Expand All @@ -72,6 +85,9 @@ export class SshHelper {
async closeConnection() {
try {
if (this.sftpClient) {
this.sftpClient.on('error', (err) => {
tl.debug('sftpClient: Ignoring error diconnecting: ' + err);
}); // ignore logout errors; see: https://github.com/mscdex/node-imap/issues/695
await this.sftpClient.end();
this.sftpClient = null;
}
Expand All @@ -98,9 +114,7 @@ export class SshHelper {
* @returns {Promise<string>}
*/
async uploadFile(sourceFile: string, dest: string) : Promise<string> {
if (process.platform === 'win32') {
dest = dest.replace(/\\/g, '/');
}
dest = this.unixyPath(dest);

tl.debug('Upload ' + sourceFile + ' to ' + dest + ' on remote machine.');

Expand Down Expand Up @@ -142,7 +156,7 @@ export class SshHelper {
if(!this.sftpClient) {
defer.reject(tl.loc('ConnectionNotSetup'));
}
if (await this.sftpClient.stat(path)) {
if (await this.sftpClient.exsts(path)) {
//path exists
defer.resolve(true);
} else {
Expand Down

0 comments on commit 4a70555

Please sign in to comment.