-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: path/filepath: add IsReserved to identify Windows reserved filenames #57152
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
Comments
Who do we expect to call |
CC @golang/windows |
For portable programs, it seems most useful to have I don't think So I think |
As @bcmills says, for people writing portable programs it seems more useful to have an Another motivating case is #57151 ( |
Function was re-written recently in package go/src/path/filepath/path_windows.go Lines 23 to 28 in f721fa3
I do not know if proposal is complete. |
With IsLocal having been added, do we still need IsReserved? |
This proposal has been added to the active column of the proposals project |
I believe A name with NUL bytes is invalid, not reserved. I could see an argument for calling "." and ".." reserved. A standard library function should be some combination of broadly useful or difficult to implement. A function which is trivial to implement may be worth including if it is very widely used, and a function which is seldom used may be worth including if those rare uses would be painful without it. I believe The complexity of this function argues to me that we should make it available on its own, not just as part of a broader API like Perhaps we could put this in some external package (although probably not |
What does IsReserved("foo/nul/bar") return? Does IsReserved mean "this path doesn't mean what it looks like?" |
I don't know about Plan 9. Do you have a reference to how #-prefixed paths work? I haven't been able to find one. Can I On Windows, "Doesn't mean what it looks like" is a good characterization. Or "not actually part of the filesystem". |
For Plan 9, search for |
I could see an argument for calling |
Yes, #c on Plan 9 is a lot like a volume name on Windows. |
What about IsReserved("..")? Can we write a precise definition of what "Reserved" means? |
Now that I think more about the volume name question, does IsReserved("C:") return true? Does IsReserved("C:/foo") return true? If not, how does code that checks paths with IsReserved avoid being tricked into writing to absolute paths starting with volume names? filepath.IsLocal already does that I guess. But then I'm confused about what the use case is. I should use IsLocal instead of IsReserved almost all the time.
Is there a clearer use case? |
Same question as last week: do we really need this function to be exported at all? |
A good definition might be: A reserved file name is one which cannot be used to create a file with that name. For example, on Windows it is not possible to create a file named Under this definition, I think the names Volume names are not reserved, because a volume name isn't a file name. I'm not certain that we need this function. My main argument in favor of it is still the one from #57152 (comment): Very few users need this, but it's incredibly hard to get right and risky to get wrong. |
What about IsReserved("/")? I have a hard time explaining why the answers that IsReserved returns for "/", ".", "..", "c:\", and "c:" would not all be the same, whatever it ends up being. If users already have IsLocal (which already rejects all these things like NUL and COMIN$), when do users need IsReserved instead of IsLocal? |
Consider a user who wants to implement #57151 (a version of You can do this with I don't think it's useful to call The motivation for
|
I feel like we should call this |
@neild and I discussed and suggest declining for now until we have more compelling use cases. Most programs will be well served by FromFS/Localize. |
Based on the discussion above, this proposal seems like a likely decline. |
This proposal has been added to the active column of the proposals project |
No change in consensus, so declined. |
On Windows, a number of filenames are reserved for use by the system, such as "CON", "COM1", and "CONIN$". The set of reserved names is subtle and varies by Windows version; some versions reserve names with extensions such as "con.txt" while others do not.
The new
filepath.IsLocal
function (#56219) returns false when provided a reserved filename on Windows. However, we don't have a function which only identifies reserved filenames. This seems like a useful thing to have. We already have one Windows-specific function in filepath (filepath.VolumeName
), so adding another may be reasonable.The proposal:
The text was updated successfully, but these errors were encountered: