libsaria: Validate library tracks after updating
I check two things during this step: 1) Does the file still exist? 2) Does the file have the same inode number? If the answer to either of these is "no", then the track is removed from the library.
This commit is contained in:
parent
d4ac6a870f
commit
41ec0b68e0
|
@ -10,6 +10,12 @@ using namespace std;
|
|||
|
||||
list<LibraryPath> path_list;
|
||||
|
||||
static void do_update(list<LibraryPath>::iterator it)
|
||||
{
|
||||
it->update();
|
||||
it->validate();
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -24,7 +30,7 @@ namespace libsaria
|
|||
{
|
||||
list<LibraryPath>::iterator it;
|
||||
for (it = path_list.begin(); it != path_list.end(); it++)
|
||||
it->update();
|
||||
do_update(it);
|
||||
}
|
||||
|
||||
void library::update_path(string dir)
|
||||
|
@ -33,7 +39,7 @@ namespace libsaria
|
|||
for (it == path_list.begin(); it != path_list.end(); it++) {
|
||||
it->get_path();
|
||||
if (it->get_path() == dir)
|
||||
(*it).update();
|
||||
do_update(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,11 @@ class LibraryPath
|
|||
void prepare_for_removal();
|
||||
void get_info(void (*)(struct libsaria::library::PathInfo &));
|
||||
void add_track(string &, sid_t &);
|
||||
void validate_track(libsaria::Track *);
|
||||
void save(OutFile &);
|
||||
|
||||
void update();
|
||||
void validate();
|
||||
};
|
||||
|
||||
#endif /* LIBSARIA_LIBRARY_PATH_H */
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
#include <libsaria/path.h>
|
||||
#include "path.h"
|
||||
|
||||
#define MAX_VALIDATE 250
|
||||
|
||||
class ValidateTask : public IdleTask
|
||||
{
|
||||
private:
|
||||
LibraryPath *lib_path;
|
||||
list<libsaria::Track *> tracks;
|
||||
|
||||
public:
|
||||
ValidateTask(LibraryPath *path)
|
||||
{
|
||||
lib_path = path;
|
||||
}
|
||||
~ValidateTask() {};
|
||||
|
||||
unsigned int add_track(libsaria::Track *track)
|
||||
{
|
||||
tracks.push_back(track);
|
||||
return tracks.size();
|
||||
}
|
||||
|
||||
void run_task();
|
||||
};
|
||||
|
||||
void ValidateTask::run_task()
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
for (it = tracks.begin(); it != tracks.end(); it++) {
|
||||
lib_path->validate_track(*it);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryPath::validate_track(libsaria::Track *track)
|
||||
{
|
||||
string filepath = track->get_filepath();
|
||||
if (lookup_songid(filepath) == track->get_songid())
|
||||
return;
|
||||
track->do_cleanup();
|
||||
delete track;
|
||||
file_list.remove(track);
|
||||
}
|
||||
|
||||
void LibraryPath::validate()
|
||||
{
|
||||
list<libsaria::Track *>::iterator it;
|
||||
ValidateTask *validate = new ValidateTask(this);
|
||||
println("Validating");
|
||||
|
||||
for (it = file_list.begin(); it != file_list.end(); it++) {
|
||||
if (validate->add_track(*it) > MAX_VALIDATE) {
|
||||
validate->queue();
|
||||
validate = new ValidateTask(this);
|
||||
}
|
||||
}
|
||||
validate->queue();
|
||||
}
|
|
@ -45,6 +45,6 @@ sid_t lookup_songid(string &filepath)
|
|||
struct stat stat;
|
||||
int err = lstat(filepath.c_str(), &stat);
|
||||
if (err != 0)
|
||||
return false;
|
||||
return err;
|
||||
return stat.st_ino;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue