Skip to content
Permalink
Browse files

Use Canonical Paths for Relative Paths Calculations (#4211)

Fix redundant path elements
Closes #4173
  • Loading branch information...
tresf committed Mar 4, 2018
1 parent 926b654 commit 1d63bd3b4e1077200498533e2a4863d1fca3dd4b
Showing with 7 additions and 3 deletions.
  1. +2 −2 src/core/ConfigManager.cpp
  2. +2 −1 src/core/SampleBuffer.cpp
  3. +3 −0 tests/src/core/RelativePathsTest.cpp
@@ -225,9 +225,9 @@ bool ConfigManager::hasWorkingDir() const
}


void ConfigManager::setWorkingDir( const QString & _wd )
void ConfigManager::setWorkingDir( const QString & wd )
{
m_workingDir = ensureTrailingSlash( _wd );
m_workingDir = ensureTrailingSlash( QFileInfo( wd ).canonicalFilePath() );
}


@@ -1415,7 +1415,8 @@ QString SampleBuffer::tryToMakeRelative( const QString & file )
{
if( QFileInfo( file ).isRelative() == false )
{
QString f = QString( file ).replace( QDir::separator(), '/' );
// Normalize the path
QString f = QFileInfo( file ).canonicalFilePath().replace( QDir::separator(), '/' );

// First, look in factory samples
// Isolate "samples/" from "data:/samples/"
@@ -40,8 +40,11 @@ private slots:

QString absPath = fi.absoluteFilePath();
QString relPath = "drums/kick01.ogg";
QString fuzPath = absPath;
fuzPath.replace(relPath, "drums/.///kick01.ogg");
QCOMPARE(SampleBuffer::tryToMakeRelative(absPath), relPath);
QCOMPARE(SampleBuffer::tryToMakeAbsolute(relPath), absPath);
QCOMPARE(SampleBuffer::tryToMakeRelative(fuzPath), relPath);
}
} RelativePathTests;

0 comments on commit 1d63bd3

Please sign in to comment.
You can’t perform that action at this time.