Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool ConfigManager::hasWorkingDir() const

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


Expand Down
2 changes: 1 addition & 1 deletion src/core/SampleBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ QString SampleBuffer::tryToMakeRelative( const QString & file )
if( QFileInfo( file ).isRelative() == false )
{
// Normalize the path
QString f = QFileInfo( file ).canonicalFilePath().replace( QDir::separator(), '/' );
QString f( QDir::cleanPath( file ).replace( QDir::separator(), '/' ) );
Copy link
Member

Choose a reason for hiding this comment

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

Just a reminder, .replace( QDir::separator(), '/' ) can be removed when Qt4 support is completely dropped later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just a reminder, .replace( QDir::separator(), '/' ) can be removed when Qt4 support is completely dropped later.

Good to know... can you elaborate? Is the default behavior to use / in Qt5? If so where is this documented and is this across all Qt functions?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Documented in http://doc.qt.io/qt-5/qdir.html#cleanPath

Yeah that doesn't have any "since qt5" warnings, so I just thought it was an example. Thanks for clarification.

Copy link
Member Author

@tresf tresf Mar 23, 2018

Choose a reason for hiding this comment

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

For comparison:

4.8:

Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path, path.

5.x:

Returns path with directory separators normalized (converted to "/") and redundant ones removed, and "."s and ".."s resolved (as far as possible).

So I hope you understand my hesitation. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm.... Here's the code for posterity...

static QString qt_cleanPath(const QString &path, bool *ok)
--
{
if (path.isEmpty())
return path;
QString name = path;
QChar dir_separator = QDir::separator();
if (dir_separator != QLatin1Char('/'))
name.replace(dir_separator, QLatin1Char('/'));
 
QString ret = qt_normalizePathSegments(name, OSSupportsUncPaths, ok);
 
// Strip away last slash except for root directories
if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) {
#if defined (Q_OS_WIN)
#  if defined(Q_OS_WINRT)
if (!((ret.length() == 3 \|\| ret.length() == QDir::rootPath().length()) && ret.at(1) == QLatin1Char(':')))
#  else
if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':')))
#  endif
#endif
ret.chop(1);
}
 
return ret;
}

The only function that seems like it would touch \\ would be the qt_normalizePathSegments.cpp, but that specifically says in the source

// This method is shared with QUrl, so it doesn't deal with QDir::separator() ...

I guess I'll take your word for it. :)

Copy link
Member

Choose a reason for hiding this comment

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

@tresf it's about a third of the way down in that qt_cleanPath function:

name.replace(dir_separator, QLatin1Char('/'));

How do you feel about adding a short code comment explaining why we run .replace( QDir::separator(), '/' ) (maybe just linking to #4271 ) so that nobody else accidentally removes it, forgetting about Qt4 support?

Copy link
Member

Choose a reason for hiding this comment

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

Looking into Qt4's code, I found that even Qt 4.0 has the replacement logic. So we can safely remove that.

Copy link
Member Author

Choose a reason for hiding this comment

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

dir_separator, got it! Missed that one. Thanks!

So we can safely remove that.

Agreed. Will do.


// First, look in factory samples
// Isolate "samples/" from "data:/samples/"
Expand Down