diff --git a/packages/teleport/src/lib/tdp/client.ts b/packages/teleport/src/lib/tdp/client.ts index 9b0865c3d..93902632f 100644 --- a/packages/teleport/src/lib/tdp/client.ts +++ b/packages/teleport/src/lib/tdp/client.ts @@ -226,8 +226,13 @@ export default class Client extends EventEmitterWebAuthnSender { if (!this.wasSuccessful(ack.errCode)) { return; } - - this.logger.info('Started sharing directory: ' + this.sdManager.getName()); + try { + this.logger.info( + 'Started sharing directory: ' + this.sdManager.getName() + ); + } catch (e) { + this.handleError(e); + } } async handleSharedDirectoryInfoRequest(buffer: ArrayBuffer) { diff --git a/packages/teleport/src/lib/tdp/sharedDirectoryManager.ts b/packages/teleport/src/lib/tdp/sharedDirectoryManager.ts index 4f2da831a..45620b1bb 100644 --- a/packages/teleport/src/lib/tdp/sharedDirectoryManager.ts +++ b/packages/teleport/src/lib/tdp/sharedDirectoryManager.ts @@ -18,6 +18,9 @@ export class SharedDirectoryManager { private dir: FileSystemDirectoryHandle | undefined; + /** + * @throws Will throw an error if a directory is already being shared. + */ add(sharedDirectory: FileSystemDirectoryHandle) { if (this.dir) { throw new Error( @@ -27,14 +30,19 @@ export class SharedDirectoryManager { this.dir = sharedDirectory; } + /** + * @throws Will throw an error if a directory has not already been initialized via add(). + */ getName(): string { this.checkReady(); return this.dir.name; } - // Gets the information for the file or directory - // at path where path is the relative path from the - // root directory. + /** + * Gets the information for the file or directory at path where path is the relative path from the root directory. + * @throws Will throw an error if a directory has not already been initialized via add(). + * @throws {PathDoesNotExistError} if the pathstr isn't a valid path in the shared directory + */ async getInfo(path: string): Promise { this.checkReady(); @@ -55,8 +63,11 @@ export class SharedDirectoryManager { }; } - // Gets the FileOrDirInfo for all the children of the - // directory at path. + /** + * Gets the FileOrDirInfo for all the children of the directory at path. + * @throws Will throw an error if a directory has not already been initialized via add(). + * @throws {PathDoesNotExistError} if the pathstr isn't a valid path in the shared directory + */ async listContents(path: string): Promise { this.checkReady(); @@ -81,7 +92,11 @@ export class SharedDirectoryManager { return infos; } - // Reads length bytes starting at offset from a file at path. + /** + * Reads length bytes starting at offset from a file at path. + * @throws Will throw an error if a directory has not already been initialized via add(). + * @throws {PathDoesNotExistError} if the pathstr isn't a valid path in the shared directory + */ async readFile( path: string, offset: bigint, @@ -101,7 +116,11 @@ export class SharedDirectoryManager { ); } - // Writes the bytes in writeData to the file at path starting at offset. + /** + * Writes the bytes in writeData to the file at path starting at offset. + * @throws Will throw an error if a directory has not already been initialized via add(). + * @throws {PathDoesNotExistError} if the pathstr isn't a valid path in the shared directory + */ async writeFile( path: string, offset: bigint, @@ -124,10 +143,12 @@ export class SharedDirectoryManager { return writeData.length; } - // walkPath walks a pathstr (assumed to be in the qualified Unix format specified - // in the TDP spec), returning the FileSystemDirectoryHandle | FileSystemFileHandle - // it finds at its end. If the pathstr isn't a valid path in the shared directory, - // it throws an error. + /** + * walkPath walks a pathstr (assumed to be in the qualified Unix format specified + * in the TDP spec), returning the FileSystemDirectoryHandle | FileSystemFileHandle + * it finds at its end. + * @throws {PathDoesNotExistError} if the pathstr isn't a valid path in the shared directory + */ private async walkPath( pathstr: string ): Promise { @@ -169,6 +190,9 @@ export class SharedDirectoryManager { return walkIt(this.dir, path); } + /** + * @throws Will throw an error if a directory has not already been initialized via add(). + */ private checkReady() { if (!this.dir) { throw new Error( diff --git a/yarn.lock b/yarn.lock index d8c8ad0e1..0d5599b7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10412,6 +10412,22 @@ node-gyp@8.4.1: tar "^6.1.2" which "^2.0.2" +node-gyp@8.4.1: + version "8.4.1" + resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-8.4.1.tgz#3d49308fc31f768180957d6b5746845fbd429937" + integrity sha512-olTJRgUtAb/hOXG0E93wZDs5YiJlgbXxTwQAFHyNlRsXQnYzUaF2aGgujZbw+hR8aF4ZG/rST57bWMWD16jr9w== + dependencies: + env-paths "^2.2.0" + glob "^7.1.4" + graceful-fs "^4.2.6" + make-fetch-happen "^9.1.0" + nopt "^5.0.0" + npmlog "^6.0.0" + rimraf "^3.0.2" + semver "^7.3.5" + tar "^6.1.2" + which "^2.0.2" + node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"