diff --git a/playlist.c b/playlist.c index 6658c15a44..e1ce473fd7 100644 --- a/playlist.c +++ b/playlist.c @@ -255,53 +255,53 @@ static void playlist_path_id_free(playlist_path_id_t *path_id) static playlist_path_id_t *playlist_path_id_init(const char *path) { - playlist_path_id_t *path_id = (playlist_path_id_t*)malloc(sizeof(*path_id)); - const char *archive_delim = NULL; - char real_path[PATH_MAX_LENGTH]; + playlist_path_id_t *path_id = (playlist_path_id_t*)malloc(sizeof(*path_id)); if (!path_id) return NULL; - path_id->real_path = NULL; - path_id->archive_path = NULL; - path_id->real_path_hash = 0; - path_id->archive_path_hash = 0; - path_id->is_archive = false; - path_id->is_in_archive = false; + path_id->real_path = NULL; + path_id->archive_path = NULL; + path_id->real_path_hash = 0; + path_id->archive_path_hash = 0; + path_id->is_archive = false; + path_id->is_in_archive = false; - if (string_is_empty(path)) - return path_id; - - /* Get real path */ - strlcpy(real_path, path, sizeof(real_path)); - playlist_resolve_path(PLAYLIST_SAVE, false, real_path, - sizeof(real_path)); - - path_id->real_path = strdup(real_path); - path_id->real_path_hash = playlist_path_hash(real_path); - - /* Check archive status */ - path_id->is_archive = path_is_compressed_file(real_path); - archive_delim = path_get_archive_delim(real_path); - - /* If path refers to a file inside an archive, - * extract the path of the parent archive */ - if (archive_delim) + if (!string_is_empty(path)) { - char archive_path[PATH_MAX_LENGTH]; - size_t len = (1 + archive_delim - real_path); - if (len >= PATH_MAX_LENGTH) - len = PATH_MAX_LENGTH; - strlcpy(archive_path, real_path, len * sizeof(char)); + char real_path[PATH_MAX_LENGTH]; + const char *archive_delim = NULL; + /* Get real path */ + strlcpy(real_path, path, sizeof(real_path)); + playlist_resolve_path(PLAYLIST_SAVE, false, real_path, + sizeof(real_path)); - path_id->archive_path = strdup(archive_path); - path_id->archive_path_hash = playlist_path_hash(archive_path); - path_id->is_in_archive = true; - } - else if (path_id->is_archive) - { - path_id->archive_path = path_id->real_path; - path_id->archive_path_hash = path_id->real_path_hash; + path_id->real_path = strdup(real_path); + path_id->real_path_hash = playlist_path_hash(real_path); + + /* Check archive status */ + path_id->is_archive = path_is_compressed_file(real_path); + archive_delim = path_get_archive_delim(real_path); + + /* If path refers to a file inside an archive, + * extract the path of the parent archive */ + if (archive_delim) + { + char archive_path[PATH_MAX_LENGTH]; + size_t len = (1 + archive_delim - real_path); + if (len >= PATH_MAX_LENGTH) + len = PATH_MAX_LENGTH; + strlcpy(archive_path, real_path, len * sizeof(char)); + + path_id->archive_path = strdup(archive_path); + path_id->archive_path_hash = playlist_path_hash(archive_path); + path_id->is_in_archive = true; + } + else if (path_id->is_archive) + { + path_id->archive_path = path_id->real_path; + path_id->archive_path_hash = path_id->real_path_hash; + } } return path_id; @@ -420,8 +420,7 @@ static bool playlist_path_matches_entry(playlist_path_id_t *path_id, /* Check whether entry contains a path ID cache */ if (!entry->path_id) { - entry->path_id = playlist_path_id_init(entry->path); - if (!entry->path_id) + if (!(entry->path_id = playlist_path_id_init(entry->path))) return false; } @@ -3055,10 +3054,10 @@ bool playlist_entries_are_equal( if (!entry_a || !entry_b || !config) return false; - if (string_is_empty(entry_a->path) && - string_is_empty(entry_a->core_path) && - string_is_empty(entry_b->path) && - string_is_empty(entry_b->core_path)) + if ( string_is_empty(entry_a->path) + && string_is_empty(entry_a->core_path) + && string_is_empty(entry_b->path) + && string_is_empty(entry_b->core_path)) return true; /* Check content paths */ @@ -3253,7 +3252,8 @@ bool playlist_scan_refresh_enabled(playlist_t *playlist) return !string_is_empty(playlist->scan_record.content_dir); } -void playlist_set_default_core_path(playlist_t *playlist, const char *core_path) +void playlist_set_default_core_path(playlist_t *playlist, + const char *core_path) { char real_core_path[PATH_MAX_LENGTH]; @@ -3274,8 +3274,8 @@ void playlist_set_default_core_path(playlist_t *playlist, const char *core_path) { if (playlist->default_core_path) free(playlist->default_core_path); - playlist->default_core_path = strdup(real_core_path); - playlist->modified = true; + playlist->default_core_path = strdup(real_core_path); + playlist->modified = true; } } @@ -3289,8 +3289,8 @@ void playlist_set_default_core_name( { if (playlist->default_core_name) free(playlist->default_core_name); - playlist->default_core_name = strdup(core_name); - playlist->modified = true; + playlist->default_core_name = strdup(core_name); + playlist->modified = true; } } @@ -3300,7 +3300,7 @@ void playlist_set_label_display_mode(playlist_t *playlist, if (playlist && playlist->label_display_mode != label_display_mode) { playlist->label_display_mode = label_display_mode; - playlist->modified = true; + playlist->modified = true; } } @@ -3379,9 +3379,9 @@ void playlist_set_scan_file_exts(playlist_t *playlist, const char *file_exts) /* Check whether string value has changed * (note that a NULL or empty argument will * unset the playlist value) */ - if (( current_string_empty && !new_string_empty) || - (!current_string_empty && new_string_empty) || - !string_is_equal(playlist->scan_record.file_exts, file_exts)) + if ( ( current_string_empty && !new_string_empty) + || (!current_string_empty && new_string_empty) + || !string_is_equal(playlist->scan_record.file_exts, file_exts)) playlist->modified = true; else return; /* Strings are identical; do nothing */ @@ -3459,13 +3459,12 @@ void playlist_set_scan_filter_dat_content(playlist_t *playlist, bool filter_dat_ * other than DETECT) */ bool playlist_entry_has_core(const struct playlist_entry *entry) { - if (!entry || - string_is_empty(entry->core_path) || - string_is_empty(entry->core_name) || - string_is_equal(entry->core_path, FILE_PATH_DETECT) || - string_is_equal(entry->core_name, FILE_PATH_DETECT)) + if ( !entry + || string_is_empty(entry->core_path) + || string_is_empty(entry->core_name) + || string_is_equal(entry->core_path, FILE_PATH_DETECT) + || string_is_equal(entry->core_name, FILE_PATH_DETECT)) return false; - return true; } @@ -3495,11 +3494,11 @@ core_info_t *playlist_get_default_core_info(playlist_t* playlist) { core_info_t *core_info = NULL; - if (!playlist || - string_is_empty(playlist->default_core_path) || - string_is_empty(playlist->default_core_name) || - string_is_equal(playlist->default_core_path, FILE_PATH_DETECT) || - string_is_equal(playlist->default_core_name, FILE_PATH_DETECT)) + if ( !playlist + || string_is_empty(playlist->default_core_path) + || string_is_empty(playlist->default_core_name) + || string_is_equal(playlist->default_core_path, FILE_PATH_DETECT) + || string_is_equal(playlist->default_core_name, FILE_PATH_DETECT)) return NULL; /* Search for associated core */