-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 mixxx::FileInfo for file system references #3741
Conversation
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 have left some comments.
I have not yet get the point where it helps in:
#2656
Can you print me to a place?
src/util/fileinfo.h
Outdated
namespace mixxx { | ||
|
||
/// Helper functions and extensions for QFileInfo using Mixxx terminology. | ||
namespace fileinfo { |
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.
Having a namespace in addition to a class would be a new concept in Mixxx, and will probably hide the function from intellisense feature of the IDE.
I would prefere to make them static class members.
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.
How would you then name those static functions to resolve the naming conflicts?
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.
We can have a static and a non static function with the same name, because the parameters are different.
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.
QSting location = AbsoluteFileInfo::location(file);
Looks Ok to me.
The purpose of the assert inside would be obvious. No need to a extra comment.
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.
The property of being not relative is not a class invariant. Instead this must be determined at runtime whenver you try to obtain a location string.
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.
How could it happen that it changes after the QFileObject is constructed?
I am unsure how this relates to my interface proposal, because it just showsa rename and a move into the class namespace.
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.
Please note that only some mixxx::FileInfo
instances will be converted into location strings. This must only be checked when you try to obtain a location, not in the constructor.
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.
Ok, I think I have got it. You want a class that is not a relative File. Why not just assert this at the constructor and all other non const members. |
I
No. I want a class that reflects the application-level concepts and allows to detect unintended usage, both at compile-time (limited API) and runtime (debug assertions). |
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.
Thank you. We are getting close.
Here some more comments.
src/util/fileinfo.h
Outdated
/// once it has been set, even after the corresponding file has | ||
/// been deleted! A non-empty canonical location is immutable. | ||
/// See also: FileInfoTest | ||
QString freshCanonicalLocation(); |
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.
Is the immutable issue a Mixxx or Qt issue?
Because of the immutable nature the name is misleading. Do we need the function at all?
Maybe something like
ResolveUnresolved()
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 consider QFileInfo a dangerous and confusing class, mainly caused by the (optional, but default) caching behind the scenes that causes side-effects.
This function has been adopted from TrackFile
. It is needed to ensure that previously unavailable locations become accessible when mounting volumes after starting Mixxx. A refresh is only triggered if the first attempt to obtain the canonical location results in an empty string. In this case and if cashing is enabled we need to check the file system again, to ensure that the file is really absent.
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.
The comment already explains the situation in detail and is now verified by an extensive test. I am not investing more time here.
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.
Ok, than this is only a naming issue.
Here:
Line 22 in 1ca77e0
auto canonicalLocation = fileInfo.freshCanonicalLocation(); |
all comments here are out of sight and you have placed another comment to explain the function again.
I think the function should be called like:
canonicalLocationFromCashOrRetryLookUp()
or
canonicalLocationRefresIfEmpty()
less exact but more catchy:
originalCanonicalLocation()
or we may split it up in too calls()
fileinfo.resolveUnresolved()
return fileinfo.canonicaLocation()
We remove the function her and inline it.
The next 2 commits will remove |
src/util/fileinfo.h
Outdated
/// once it has been set, even after the corresponding file has | ||
/// been deleted! A non-empty canonical location is immutable. | ||
/// See also: FileInfoTest | ||
QString freshCanonicalLocation(); |
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.
Ok, than this is only a naming issue.
Here:
Line 22 in 1ca77e0
auto canonicalLocation = fileInfo.freshCanonicalLocation(); |
all comments here are out of sight and you have placed another comment to explain the function again.
I think the function should be called like:
canonicalLocationFromCashOrRetryLookUp()
or
canonicalLocationRefresIfEmpty()
less exact but more catchy:
originalCanonicalLocation()
or we may split it up in too calls()
fileinfo.resolveUnresolved()
return fileinfo.canonicaLocation()
We remove the function her and inline it.
I am not able to change Line 22 in 1ca77e0
|
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.
Thank you. Nice result :-)
Can this be merged after CI has finished? |
Yes. Please wait for CI, I haven't built this locally yet. |
All Green. Thank you. |
Add a wrapper
mixxx::FileInfo
that acts as a shim forQFileInfo
with a reduced API and Mixxx-specific extensions. It introduces the concept of a "location" for permanent, normalized file/directory/symlink references that are used in many places in Mixxx. Supposed to replace bothTrackFile
andMDir
. Please refer to the code for more detailed documentation.This is only the first PR in a row. If you want to see this class in action please check #2656.