This repository was archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
SharedDirectoryInfoResponse
#996
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
2cbc1b0
super basic picker with logging
bc51777
Adds SharedDirectoryAnnounce
bc6586b
Removes recording icon
fa09ec3
reverting config to its rightful checkin state
becfad3
updates storybook and storybook test snapshot
17408f8
Adds types for File System Access API
edfe30d
prettier
b9f0690
Adds SharedDirectoryAcknowledge, SharedDirectoryErrCode, updates some…
b3bf95c
Adds debug to logger
d69f16d
Adds SharedDirectoryInfoRequest
3474fed
Updates test with some ts-fu to get the maximum value of a numerical …
a0c6e9d
Updates babel targets to the latest 2 versions of primary browsers
1cd8131
Updates Adding Packages section with better instructions
589bc1e
Merge branch 'master' into isaiah/update-babel-build-targets
f2970db
super basic picker with logging
8150acc
Adds SharedDirectoryAnnounce
d3f9cac
Removes recording icon
9b5f4c6
updates storybook and storybook test snapshot
15d8343
Adds types for File System Access API
ca59266
prettier
20c14ff
Adds SharedDirectoryAcknowledge, SharedDirectoryErrCode, updates some…
43f921f
Adds debug to logger
e779785
Adds SharedDirectoryInfoRequest
265564f
Updates test with some ts-fu to get the maximum value of a numerical …
14a6166
swaps out wicg-native-file-system for apparently more up to date wicg…
317d0d8
adds SharedDirectoryInfoResponse and FileSystemObject to the codec
6c258ad
Retains existing functionality, substituting in a new sharedDirectory…
ece73c7
Adds untested walkPath
a187232
Merge branch 'master' into isaiah/sd-acknowledge
fe6ea5b
uses consts in decodeSharedDirectoryAcknowledge
7170e15
Merge branch 'isaiah/sd-acknowledge' into isaiah/sd-info-request
e54f251
uses consts in decodeSharedDirectoryInfoRequest
1c2ec0e
uses consts in decodeSharedDirectoryInfoRequest
d86c2ee
uses consts in decodePngFrame
85f87e5
uses consts in decodeStringMessage
f09ec07
uses consts in decodeMfaJson
a53d2ca
Merge branch 'master' into isaiah/sd-info-request
868f9d0
Adds __LAST to MessageType enum
6285d0e
Merge branch 'isaiah/sd-info-request' into isaiah/sd-info-response
634ad6a
reverting webapps.e change
e51e4e5
fixes broken merge
aea3043
creates getInfo for more efficient traversal
9b1e905
manually tested, cleaning up
ca89319
Merge branch 'master' into isaiah/sd-info-response
9a732a5
removing duplicate function definition
97cc3c0
Update packages/teleport/src/lib/tdp/sharedDirectoryManager.ts
215f038
Merge branch 'master' into isaiah/sd-info-response
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
packages/teleport/src/lib/tdp/sharedDirectoryManager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Copyright 2022 Gravitational, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // SharedDirectoryManager manages a FileSystemDirectoryHandle for use | ||
| // by the TDP client. Most of its methods can potentially throw errors | ||
| // and so should be wrapped in try/catch blocks. | ||
| export class SharedDirectoryManager { | ||
| private dir: FileSystemDirectoryHandle | undefined; | ||
|
|
||
| add(sharedDirectory: FileSystemDirectoryHandle) { | ||
| if (this.dir) { | ||
| throw new Error( | ||
| 'SharedDirectoryManager currently only supports sharing a single directory' | ||
| ); | ||
| } | ||
| this.dir = sharedDirectory; | ||
| } | ||
|
|
||
| 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. | ||
| async getInfo(path: string): Promise<{ | ||
| size: number; // bytes | ||
| lastModified: number; // ms since unix epoch | ||
| kind: 'file' | 'directory'; | ||
| }> { | ||
| this.checkReady(); | ||
|
|
||
| const fileOrDir = await this.walkPath(path); | ||
|
|
||
| if (fileOrDir.kind === 'directory') { | ||
| // Magic numbers are the values for directories where the true | ||
| // value is unavailable, according to the TDP spec. | ||
| return { size: 4096, lastModified: 0, kind: fileOrDir.kind }; | ||
| } | ||
|
|
||
| let file = await fileOrDir.getFile(); | ||
| return { | ||
| size: file.size, | ||
| lastModified: file.lastModified, | ||
| kind: fileOrDir.kind, | ||
| }; | ||
| } | ||
|
|
||
| // 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. | ||
| private async walkPath( | ||
| pathstr: string | ||
| ): Promise<FileSystemDirectoryHandle | FileSystemFileHandle> { | ||
| if (pathstr === '') { | ||
| return this.dir; | ||
| } | ||
|
|
||
| let path = pathstr.split('/'); | ||
|
|
||
| let walkIt = async ( | ||
| dir: FileSystemDirectoryHandle, | ||
| path: string[] | ||
| ): Promise<FileSystemDirectoryHandle | FileSystemFileHandle> => { | ||
| // Pop the next path element off the stack | ||
| let nextPathElem = path.shift(); | ||
|
|
||
| // Iterate through the items in the directory | ||
| for await (const entry of dir.values()) { | ||
| // If we find the entry we're looking for | ||
| if (entry.name === nextPathElem) { | ||
| if (path.length === 0) { | ||
| // We're at the end of the path, so this | ||
| // is the end element we've been walking towards. | ||
| return entry; | ||
| } else if (entry.kind === 'directory') { | ||
| // We're not at the end of the path and | ||
| // have encountered a directory, recurse | ||
| // further. | ||
| return walkIt(entry, path); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw new PathDoesNotExistError('path does not exist'); | ||
| }; | ||
|
|
||
| return walkIt(this.dir, path); | ||
| } | ||
|
|
||
| private checkReady() { | ||
| if (!this.dir) { | ||
| throw new Error( | ||
| 'attempted to use a shared directory before one was initialized' | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export class PathDoesNotExistError extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.