diff --git a/src/library/dao/directorydao.cpp b/src/library/dao/directorydao.cpp index 4ff78062014..4f147f13812 100644 --- a/src/library/dao/directorydao.cpp +++ b/src/library/dao/directorydao.cpp @@ -107,14 +107,15 @@ QSet DirectoryDAO::relocateDirectory(const QString& oldFolder, } FieldEscaper escaper(m_database); - QString startsWithOldFolder = - escaper.escapeString(escaper.escapeStringForLike(oldFolder % '/', '%') + '%'); + // on Windows the absolute path starts with the drive name + // we also need to check for that + QString startsWithOldFolder = escaper.escapeStringForLike(QDir(oldFolder).absolutePath() + "/", '%') + "%"; // Also update information in the track_locations table. This is where mixxx - // gets the location information for a track. + // gets the location information for a track. Put marks around %1 so that this also works on windows query.prepare(QString("SELECT library.id, track_locations.id, track_locations.location " "FROM library INNER JOIN track_locations ON " "track_locations.id = library.location WHERE " - "track_locations.location LIKE %1 ESCAPE '%'") + "track_locations.location LIKE '%1' ESCAPE '%'") .arg(startsWithOldFolder)); if (!query.exec()) { LOG_FAILED_QUERY(query) << "coud not relocate path of tracks"; @@ -144,6 +145,12 @@ QSet DirectoryDAO::relocateDirectory(const QString& oldFolder, } } + query.prepare(QString("SELECT location FROM track_locations")); + query.exec(); + while (query.next()) { + qDebug() << query.value(0).toString(); + } + qDebug() << "Relocated tracks:" << ids.size(); transaction.commit(); diff --git a/src/test/directorydoatest.cpp b/src/test/directorydoatest.cpp index 1ff233e34f3..a5496989a2e 100644 --- a/src/test/directorydoatest.cpp +++ b/src/test/directorydoatest.cpp @@ -133,24 +133,29 @@ TEST_F(DirectoryDAOTest, getDirTest) { TEST_F(DirectoryDAOTest, relocateDirTest) { DirectoryDAO &directoryDao = m_pTrackCollection->getDirectoryDAO(); - directoryDao.addDirectory("/Test"); - directoryDao.addDirectory("/Test2"); + // use a temp dir so that we always use a real existing system path + QString testdir(QDir::tempPath() + "/TestDir"); + QString test2(QDir::tempPath() + "/TestDir2"); + QString testnew(QDir::tempPath() + "/TestDirNew"); + + directoryDao.addDirectory(testdir); + directoryDao.addDirectory(test2); TrackDAO &trackDAO = m_pTrackCollection->getTrackDAO(); // ok now lets create some tracks here trackDAO.addTracksPrepare(); - trackDAO.addTracksAdd(new TrackInfoObject("/Test/a", false), false); - trackDAO.addTracksAdd(new TrackInfoObject("/Test/b", false), false); - trackDAO.addTracksAdd(new TrackInfoObject("/Test2/c", false), false); - trackDAO.addTracksAdd(new TrackInfoObject("/Test2/d", false), false); + trackDAO.addTracksAdd(new TrackInfoObject(testdir + "/a", false), false); + trackDAO.addTracksAdd(new TrackInfoObject(testdir + "/b", false), false); + trackDAO.addTracksAdd(new TrackInfoObject(test2 + "/c", false), false); + trackDAO.addTracksAdd(new TrackInfoObject(test2 + "/d", false), false); trackDAO.addTracksFinish(false); - QSet ids = directoryDao.relocateDirectory("/Test", "/new"); + QSet ids = directoryDao.relocateDirectory(testdir, testnew); EXPECT_EQ(2, ids.size()); QStringList dirs = directoryDao.getDirs(); ASSERT_EQ(2, dirs.size()); qSort(dirs); - EXPECT_THAT(dirs, ElementsAre(QString("/Test2"), QString("/new"))); + EXPECT_THAT(dirs, ElementsAre(test2, testnew)); } } // namespace