Add more robust subdirectory detection in LibraryWatcher.

This commit is contained in:
John Maguire 2012-01-05 15:56:46 +00:00
parent 97f3885f58
commit 761737eb4d
3 changed files with 20 additions and 18 deletions

View File

@ -46,6 +46,9 @@ void MacFSListener::EventStreamCallback(
for (int i = 0; i < num_events; ++i) {
QString path = QString::fromUtf8(paths[i]);
qLog(Debug) << "Something changed at:" << path;
if (path.endsWith('/')) {
path.chop(1);
}
emit me->PathChanged(path);
}
}

View File

@ -115,7 +115,7 @@ LibraryWatcher::ScanTransaction::~ScanTransaction() {
if (watcher_->monitor_) {
// Watch the new subdirectories
foreach (const Subdirectory& subdir, new_subdirs) {
watcher_->AddWatch(subdir.path);
watcher_->AddWatch(watcher_->watched_dirs_[dir_], subdir.path);
}
}
}
@ -207,7 +207,7 @@ void LibraryWatcher::AddDirectory(const Directory& dir, const SubdirectoryList&
ScanSubdirectory(subdir.path, subdir, &transaction);
if (monitor_)
AddWatch(subdir.path);
AddWatch(data, subdir.path);
}
}
@ -546,13 +546,14 @@ uint LibraryWatcher::GetMtimeForCue(const QString& cue_path) {
: 0;
}
void LibraryWatcher::AddWatch(const QString& path) {
void LibraryWatcher::AddWatch(DirData dir, const QString& path) {
if (!QFile::exists(path))
return;
connect(fs_watcher_, SIGNAL(PathChanged(const QString&)), this,
SLOT(DirectoryChanged(const QString&)), Qt::UniqueConnection);
fs_watcher_->AddPath(path);
subdir_mapping_[path] = dir;
}
void LibraryWatcher::RemoveDirectory(const Directory& dir) {
@ -573,11 +574,11 @@ bool LibraryWatcher::FindSongByPath(const SongList& list, const QString& path, S
void LibraryWatcher::DirectoryChanged(const QString &subdir) {
// Find what dir it was in
Directory dir;
foreach (const DirData& info, watched_dirs_) {
if (subdir.startsWith(info.dir.path))
dir = info.dir;
QHash<QString, DirData>::const_iterator it = subdir_mapping_.constFind(subdir);
if (it == subdir_mapping_.constEnd()) {
return;
}
Directory dir = it->dir;
qLog(Debug) << "Subdir" << subdir << "changed under directory" << dir.path << "id" << dir.id;
@ -700,7 +701,7 @@ void LibraryWatcher::ReloadSettings() {
foreach (const DirData& data, watched_dirs_.values()) {
SubdirectoryList subdirs = backend_->SubdirsInDirectory(data.dir.id);
foreach (const Subdirectory& subdir, subdirs) {
AddWatch(subdir.path);
AddWatch(data, subdir.path);
}
}
}

View File

@ -21,6 +21,7 @@
#include "directory.h"
#include "core/song.h"
#include <QHash>
#include <QObject>
#include <QStringList>
#include <QMap>
@ -140,13 +141,18 @@ class LibraryWatcher : public QObject {
ScanTransaction* t, bool force_noincremental = false);
private:
// One of these gets stored for each Directory we're watching
struct DirData {
Directory dir;
};
static bool FindSongByPath(const SongList& list, const QString& path, Song* out);
inline static QString NoExtensionPart( const QString &fileName );
inline static QString ExtensionPart( const QString &fileName );
inline static QString DirectoryPart( const QString &fileName );
QString PickBestImage(const QStringList& images);
QString ImageForSong(const QString& path, QMap<QString, QStringList>& album_art);
void AddWatch(const QString& path);
void AddWatch(DirData dir, const QString& path);
uint GetMtimeForCue(const QString& cue_path);
void PerformScan(bool incremental, bool ignore_mtimes);
@ -171,16 +177,12 @@ class LibraryWatcher : public QObject {
const QString& matching_cue, QSet<QString>* cues_processed);
private:
// One of these gets stored for each Directory we're watching
struct DirData {
Directory dir;
};
LibraryBackend* backend_;
TaskManager* task_manager_;
QString device_name_;
FileSystemWatcherInterface* fs_watcher_;
QHash<QString, DirData> subdir_mapping_;
/* A list of words use to try to identify the (likely) best image
* found in an directory to use as cover artwork.
@ -203,10 +205,6 @@ class LibraryWatcher : public QObject {
CueParser* cue_parser_;
static QStringList sValidImages;
#ifdef Q_OS_DARWIN
static const int kMaxWatches = 100;
#endif
};
inline QString LibraryWatcher::NoExtensionPart( const QString &fileName ) {