bool update_walk(const char *path, bool discard) { walk_discard = discard; modified = false; if (path != NULL && !isRootDirectory(path)) { updatePath(path); } else { struct directory *directory = db_get_root(); struct stat st; if (stat_directory(directory, &st) == 0) updateDirectory(directory, &st); } return modified; }
static struct directory * addParentPathToDB(const char *utf8path) { struct directory *directory = db_get_root(); char *duplicated = g_strdup(utf8path); char *slash = duplicated; while ((slash = strchr(slash, '/')) != NULL) { *slash = 0; directory = directory_make_child_checked(directory, duplicated); if (directory == NULL || slash == NULL) break; *slash++ = '/'; } g_free(duplicated); return directory; }
struct song * playlist_check_translate_song(struct song *song, const char *base_uri) { struct song *dest; if (song_in_database(song)) /* already ok */ return song; char *uri = song->uri; if (uri_has_scheme(uri)) { if (uri_supported_scheme(uri)) /* valid remote song */ return song; else { /* unsupported remote song */ song_free(song); return NULL; } } if (g_path_is_absolute(uri)) { /* XXX fs_charset vs utf8? */ char *prefix = base_uri != NULL ? map_uri_fs(base_uri) : map_directory_fs(db_get_root()); if (prefix == NULL || !g_str_has_prefix(uri, prefix) || uri[strlen(prefix)] != '/') { /* local files must be relative to the music directory */ g_free(prefix); song_free(song); return NULL; } uri += strlen(prefix) + 1; g_free(prefix); } if (base_uri != NULL) uri = g_build_filename(base_uri, uri, NULL); else uri = g_strdup(uri); if (uri_has_scheme(base_uri)) { dest = song_remote_new(uri); g_free(uri); } else { dest = db_get_song(uri); g_free(uri); if (dest == NULL) { /* not found in database */ song_free(song); return dest; } } dest = apply_song_metadata(dest, song); song_free(song); return dest; }