diff options
Diffstat (limited to '')
-rw-r--r-- | src/UpdateWalk.cxx (renamed from src/update_walk.c) | 111 |
1 files changed, 57 insertions, 54 deletions
diff --git a/src/update_walk.c b/src/UpdateWalk.cxx index 8554e8f3c..208e6290a 100644 --- a/src/update_walk.c +++ b/src/UpdateWalk.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,22 +18,25 @@ */ #include "config.h" /* must be first for large file support */ -#include "update_walk.h" -#include "update_io.h" -#include "update_db.h" -#include "update_song.h" -#include "update_archive.h" -#include "database.h" -#include "db_lock.h" -#include "exclude.h" -#include "directory.h" +#include "UpdateWalk.hxx" +#include "UpdateIO.hxx" +#include "UpdateDatabase.hxx" +#include "UpdateSong.hxx" +#include "UpdateArchive.hxx" +#include "DatabaseLock.hxx" +#include "DatabaseSimple.hxx" +#include "Directory.hxx" #include "song.h" -#include "playlist_vector.h" +#include "PlaylistVector.hxx" +#include "Mapper.hxx" +#include "ExcludeList.hxx" +#include "conf.h" + +extern "C" { #include "uri.h" -#include "mapper.h" #include "path.h" #include "playlist_list.h" -#include "conf.h" +} #include <glib.h> @@ -84,7 +87,7 @@ update_walk_global_finish(void) } static void -directory_set_stat(struct directory *dir, const struct stat *st) +directory_set_stat(Directory *dir, const struct stat *st) { dir->inode = st->st_ino; dir->device = st->st_dev; @@ -92,16 +95,16 @@ directory_set_stat(struct directory *dir, const struct stat *st) } static void -remove_excluded_from_directory(struct directory *directory, - GSList *exclude_list) +remove_excluded_from_directory(Directory *directory, + const ExcludeList &exclude_list) { db_lock(); - struct directory *child, *n; + Directory *child, *n; directory_for_each_child_safe(child, n, directory) { - char *name_fs = utf8_to_fs_charset(directory_get_name(child)); + char *name_fs = utf8_to_fs_charset(child->GetName()); - if (exclude_list_check(exclude_list, name_fs)) { + if (exclude_list.Check(name_fs)) { delete_directory(child); modified = true; } @@ -114,7 +117,7 @@ remove_excluded_from_directory(struct directory *directory, assert(song->parent == directory); char *name_fs = utf8_to_fs_charset(song->uri); - if (exclude_list_check(exclude_list, name_fs)) { + if (exclude_list.Check(name_fs)) { delete_song(directory, song); modified = true; } @@ -126,9 +129,9 @@ remove_excluded_from_directory(struct directory *directory, } static void -purge_deleted_from_directory(struct directory *directory) +purge_deleted_from_directory(Directory *directory) { - struct directory *child, *n; + Directory *child, *n; directory_for_each_child_safe(child, n, directory) { if (directory_exists(child)) continue; @@ -156,19 +159,21 @@ purge_deleted_from_directory(struct directory *directory) g_free(path); } - struct playlist_metadata *pm, *np; - directory_for_each_playlist_safe(pm, np, directory) { - if (!directory_child_is_regular(directory, pm->name)) { + for (auto i = directory->playlists.begin(), + end = directory->playlists.end(); + i != end;) { + if (!directory_child_is_regular(directory, i->name.c_str())) { db_lock(); - playlist_vector_remove(&directory->playlists, pm->name); + i = directory->playlists.erase(i); db_unlock(); - } + } else + ++i; } } #ifndef G_OS_WIN32 static int -update_directory_stat(struct directory *directory) +update_directory_stat(Directory *directory) { struct stat st; if (stat_directory(directory, &st) < 0) @@ -180,7 +185,7 @@ update_directory_stat(struct directory *directory) #endif static int -find_inode_ancestor(struct directory *parent, ino_t inode, dev_t device) +find_inode_ancestor(Directory *parent, ino_t inode, dev_t device) { #ifndef G_OS_WIN32 while (parent) { @@ -204,23 +209,24 @@ find_inode_ancestor(struct directory *parent, ino_t inode, dev_t device) } static bool -update_playlist_file2(struct directory *directory, +update_playlist_file2(Directory *directory, const char *name, const char *suffix, const struct stat *st) { if (!playlist_suffix_supported(suffix)) return false; + PlaylistInfo pi(name, st->st_mtime); + db_lock(); - if (playlist_vector_update_or_add(&directory->playlists, name, - st->st_mtime)) + if (directory->playlists.UpdateOrInsert(std::move(pi))) modified = true; db_unlock(); return true; } static bool -update_regular_file(struct directory *directory, +update_regular_file(Directory *directory, const char *name, const struct stat *st) { const char *suffix = uri_get_suffix(name); @@ -233,10 +239,10 @@ update_regular_file(struct directory *directory, } static bool -update_directory(struct directory *directory, const struct stat *st); +update_directory(Directory *directory, const struct stat *st); static void -update_directory_child(struct directory *directory, +update_directory_child(Directory *directory, const char *name, const struct stat *st) { assert(strchr(name, '/') == NULL); @@ -248,8 +254,7 @@ update_directory_child(struct directory *directory, return; db_lock(); - struct directory *subdir = - directory_make_child(directory, name); + Directory *subdir = directory->MakeChild(name); db_unlock(); assert(directory == subdir->parent); @@ -275,7 +280,7 @@ static bool skip_path(const char *path) G_GNUC_PURE static bool -skip_symlink(const struct directory *directory, const char *utf8_name) +skip_symlink(const Directory *directory, const char *utf8_name) { #ifndef WIN32 char *path_fs = map_directory_child_fs(directory, utf8_name); @@ -348,7 +353,7 @@ skip_symlink(const struct directory *directory, const char *utf8_name) } static bool -update_directory(struct directory *directory, const struct stat *st) +update_directory(Directory *directory, const struct stat *st) { assert(S_ISDIR(st->st_mode)); @@ -367,12 +372,13 @@ update_directory(struct directory *directory, const struct stat *st) } char *exclude_path_fs = g_build_filename(path_fs, ".mpdignore", NULL); - GSList *exclude_list = exclude_list_load(exclude_path_fs); + ExcludeList exclude_list; + exclude_list.LoadFile(exclude_path_fs); g_free(exclude_path_fs); g_free(path_fs); - if (exclude_list != NULL) + if (!exclude_list.IsEmpty()) remove_excluded_from_directory(directory, exclude_list); purge_deleted_from_directory(directory); @@ -382,8 +388,7 @@ update_directory(struct directory *directory, const struct stat *st) char *utf8; struct stat st2; - if (skip_path(ent->d_name) || - exclude_list_check(exclude_list, ent->d_name)) + if (skip_path(ent->d_name) || exclude_list.Check(ent->d_name)) continue; utf8 = fs_charset_to_utf8(ent->d_name); @@ -404,8 +409,6 @@ update_directory(struct directory *directory, const struct stat *st) g_free(utf8); } - exclude_list_free(exclude_list); - closedir(dir); directory->mtime = st->st_mtime; @@ -413,11 +416,11 @@ update_directory(struct directory *directory, const struct stat *st) return true; } -static struct directory * -directory_make_child_checked(struct directory *parent, const char *name_utf8) +static Directory * +directory_make_child_checked(Directory *parent, const char *name_utf8) { db_lock(); - struct directory *directory = directory_get_child(parent, name_utf8); + Directory *directory = parent->FindChild(name_utf8); db_unlock(); if (directory != NULL) @@ -434,21 +437,21 @@ directory_make_child_checked(struct directory *parent, const char *name_utf8) /* if we're adding directory paths, make sure to delete filenames with potentially the same name */ db_lock(); - struct song *conflicting = directory_get_song(parent, name_utf8); + struct song *conflicting = parent->FindSong(name_utf8); if (conflicting) delete_song(parent, conflicting); - directory = directory_new_child(parent, name_utf8); + directory = parent->CreateChild(name_utf8); db_unlock(); directory_set_stat(directory, &st); return directory; } -static struct directory * +static Directory * directory_make_uri_parent_checked(const char *uri) { - struct directory *directory = db_get_root(); + Directory *directory = db_get_root(); char *duplicated = g_strdup(uri); char *name_utf8 = duplicated, *slash; @@ -472,7 +475,7 @@ directory_make_uri_parent_checked(const char *uri) static void update_uri(const char *uri) { - struct directory *parent = directory_make_uri_parent_checked(uri); + Directory *parent = directory_make_uri_parent_checked(uri); if (parent == NULL) return; @@ -497,7 +500,7 @@ update_walk(const char *path, bool discard) if (path != NULL && !isRootDirectory(path)) { update_uri(path); } else { - struct directory *directory = db_get_root(); + Directory *directory = db_get_root(); struct stat st; if (stat_directory(directory, &st) == 0) |