static void update_regular_file(struct directory *directory, const char *name, const struct stat *st) { const char *suffix = uri_get_suffix(name); const struct decoder_plugin* plugin; #ifdef ENABLE_ARCHIVE const struct archive_plugin *archive; #endif if (suffix == NULL) return; if ((plugin = decoder_plugin_from_suffix(suffix, false)) != NULL) { struct song* song = songvec_find(&directory->songs, name); if (!(song != NULL && st->st_mtime == song->mtime && !walk_discard) && plugin->container_scan != NULL) { if (update_container_file(directory, name, st, plugin)) { if (song != NULL) delete_song(directory, song); return; } } if (song == NULL) { song = song_file_load(name, directory); if (song == NULL) { g_debug("ignoring unrecognized file %s/%s", directory_get_path(directory), name); return; } songvec_add(&directory->songs, song); modified = true; g_message("added %s/%s", directory_get_path(directory), name); } else if (st->st_mtime != song->mtime || walk_discard) { g_message("updating %s/%s", directory_get_path(directory), name); if (!song_file_update(song)) { g_debug("deleting unrecognized file %s/%s", directory_get_path(directory), name); delete_song(directory, song); } modified = true; } #ifdef ENABLE_ARCHIVE } else if ((archive = archive_plugin_from_suffix(suffix))) { update_archive_file(directory, name, st, archive); #endif } }
static struct directory * directory_make_child_checked(struct directory *parent, const char *path) { struct directory *directory; char *base; struct stat st; struct song *conflicting; directory = directory_get_child(parent, path); if (directory != NULL) return directory; base = g_path_get_basename(path); if (stat_directory_child(parent, base, &st) < 0 || inodeFoundInParent(parent, st.st_ino, st.st_dev)) { g_free(base); return NULL; } /* if we're adding directory paths, make sure to delete filenames with potentially the same name */ conflicting = songvec_find(&parent->songs, base); if (conflicting) delete_song(parent, conflicting); g_free(base); directory = directory_new_child(parent, path); directory_set_stat(directory, &st); return directory; }
static int delete_each_song(struct song *song, G_GNUC_UNUSED void *data) { struct directory *directory = data; assert(song->parent == directory); delete_song(directory, song); return 0; }
directory_for_each_song_safe(song, ns, directory) { assert(song->parent == directory); char *name_fs = utf8_to_fs_charset(song->uri); if (exclude_list_check(exclude_list, name_fs)) { delete_song(directory, song); modified = true; } g_free(name_fs); }
/* passed to songvec_for_each */ static int delete_song_if_removed(struct song *song, void *_data) { struct directory *dir = _data; char *path; struct stat st; if ((path = map_song_fs(song)) == NULL || stat(path, &st) < 0 || !S_ISREG(st.st_mode)) { delete_song(dir, song); modified = true; } g_free(path); return 0; }
static void delete_name_in(struct directory *parent, const char *name) { struct directory *directory = directory_get_child(parent, name); struct song *song = songvec_find(&parent->songs, name); if (directory != NULL) { delete_directory(directory); modified = true; } if (song != NULL) { delete_song(parent, song); modified = true; } }
/* passed to songvec_for_each */ static int delete_song_if_excluded(struct song *song, void *_data) { GSList *exclude_list = _data; char *name_fs; assert(song->parent != NULL); name_fs = utf8_to_fs_charset(song->uri); if (exclude_list_check(exclude_list, name_fs)) { delete_song(song->parent, song); modified = true; } g_free(name_fs); return 0; }
int main() { srand((unsigned) time(NULL)); printf("LIBRARY\n"); printf("=======\n"); add_song(table, "hello", "adele"); add_song(table, "arabella", "arctic monkeys"); add_song(table, "formation", "beyonce"); add_song(table, "sorry", "beyonce"); add_song(table, "cardiac arrest", "bad suns"); add_song(table, "summer", "calvin harris"); add_song(table, "closer", "the chainsmokers"); print_library(table); printf("\n"); printf("searching for \'closer - the chainsmokers\'\n"); printf("===========================================\n"); song_node *findSong = find_song(table, "closer", "the chainsmokers"); if (findSong) printf("found %s - %s\n", findSong->name, findSong->artist); printf("\n"); printf("searching for \'kids - mgmt\'\n"); printf("=============================\n"); song_node *findSong2 = find_song(table, "kids", "mgmt"); if (findSong2) printf("found %s - %s\n", findSong2->name, findSong2->artist); printf("\n"); printf("searching for adele\n"); printf("===================\n"); song_node *findArtist = find_artist(table, "adele"); if (findArtist) print_list(findArtist); printf("\n"); printf("searching for akmu\n"); printf("===================\n"); song_node *findArtist2 = find_artist(table, "akmu"); if (findSong2) print_list(findArtist2); printf("\n"); printf("print \'b\'\n"); printf("===========\n"); print_letter(table, "b"); printf("\n"); printf("print beyonce\n"); printf("=============\n"); print_artist(table, "beyonce"); printf("\n"); printf("print entire library\n"); printf("====================\n"); print_library(table); printf("\n"); printf("shuffle and list three songs\n"); printf("============================\n"); shuffle(table, 3); printf("\n"); printf("deleting a song\n"); printf("===============\n"); printf("deleting \'summer - calvin harris\'\n"); delete_song(table, "summer", "calvin harris"); print_library(table); printf("\n"); printf("deleting everything (FAULTY)\n"); printf("============================\n"); delete_all(table); print_library(table); }
static void update_song_file2(struct directory *directory, const char *name, const struct stat *st, const struct decoder_plugin *plugin) { db_lock(); struct song *song = directory_get_song(directory, name); db_unlock(); if (!directory_child_access(directory, name, R_OK)) { g_warning("no read permissions on %s/%s", directory_get_path(directory), name); if (song != NULL) { db_lock(); delete_song(directory, song); db_unlock(); } return; } if (!(song != NULL && st->st_mtime == song->mtime && !walk_discard) && update_container_file(directory, name, st, plugin)) { if (song != NULL) { db_lock(); delete_song(directory, song); db_unlock(); } return; } if (song == NULL) { g_debug("reading %s/%s", directory_get_path(directory), name); song = song_file_load(name, directory); if (song == NULL) { g_debug("ignoring unrecognized file %s/%s", directory_get_path(directory), name); return; } db_lock(); directory_add_song(directory, song); db_unlock(); modified = true; g_message("added %s/%s", directory_get_path(directory), name); } else if (st->st_mtime != song->mtime || walk_discard) { g_message("updating %s/%s", directory_get_path(directory), name); if (!song_file_update(song)) { g_debug("deleting unrecognized file %s/%s", directory_get_path(directory), name); db_lock(); delete_song(directory, song); db_unlock(); } modified = true; } }
/* Parameters: library: Pointer to Start of Library Array song_artist: Song Artist song_name: Song Name */ void delete_song_from_library(struct song_node* *library, char *song_artist, char *song_name) { library[ letter_to_index(song_artist) ] = delete_song( library[letter_to_index(song_artist)], song_artist, song_name); }