diff --git a/tabby-core/src/api/platform.ts b/tabby-core/src/api/platform.ts index bf72880a3f..f6f9044c43 100644 --- a/tabby-core/src/api/platform.ts +++ b/tabby-core/src/api/platform.ts @@ -22,7 +22,7 @@ export interface MessageBoxResult { export abstract class FileTransfer { abstract getName (): string - abstract getRelativePath (): string + abstract getRelativePath (): string | null abstract getMode (): number abstract getSize (): number abstract close (): void @@ -204,8 +204,8 @@ export class HTMLFileUpload extends FileUpload { return this.file.name } - getRelativePath (): string { - return '' + getRelativePath (): null { + return null } getMode (): number { diff --git a/tabby-electron/src/services/platform.service.ts b/tabby-electron/src/services/platform.service.ts index 87d5fca54f..e8d20a0b3b 100644 --- a/tabby-electron/src/services/platform.service.ts +++ b/tabby-electron/src/services/platform.service.ts @@ -226,16 +226,17 @@ export class ElectronPlatformService extends PlatformService { } if(options.directory) { - let allFiles: string[] = [] - let relativePaths: string[] = [] + let fileInfos: { fullPath: string, relativePath: string }[] = [] for (const folderPath of paths) { const files = await this.getAllFiles(folderPath) - allFiles = allFiles.concat(files) - relativePaths = relativePaths.concat(files.map(file => path.posix.join(path.basename(folderPath), path.posix.relative(folderPath, file)))) + fileInfos = fileInfos.concat(files.map(file => ({ + fullPath: file, + relativePath: path.posix.join(path.basename(folderPath), path.posix.relative(folderPath, file)) + }))) } - return Promise.all(allFiles.map(async (p, index) => { - const transfer = new ElectronFileUpload(p, this.electron, relativePaths[index]) + return Promise.all(fileInfos.map(async (fileInfo) => { + const transfer = new ElectronFileUpload(fileInfo.fullPath, this.electron, fileInfo.relativePath) await wrapPromise(this.zone, transfer.open()) this.fileTransferStarted.next(transfer) return transfer @@ -363,8 +364,8 @@ class ElectronFileDownload extends FileDownload { return path.basename(this.filePath) } - getRelativePath (): string { - return '' + getRelativePath (): null { + return null } getMode (): number { diff --git a/tabby-ssh/src/components/sftpPanel.component.ts b/tabby-ssh/src/components/sftpPanel.component.ts index 773e34c03d..bee3a38bdd 100644 --- a/tabby-ssh/src/components/sftpPanel.component.ts +++ b/tabby-ssh/src/components/sftpPanel.component.ts @@ -187,25 +187,29 @@ export class SFTPPanelComponent { async uploadOneWithFolder (transfer: FileUpload): Promise { const savedPath = this.path + const RelativePath = transfer.getRelativePath() + if (RelativePath == null){ + return + } try { - await this.sftp.stat(path.join(this.path, transfer.getRelativePath())) + await this.sftp.stat(path.join(this.path, RelativePath)) } catch (e) { if (e instanceof Error && e.message.includes('No such file')) { let accumPath = '' - for (const pathParts of path.posix.dirname(transfer.getRelativePath()).split(path.posix.sep)) { + for (const pathParts of path.posix.dirname(RelativePath).split(path.posix.sep)) { accumPath = path.posix.join(accumPath, pathParts) - this.sftp.mkdir(path.join(this.path, accumPath)).then(() => { - this.notifications.notice('The directory was created successfully') - }).catch(() => { + try { + await this.sftp.mkdir(path.join(this.path, accumPath)) + } catch (e) { // Intentionally ignoring errors from making duplicate dirs. - }) + } } } else { throw e } } - await this.sftp.upload(path.join(this.path, transfer.getRelativePath()), transfer) + await this.sftp.upload(path.join(this.path, RelativePath), transfer) if (this.path === savedPath) { await this.navigate(this.path) } diff --git a/tabby-web/src/platform.ts b/tabby-web/src/platform.ts index aa1d504561..d95d4f73c0 100644 --- a/tabby-web/src/platform.ts +++ b/tabby-web/src/platform.ts @@ -159,8 +159,8 @@ class HTMLFileDownload extends FileDownload { return this.name } - getRelativePath (): string { - return '' + getRelativePath (): null { + return null } getMode (): number {