Store port number in cache filename, to handle cases where more than 1 MPD is running on a host
This commit is contained in:
@@ -65,6 +65,8 @@
|
||||
41. Fix Qt5 segfault on exit, due to static QIcons being destructed.
|
||||
42. Work-around Qt5 bug where toolbuttons (usually with menus) stay in the
|
||||
mouse-over state.
|
||||
43. Add port number to library cache filename, to cater for scenarios where
|
||||
there is more than 1 server on the same host.
|
||||
|
||||
1.0.3
|
||||
-----
|
||||
|
||||
@@ -75,13 +75,19 @@ const QLatin1String MusicLibraryModel::constLibraryCache("library/");
|
||||
const QLatin1String MusicLibraryModel::constLibraryExt(".xml");
|
||||
const QLatin1String MusicLibraryModel::constLibraryCompressedExt(".xml.gz");
|
||||
|
||||
static const QString cacheFileName()
|
||||
static QString cacheFileName(const MPDConnectionDetails &details, bool withPort=true)
|
||||
{
|
||||
QString fileName=MPDConnection::self()->getDetails().hostname+MusicLibraryModel::constLibraryCompressedExt;
|
||||
QString fileName=(withPort && !details.isLocal() ? details.hostname+'_'+QString::number(details.port) : details.hostname)
|
||||
+MusicLibraryModel::constLibraryCompressedExt;
|
||||
fileName.replace('/', '_');
|
||||
return Utils::cacheDir(MusicLibraryModel::constLibraryCache)+fileName;
|
||||
}
|
||||
|
||||
static QString cacheFileName(bool withPort=true)
|
||||
{
|
||||
return cacheFileName(MPDConnection::self()->getDetails(), withPort);
|
||||
}
|
||||
|
||||
void MusicLibraryModel::convertCache(const QString &compressedName)
|
||||
{
|
||||
QString prev=compressedName;
|
||||
@@ -110,9 +116,12 @@ void MusicLibraryModel::cleanCache()
|
||||
QSet<QString> existing;
|
||||
QList<MPDConnectionDetails> connections=Settings::self()->allConnections();
|
||||
foreach (const MPDConnectionDetails &conn, connections) {
|
||||
QString fileName=conn.hostname;
|
||||
fileName.replace('/', '_');
|
||||
existing.insert(fileName+constLibraryCompressedExt);
|
||||
QString withPort=cacheFileName(conn);
|
||||
QString withoutPort=cacheFileName(conn, false);
|
||||
if (withPort!=withoutPort) {
|
||||
existing.insert(withoutPort);
|
||||
}
|
||||
existing.insert(withPort);
|
||||
}
|
||||
QDir dir(Utils::cacheDir(constLibraryCache));
|
||||
QFileInfoList files=dir.entryInfoList(QStringList() << "*"+constLibraryExt << "*"+constLibraryCompressedExt, QDir::Files);
|
||||
@@ -688,6 +697,12 @@ void MusicLibraryModel::removeCache()
|
||||
QFile::remove(cacheFile);
|
||||
}
|
||||
|
||||
// Remove old (non-compressed) cache file as well...
|
||||
QString cacheFileWithoutPort(cacheFileName(false));
|
||||
if (cacheFileWithoutPort!=cacheFile && QFile::exists(cacheFileWithoutPort)) {
|
||||
QFile::remove(cacheFileWithoutPort);
|
||||
}
|
||||
|
||||
// Remove old (non-compressed) cache file as well...
|
||||
QString oldCache=cacheFile;
|
||||
oldCache.replace(constLibraryCompressedExt, constLibraryExt);
|
||||
@@ -975,6 +990,13 @@ void MusicLibraryModel::toXML(const MusicLibraryItemRoot *root, const QDateTime
|
||||
*/
|
||||
bool MusicLibraryModel::fromXML()
|
||||
{
|
||||
// If socket conneciton used, then check if cahce file has port number...
|
||||
QString withPort=cacheFileName();
|
||||
QString withoutPort=cacheFileName(false);
|
||||
if (withPort!=withoutPort && QFile::exists(withoutPort) && !QFile::exists(withPort)) {
|
||||
QFile::rename(withoutPort, withPort);
|
||||
}
|
||||
|
||||
convertCache(cacheFileName());
|
||||
MusicLibraryItemRoot *root=new MusicLibraryItemRoot;
|
||||
quint32 date=root->fromXML(cacheFileName(), MPDStats::self()->dbUpdate());
|
||||
|
||||
Reference in New Issue
Block a user