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

Prefer absolute path resolves #6919

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/commandlineoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ bool CommandlineOptions::Parse() {
QString value = QFile::decodeName(argv_[i]);
QFileInfo file_info(value);
if (file_info.exists())
urls_ << QUrl::fromLocalFile(file_info.canonicalFilePath());
urls_ << QUrl::fromLocalFile(file_info.absoluteFilePath());
else
urls_ << QUrl::fromUserInput(value);
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,11 @@ bool UrlOnSameDriveAsClementine(const QUrl& url) {
if (url.scheme() != "file") return false;

#ifdef Q_OS_WIN
QUrl canUrl =
QUrl::fromLocalFile(QFileInfo(url.toLocalFile()).canonicalFilePath());
QUrl appUrl = QUrl::fromLocalFile(QCoreApplication::applicationDirPath());
if (url.toLocalFile().left(1) == appUrl.toLocalFile().left(1))

if (canUrl.toLocalFile().left(1) == appUrl.toLocalFile().left(1))
return true;
else
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/library/librarybackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ void LibraryBackend::UpdateTotalSongCount() {
}

void LibraryBackend::AddDirectory(const QString& path) {
QString canonical_path = QFileInfo(path).canonicalFilePath();
QString db_path = canonical_path;
QString absolute_path = QFileInfo(path).absoluteFilePath();
QString db_path = absolute_path;

if (Application::kIsPortable && Utilities::UrlOnSameDriveAsClementine(
QUrl::fromLocalFile(canonical_path))) {
QUrl::fromLocalFile(absolute_path))) {
smithjd15 marked this conversation as resolved.
Show resolved Hide resolved
db_path = Utilities::GetRelativePathToClementineBin(db_path);
qLog(Debug) << "db_path" << db_path;
}
Expand All @@ -239,7 +239,7 @@ void LibraryBackend::AddDirectory(const QString& path) {
if (db_->CheckErrors(q)) return;

Directory dir;
dir.path = canonical_path;
dir.path = absolute_path;
dir.id = q.lastInsertId().toInt();

emit DirectoryDiscovered(dir, SubdirectoryList());
Expand Down
2 changes: 1 addition & 1 deletion src/networkremote/incomingdataparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ void IncomingDataParser::AppendFilesToPlaylist(
QDir dir(fi_folder.absoluteFilePath());
for (const auto& file : req_append.files()) {
QFileInfo fi(dir, file.c_str());
if (fi.exists()) urls << QUrl::fromLocalFile(fi.canonicalFilePath());
if (fi.exists()) urls << QUrl::fromLocalFile(fi.absoluteFilePath());
}
if (!urls.isEmpty()) {
MimeData* data = new MimeData;
Expand Down
7 changes: 2 additions & 5 deletions src/playlistparsers/parserbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ void ParserBase::LoadSong(const QString& filename_or_url, qint64 beginning,
// was created on/for, using replace() lets playlists work on any platform.
filename = filename.replace('\\', '/');

// Make the path absolute
// Make the path absolute and clean it
if (!QDir::isAbsolutePath(filename)) {
filename = dir.absoluteFilePath(filename);
}

// Use the canonical path
if (QFile::exists(filename)) {
filename = QFileInfo(filename).canonicalFilePath();
}
filename = QDir::cleanPath(filename);

const QUrl url = QUrl::fromLocalFile(filename);

Expand Down
2 changes: 1 addition & 1 deletion src/playlistparsers/parserbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ParserBase : public QObject {
protected:
// Loads a song. If filename_or_url is a URL (with a scheme other than
// "file") then it is set on the song and the song marked as a stream.
// If it is a filename or a file:// URL then it is made absolute and canonical
// If it is a filename or a file:// URL then it is made absolute and cleaned
// and set as a file:// url on the song. Also sets the song's metadata by
// searching in the Library, or loading from the file as a fallback.
// This function should always be used when loading a playlist.
Expand Down
4 changes: 2 additions & 2 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ void MainWindow::AddFile() {
// Convert to URLs
QList<QUrl> urls;
for (const QString& path : file_names) {
urls << QUrl::fromLocalFile(QFileInfo(path).canonicalFilePath());
urls << QUrl::fromLocalFile(QFileInfo(path).absoluteFilePath());
}

MimeData* data = new MimeData;
Expand All @@ -2205,7 +2205,7 @@ void MainWindow::AddFolder() {
// Add media
MimeData* data = new MimeData;
data->setUrls(QList<QUrl>() << QUrl::fromLocalFile(
QFileInfo(directory).canonicalFilePath()));
QFileInfo(directory).absoluteFilePath()));
AddToPlaylist(data);
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/fileviewlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ QList<QUrl> FileViewList::UrlListFromSelection() const {
if (index.column() == 0)
urls << QUrl::fromLocalFile(static_cast<QFileSystemModel*>(model())
->fileInfo(index)
.canonicalFilePath());
.absoluteFilePath());
}
return urls;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/librarybackend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST_F(LibraryBackendTest, AddDirectory) {
// Check the signal was emitted correctly
ASSERT_EQ(1, spy.count());
Directory dir = spy[0][0].value<Directory>();
EXPECT_EQ(QFileInfo("/tmp").canonicalFilePath(), dir.path);
EXPECT_EQ(QFileInfo("/tmp").absoluteFilePath(), dir.path);
EXPECT_EQ(1, dir.id);
EXPECT_EQ(0, spy[0][1].value<SubdirectoryList>().size());
}
Expand Down