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

Replace MDir with mixxx::FileInfo/FileAccess #3744

Merged
merged 8 commits into from
Apr 2, 2021
Merged

Replace MDir with mixxx::FileInfo/FileAccess #3744

merged 8 commits into from
Apr 2, 2021

Conversation

uklotzde
Copy link
Contributor

@uklotzde uklotzde commented Mar 23, 2021

Next step towards replacing TrackFile and a more cohesive handling of sandboxing:

  • mixxx::FileAccess = mixxx::FileInfo + SecurityTokenPointer
  • Improve management of library root directories
    • Overhaul DirectoryDAO
    • Move access to DirectoryDAO from Library into TrackCollection which owns DirectoryDAO
    • Improve detection of parent/child directories based on location paths provided by mixxx::FileInfo
  • Remove MDir

The next PR will improve sandboxing based on this foundation and finally remove TrackFile.

Unfortunately I am unable to split these changes into even smaller change sets afterwards. There is also some overlap between the current and the following changes. Just trying to keep it as small as possible after holding those PRs back for such a long time. For all new code I try to submit tiny PRs, one at a time.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have test tested this on Ubuntu and it still works. Thank you.

How do want to proceeded with the MacOS tests. Can we take the risk an and merge it without?

@@ -49,7 +49,7 @@ class BrowseThread : public QThread {

// You must hold m_path_mutex to touch m_path or m_model_observer
QMutex m_path_mutex;
MDir m_path;
mixxx::FileAccess m_path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks confusing, because one may think this refrences a file, but it is a directory. Do you have an idea to improve the naming?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QFileInfo also could reference everything file/dir/symlink, we follow it. This naming is at least consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know. Unfortunately this makes the usage code harder to read.
Can we rename m_pPath to something more specific, to improve the situation?

Do we use the security tokens for single files? Looking into the implementation, there are different call stacks for files and directories. Maybe we can inherit a file and a dir version and accept some code duplications for some extra safety

What are your future plans with this?

Copy link
Member

@daschuer daschuer Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nothing that blocks this PR ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just noticed this. The special QDir overloads in Sandbox are not needed an can be removed. We can switch entirely to mixxx::FileInfo. Only the browse view seems to be affected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inheriting does not make sense for this use case. You can only know at runtime if a file system reference is a file, directory, or symlink.

The equivalent of QFileInfo in Rust would be std::path::Path/std::path::PathBuf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that Sandbox handles directories differently. Converting back to draft until I have checked that nothing got mixed up here. Thanks for reviewing so far.

src/library/browse/foldertreemodel.cpp Show resolved Hide resolved
->getDirectoryDAO()
.getDirs();
for (const auto& dir : dirs) {
const auto dirInfos = m_pTrackCollectionManager->internalCollection()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const auto dirInfos = m_pTrackCollectionManager->internalCollection()
const QList<mixxx::FileInfo> dirInfos = m_pTrackCollectionManager->internalCollection()

We don`t have a DirInfos class or such. That's why I think we we need to be here more verbose here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check consider this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have explicitly added the type for the loop variable (even though I don't consider it as relevant and everything was declared as auto before). It doesn't matter that the container is a QList, we just iterate through it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uklotzde uklotzde marked this pull request as draft March 25, 2021 10:02
@uklotzde uklotzde changed the title Replace MDir with mixxx::FileInfo/FileAccess [WiP] Replace MDir with mixxx::FileInfo/FileAccess Mar 25, 2021
@uklotzde
Copy link
Contributor Author

@Holzhaus I needed platform-specific defines in tests: bf44876

@uklotzde
Copy link
Contributor Author

Now with tests for directory links (not on Windows) and explicit distinction of directory vs. file sandboxing. Just to be sure that we don't break anything. The code in Sandbox still contains some redundancies and I am not entirely sure that it is correct. But that didn't change and everything should work as before.

@uklotzde uklotzde changed the title [WiP] Replace MDir with mixxx::FileInfo/FileAccess Replace MDir with mixxx::FileInfo/FileAccess Mar 25, 2021
@uklotzde uklotzde marked this pull request as ready for review March 25, 2021 22:25
Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine for me, tests pass.

src/util/fileaccess.h Outdated Show resolved Hide resolved
@Holzhaus Holzhaus requested a review from daschuer March 28, 2021 10:28
@Holzhaus
Copy link
Member

@daschuer Can I hit merge or are you planning to review this again?

@daschuer
Copy link
Member

If you have reviewed and tested it, it should be sufficient, however a test on a mac would be nice.
Or did we test this already on a mac?

@Holzhaus
Copy link
Member

No, maybe @Be-ing can help out.

@@ -49,7 +49,7 @@ class BrowseThread : public QThread {

// You must hold m_path_mutex to touch m_path or m_model_observer
QMutex m_path_mutex;
MDir m_path;
mixxx::FileAccess m_path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this:

Suggested change
mixxx::FileAccess m_path;
mixxx::FileAccess m_dir;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to introduce many unrelated changes just by renaming things. And I especially try to avoid touching this browse stuff.

Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, thank you!

@Holzhaus Holzhaus merged commit fb747b6 into mixxxdj:main Apr 2, 2021
@uklotzde uklotzde deleted the fileaccess branch April 2, 2021 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants