-
Notifications
You must be signed in to change notification settings - Fork 108
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
Filesystem abstraction library #39
base: master
Are you sure you want to change the base?
Conversation
Some suggestions (taking the associated gist in mind)
|
@iboB thanks for the valuable feedback!
|
Looking forward to this! |
I see the thread started in 2017 and hasn't had updates since 2018, is this still being considered? The marketing pitch looks great. |
Just saw this, and wanted to comment that a common mistake I see with filesystem abstractions (in my opinion) is using a single string to represent a file path. Google Drive is very much a filesystem, but it allows nearly all characters in filenames including forward slashes and backslashes, and has no concept of single-string-path. It also allows multiple identically-named items to exist in the same place. Nearly all filesystem APIs are incapable of handling this without doing weird workarounds, because they forget to abstract the concept of a path to a filesystem object at all. It's more than just changing slash directions. Sure, traditional filepaths can be the input to a convenience function that spits out the real path abstraction, but otherwise I feel that single-string paths do more harm than good since they often need processing anyway. I am also very much not convinced that web addresses / URLs should be involved here - you can't iterate over the content of a directory if it's a web URL because that's not how the web works. "Opening" a URL for "reading" may have side effects. It's an entirely different beast. Instead I think it'd make more sense to have a virtual filesystem that knows the directory layout already and can just perform HTTP requests on the fly under the hood while giving the appearance of an ordinary filesystem, specifically for the case of a web app. IMO the colon and everything before it should be an intrinsic property of the filesystem, and shouldn't be exposed to the code that uses that filesystem. You shouldn't have one API that can accept both Consider games - they'd need one read-only filesystem with the root as their install directory, and a read-write filesystem with the root as the place the player or OS has designated save data should go (e.g. the Saved Games folder on Windows, Maybe something like this would work - a path as an array of path fragments, and each fragment must have either a name or unique ID (or both), and it can only be used with a filesystem directly, not with a centralized API: using corrade::filesystem_literals::_pf; //path fragment
auto level_path = u8"level1"_pf/u8"geometry"/u8"main"; //slash operator like std::filesystem
Containers::Array<char> data = embedded_filesystem->read(level_path);
auto case_insensitive_path = u8"WiNdOwS iS wEiRd.TxT"_pf;
auto normalized_path = windows_filesystem->normalize(case_insensitive_path);
assert(normalized_path[0].name() == u8"Windows is Weird.txt");
auto gdrive_path = u8"directory of files w/o unique names \\o/"/PathFragment(u8"dummy filename, the ID takes precedence", unique_id);
std::u8string actual_filename = gdrive_filesystem->normalize(gdrive_path).crbegin()->name(); In the case of Google Drive I imagine that a single path fragment with an ID is enough to find the file anywhere and get its full path via normalization. A similar thing is possible in Windows, with ...This took more time to write than I realized, and may be overkill. Maybe simpler is better in most cases. I'd just like to vote for a little less simplicity for the sake of a lot more flexibility. I don't want a repeat of |
@LB-- thanks a lot for stopping by, you've made a bunch of great points 👍 I was not aware of Google Drive allowing Regarding the "single path string" -- good point. Instead of overloading fs->open("path/to/a/file.dat");
fs->open({"path", "to", "a", "file.dat"}); This will solve the problem of Allowing the use of IDs (GUID, inode ID...) for opening files is also a very good idea -- that nicely sidesteps all string processing and could be extended further (for example, referencing files by their SHA, like Git does). A caveat is that, as far as I can tell, both inode ID and GUID might get reassigned to a different file, so it's not failproof.
The main use case of the scheme prefixes is for convenient opening of arbitrary URLs by the user, similar to the KIO framework in KDE. For example, you could use magnum-player to open a file from an URL, a file from inside a ZIP file etc: magnum-player https://a.path.to/file.glb
magnum-player fish://192.168.1.105/home/mosra/models/chair.blend
magnum-player zip://backup.zip/cube.obj For Saved Games locations, this is not really where it could be used, except maybe if you'd want to give the users an ability to override the location (and then allow them to store the saves on a remote location, e.g.). I'll update the PR description with new TODO items for the above. @hsdk123 yes, if it wouldn't be, it would be closed already ;) I did some design/research work related to on-the-fly decompression back in August and have a bunch of new things locally, nothing pushed here tho. |
From what I can tell the API is more search-oriented (makes sense given the company in question), you search for files and you get a list of all the parent folders each file has. Also, folders are just files with a special MIME type, and
That was what I was thinking originally too, I just went with the operator overload in my example to mirror
After sleeping on this I realized I had a few misconceptions, since I was worried about conflicts with OS-registered protocol handlers. Then I realized, duh, |
Google developed a Linux FS that works akin to the custom pagefault callbacks linked above: https://www.osnews.com/story/131383/googles-new-incremental-file-system-may-let-you-play-big-android-games-before-theyre-fully-downloaded/ Not sure yet if I like it or not. |
A "one line" marketing pitch (everything subject to change):
Further info: https://gist.github.com/mosra/d64d4388d6a3bef80c6226ea6b479d6d
Things to do, based on the comments below and further research on my side:
magnum-player
), non-blocking on platforms where async is the default (Emscripten, HTTP downloads).Features
enum advertising each, checking that only allowed APIs are usedAbstractFilesystem
provide convenience wrappers to turn one into the other? I.e., spinning a thread to turn a blocking IO to async, do a "spin loop" waiting for the async for the inverse?Utility::FileWatcher
, but generalized)Further ideas:
Utility::Resource
, exposing it as a filesystem