Skip to content

Commit

Permalink
Refactor a couple minor parts of validDataPath for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
scribblemaniac committed Jun 6, 2024
1 parent 0c5bb63 commit fb2f6fb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core_lib/src/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,30 @@ QString validateDataPath(QString filePath, QString dataDirPath)
// Recursively resolve symlinks
QString canonicalPath = fi.canonicalFilePath();

// Iterate over parent directories of the file path to see if one of them equals the data directory
QDir dataDir(dataDirPath);
if (dataDir.exists()) dataDir.setPath(dataDir.canonicalPath());
// Resolve symlinks in data dir path so it can be compared against file paths with resolved symlinks
if (dataDir.exists())
{
dataDir.setPath(dataDir.canonicalPath());
}
// Iterate over parent directories of the file path to see if one of them equals the data directory
if (canonicalPath.isEmpty())
{
// File does not exist, use absolute path and attempt to resolve symlinks again for each parent directory
fi.setFile(fi.absoluteFilePath());
QDir ancestor(fi.absoluteFilePath());
while (true) {
if (ancestor == dataDir)
{
// Found data dir in parents
return fi.absoluteFilePath();
}
QDir newAncestor = QFileInfo(ancestor.absolutePath()).dir();
if (newAncestor.exists())
{
// Resolve directory symlinks
newAncestor.setPath(newAncestor.canonicalPath());
}
if (ancestor == dataDir)
{
// Found data dir in parents
return fi.absoluteFilePath();
}
if (ancestor == newAncestor)
{
// Reached root directory without finding data dir
Expand Down

0 comments on commit fb2f6fb

Please sign in to comment.