-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add VSIMemGenerateHiddenFilename() and use it in drivers #10771
Conversation
cf21f7e
to
1104e38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, did you consider to name this feature "HiddenFile" instead of "UnlistedFile" ?
indeed, I did hesitate on the naming. I considered HiddenFile but thought that it would imply the file would be totally "invisible", which is not fully the case if you know where it is / how it is named. But on reflection, a hidden file on an operating system is pretty much similar. You don't see hit if you don't enable special filters, but if you know where it is , you can access it. |
Maybe @dbaston as a native speaker has a good suggestion on the best naming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rouault I'm going to stick to UUID strings in my own applications, but this is great 👍
port/cpl_vsi_mem.cpp
Outdated
// | ||
// The high-level design constraint is that "/vsimem/.#!HIDDEN!#." acts as a | ||
// "side" hiearchy, but still unders the "/vsimem/" namespace, so that code | ||
// acting specifically on /vsimem/ files. The structure of the returned filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this reads like an unfinished sentence (and I'm not sure how to finish it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant: "so that code having special processing of filenames starting with /vsimem/ can still work"
// - we don't want ".#!HIDDEN!#." to be listed in VSIReadDir("/vsimem/") | ||
// - we don't want content under ""/vsimem/.#!HIDDEN!#" to be deleted by | ||
// VSIRmdirRecursive("/vsimem/") | ||
// - we don't want the creation of a file (or directory) called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble understanding this. I would have expected
- directories starting with
.#!HIDDEN!#.'
are not listed - the filename returned by the new function is in a regular directory with a name like like
mktemp -u -d -p '/vsimem/.#!HIDDEN!#.'
.
It sounds more complex than this. I would need to check it out and play around to understand it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imagine:
- First call with VSIMemGenerateHiddenFilename("foo.gml") will return: "/vsimem/.!HIDDEN!./1/foo.gml"
- Second call with VSIMemGenerateHiddenFilename("bar.shp") will return: "/vsimem/.!HIDDEN!./2/bar.shp"
- Third call with VSIMemGenerateHiddenFilename("my_dir") will return: "/vsimem/.!HIDDEN!./3/my_dir", and user calls VSIMkdir("/vsimem/.!HIDDEN!./3/my_dir"), and craetes files "one" and "two" within it
Then
- VSIReadDir("/vsimem/") does not mention ".!HIDDEN!"
- VSIReadDir("/vsimem/.!HIDDEN!.") returns "1", "2" and "3", but this is an implementation detail, just for the purpose of our unit tests as code is not suppose to access the parent directories of the return path
- VSIReadDir("/vsimem/.!HIDDEN!./3/my_dir") returns "one" and "two"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by VSIReadDir("/vsimem/.!HIDDEN!.")
listing "1", "2", and "3", but then VSIStat
telling me that "/vsimem/.!HIDDEN!./2"
does not exist. Why is "2" not just a regular directory with a unique name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is "2" not just a regular directory with a unique name?
"Explicit" directories, like regular files, are listed in the oFileList member variable. If they are listed there, someone must clean up them at some point using Unlink() or Rmdir().
For a file returned by VSIMemGenerateHiddenFilename("foo.tif"), so something like "/vsimem/.!HIDDEN!./123/foo.tif", we only want the returned filename to be something explicit, because that's the only resource the user must take care of deleting, but not its parent directories "/vsimem/.!HIDDEN!./123" or ""/vsimem/.!HIDDEN!."
Hence VSIReadDir("/vsimem/.!HIDDEN!."), which is normally just for debugging purposes, has special processing to synthetize the "{counter}" directories from the filenames like "/vsimem/.!HIDDEN!./123/foo.tif", but without needing an explicit "/vsimem/.!HIDDEN!./123" entry in oFileList
We could possibly have VSIStat() work on "/vsimem/.!HIDDEN!./123" but that doesn't appear to me as being strictly needed for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand how treating these directories as a special case avoids the need to clean them up later. And I guess forcing every temporary file into a separate "directory" avoids potential collisions from sidecar files. It seems like a complex solution relative to following an existing API like mktemp
, but not something I feel terribly strongly about.
+1 for VSIMemGenerateHiddenFilename |
1104e38
to
9119a48
Compare
Renamed to VSIMemGenerateHiddenFilename |
Tons of drivers need to create temporary
/vsimem/
files. The current practice has been that drivers needed to figure out the filename by themselves. There were 2 major issues:This PR thus adds the following function and use it wherever possible: