Skip to content

Commit

Permalink
Use Canonical Paths for Relative Paths Calculations (LMMS#4211)
Browse files Browse the repository at this point in the history
Fix redundant path elements
Closes LMMS#4173
  • Loading branch information
tresf committed Mar 4, 2018
1 parent bd45599 commit 0c756ef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/ConfigManager.cpp
Expand Up @@ -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() );
}


Expand Down
3 changes: 2 additions & 1 deletion src/core/SampleBuffer.cpp
Expand Up @@ -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/"
Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/RelativePathsTest.cpp
Expand Up @@ -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;

Expand Down

0 comments on commit 0c756ef

Please sign in to comment.