library: Implement library path validation
I scan the track database and remove files that no longer exist. I don't yet add in new tracks found in the directories. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
e0f28cb366
commit
b759b9743d
|
@ -235,7 +235,7 @@ void library :: Track :: print()
|
||||||
/*
|
/*
|
||||||
* Internal library functions
|
* Internal library functions
|
||||||
*/
|
*/
|
||||||
static void do_update(unsigned int, const std :: string &);
|
static void do_scan_path(unsigned int, const std :: string &);
|
||||||
|
|
||||||
static void read_tags(unsigned int lib_id, const std :: string &path)
|
static void read_tags(unsigned int lib_id, const std :: string &path)
|
||||||
{
|
{
|
||||||
|
@ -266,7 +266,7 @@ static void process_path(unsigned int lib_id, const std :: string &dir,
|
||||||
std :: string path = dir + "/" + name;
|
std :: string path = dir + "/" + name;
|
||||||
|
|
||||||
if (g_file_test(path.c_str(), G_FILE_TEST_IS_DIR) == true)
|
if (g_file_test(path.c_str(), G_FILE_TEST_IS_DIR) == true)
|
||||||
do_update(lib_id, path);
|
do_scan_path(lib_id, path);
|
||||||
else
|
else
|
||||||
read_tags(lib_id, path);
|
read_tags(lib_id, path);
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ static void save_all_dbs()
|
||||||
track_db.save();
|
track_db.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_update(unsigned int lib_id, const std :: string &path)
|
static void do_scan_path(unsigned int lib_id, const std :: string &path)
|
||||||
{
|
{
|
||||||
GDir *dir;
|
GDir *dir;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -296,6 +296,31 @@ static void do_update(unsigned int lib_id, const std :: string &path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void do_validate_library(unsigned int lib_id)
|
||||||
|
{
|
||||||
|
std :: string path;
|
||||||
|
|
||||||
|
if (track_db.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (unsigned int i = track_db.first(); i <= track_db.last(); i = track_db.next(i)) {
|
||||||
|
if (track_db[i].library_id != lib_id)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
path = library_db[lib_id].root_path + "/" + track_db[i].filepath;
|
||||||
|
if (g_file_test(path.c_str(), G_FILE_TEST_EXISTS) == false) {
|
||||||
|
dprint("Removing file: %s\n", path.c_str());
|
||||||
|
track_db.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void do_update_library(unsigned int lib_id)
|
||||||
|
{
|
||||||
|
do_validate_library(lib_id);
|
||||||
|
do_scan_path(lib_id, library_db[lib_id].root_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -331,7 +356,7 @@ void library :: update_path(unsigned int id)
|
||||||
return;
|
return;
|
||||||
if (library_db[id].valid == false)
|
if (library_db[id].valid == false)
|
||||||
return;
|
return;
|
||||||
do_update(id, library_db[id].root_path);
|
do_update_library(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool library :: lookup(unsigned int id, library :: Song *song)
|
bool library :: lookup(unsigned int id, library :: Song *song)
|
||||||
|
|
|
@ -137,6 +137,27 @@ void test_5()
|
||||||
test_lookup("5d", 42, true);
|
test_lookup("5d", 42, true);
|
||||||
/* Lookup beyond db */
|
/* Lookup beyond db */
|
||||||
test_lookup("5e", 100000, false);
|
test_lookup("5e", 100000, false);
|
||||||
|
print("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test validation code */
|
||||||
|
void test_6()
|
||||||
|
{
|
||||||
|
library :: reset();
|
||||||
|
|
||||||
|
test_add_dir("6a", "/tmp/library/0", true);
|
||||||
|
print("\n");
|
||||||
|
|
||||||
|
print("6b: Updating library 0 (nothing should change)\n");
|
||||||
|
library :: update_path(0);
|
||||||
|
library :: print_db(library :: DB_TRACK);
|
||||||
|
print("\n");
|
||||||
|
|
||||||
|
print("6c: Delete /tmp/library/0/Artist 2\n");
|
||||||
|
system("rm -rf /tmp/library/0/Artist\\ 2/");
|
||||||
|
library :: update_path(0);
|
||||||
|
library :: print_db(library :: DB_TRACK);
|
||||||
|
print("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -148,6 +169,7 @@ int main(int argc, char **argv)
|
||||||
test_2();
|
test_2();
|
||||||
test_3();
|
test_3();
|
||||||
test_4();
|
test_4();
|
||||||
//test_5();
|
test_5();
|
||||||
|
test_6();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user