Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSystemHandle.name of the root directory #437

Open
ichaoX opened this issue Jan 29, 2024 · 6 comments
Open

FileSystemHandle.name of the root directory #437

ichaoX opened this issue Jan 29, 2024 · 6 comments

Comments

@ichaoX
Copy link

ichaoX commented Jan 29, 2024

The FileSystemHandle.name of the root directory may not be a valid file name (e.g. in bucket file system, it is an empty string), and developers may need to be aware of these special cases.

Is there a universal rule for obtaining the FileSystemHandle.name based on the root directory?

The following names are just my predictions and may differ from the current implementation of Chromium.

path FileSystemHandle.name
'/' ''
'D:\' 'D:'
'\\smb.example.com\share\' 'share'
'http://webdav.example.com:8080/' 'webdav.example.com:8080'
@a-sully
Copy link
Collaborator

a-sully commented Jan 29, 2024

The root directory of a Bucket File System is a special case. It is always the empty string; the only directory for which the name is not a "valid file name".

For all other FileSystemHandles (including other "root" directories), the name is specified by https://fs.spec.whatwg.org/#locating-an-entry:

entry’s name is the last item of locator’s path.

@a-sully a-sully closed this as completed Jan 29, 2024
@ichaoX
Copy link
Author

ichaoX commented Jan 30, 2024

@a-sully Thanks for your reply.

entry’s name is the last item of locator’s path.

A file system path is a list of one or more strings. This may be a virtual path that is mapped to real location on disk or in memory, may correspond directly to a path on the local file system, or may not correspond to any file on disk at all. The actual physical location of the corresponding file system entry is implementation-defined.

These descriptions are a bit unclear to me, does it mean that different User-Agents may return different FileSystemHandle.name for the same path 'D:\'? (e.g. it's '\' in Chromium, but 'D:' in Firefox Extension.)

As far as I know if FileSystemHandle.name is '\' or 'D:' both will make vscode.dev unavailable.

@a-sully
Copy link
Collaborator

a-sully commented Jan 30, 2024

Ah I see. This is currently not well-specified. The picker methods say to create:

a new FileSystemFileHandle associated with entry

... which has a few problems:

All that being said, '\' is not a valid file name (nor would it be once we update the criteria for a valid file name). Chromium appears to strip the drive letter from the path if you select a root (though we add it back in UI surfaces, e.g. for permissions) though I'm not sure off the top of my head why (@mkruisselbrink may know). Would you mind filing a new Chrome bug and pasting the URL here?

Firefox Extension

This looks very cool, by the way! :)

@a-sully a-sully reopened this Jan 30, 2024
@ichaoX
Copy link
Author

ichaoX commented Jan 30, 2024

The path "/" likely doesn't have a valid file name either. The FileSystemHandle.name is '/' in Chromium, but '' in Firefox Extension.

If an invalid file name is a bug, then what should the name be?

@a-sully
Copy link
Collaborator

a-sully commented Jan 31, 2024

it's '\' in Chromium, but 'D:' in Firefox Extension

I agree that both '\' and '/' are not valid names - or at least won't be once we address whatwg/fs#93

That issue relates to paths for the Bucket File System, though. What's not specified - but is necessary to safely allow access to the local file system - is the additional restrictions the user agent may put on file names. I imagine these restrictions will be non-normative once they are added to the spec.

For example, it looks like Chromium does not allow the colon character in file names, which explains why the drive letter is stripped....

If an invalid file name is a bug, then what should the name be?

...Good question! :)

The least-bad option might be to carve out an exception for drive roots ('/', 'D:', etc) in the same way we have done for the Bucket File System root. Whether that's '/' or '\' or '' or something else, I'm indifferent to... But it seems like it would be nice to pick one and specify it

@ichaoX
Copy link
Author

ichaoX commented Feb 1, 2024

I think that if the user agent cannot generate a valid file name for the root directory, reusing the empty string of the bucket file system is better than using path separators. Because developers only need to additionally consider this one special case.

However, probably generating a valid file name (e.g. "[root]") would have better compatibility than using an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants