mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-20 18:54:05 -04:00
[scan] Coverity fixups
This commit is contained in:
parent
d72958f1f7
commit
a09da06e8f
@ -170,10 +170,10 @@ virtual_path_make(char *virtual_path, int virtual_path_len, const char *path)
|
|||||||
|
|
||||||
ret = snprintf(virtual_path, virtual_path_len, "/file:%s", path);
|
ret = snprintf(virtual_path, virtual_path_len, "/file:%s", path);
|
||||||
if ((ret < 0) || (ret >= virtual_path_len))
|
if ((ret < 0) || (ret >= virtual_path_len))
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Virtual path '/file:%s', virtual_path_len exceeded (%d/%d)\n", path, ret, virtual_path_len);
|
DPRINTF(E_LOG, L_SCAN, "Virtual path '/file:%s', virtual_path_len exceeded (%d/%d)\n", path, ret, virtual_path_len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -816,7 +816,6 @@ process_directory(char *path, int parent_id, int flags)
|
|||||||
if (!dirp)
|
if (!dirp)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Could not open directory %s: %s\n", path, strerror(errno));
|
DPRINTF(E_LOG, L_SCAN, "Could not open directory %s: %s\n", path, strerror(errno));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -824,7 +823,10 @@ process_directory(char *path, int parent_id, int flags)
|
|||||||
|
|
||||||
ret = virtual_path_make(virtual_path, sizeof(virtual_path), path);
|
ret = virtual_path_make(virtual_path, sizeof(virtual_path), path);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return;
|
{
|
||||||
|
closedir(dirp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dir_id = db_directory_addorupdate(virtual_path, path, 0, parent_id);
|
dir_id = db_directory_addorupdate(virtual_path, path, 0, parent_id);
|
||||||
if (dir_id <= 0)
|
if (dir_id <= 0)
|
||||||
@ -853,7 +855,6 @@ process_directory(char *path, int parent_id, int flags)
|
|||||||
if (errno)
|
if (errno)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "readdir error in %s: %s\n", path, strerror(errno));
|
DPRINTF(E_LOG, L_SCAN, "readdir error in %s: %s\n", path, strerror(errno));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -879,7 +880,6 @@ process_directory(char *path, int parent_id, int flags)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Skipping %s, read_attributes() failed\n", entry);
|
DPRINTF(E_LOG, L_SCAN, "Skipping %s, read_attributes() failed\n", entry);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -916,7 +916,6 @@ process_directory(char *path, int parent_id, int flags)
|
|||||||
if (wi.wd < 0)
|
if (wi.wd < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_SCAN, "Could not create inotify watch for %s: %s\n", path, strerror(errno));
|
DPRINTF(E_WARN, L_SCAN, "Could not create inotify watch for %s: %s\n", path, strerror(errno));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1112,8 +1111,8 @@ static void
|
|||||||
process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
|
process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
|
||||||
{
|
{
|
||||||
struct watch_enum we;
|
struct watch_enum we;
|
||||||
|
struct watch_info dummy_wi;
|
||||||
uint32_t rm_wd;
|
uint32_t rm_wd;
|
||||||
char *s;
|
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
int ret;
|
int ret;
|
||||||
int parent_id;
|
int parent_id;
|
||||||
@ -1204,12 +1203,9 @@ process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
|
|||||||
DPRINTF(E_DBG, L_SCAN, "Directory permissions changed (%s): %s\n", wi->path, path);
|
DPRINTF(E_DBG, L_SCAN, "Directory permissions changed (%s): %s\n", wi->path, path);
|
||||||
|
|
||||||
// Find out if we are already watching the dir (ret will be 0)
|
// Find out if we are already watching the dir (ret will be 0)
|
||||||
s = wi->path;
|
ret = db_watch_get_bypath(&dummy_wi, path);
|
||||||
wi->path = path;
|
|
||||||
ret = db_watch_get_bypath(wi);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
free(wi->path);
|
free_wi(&dummy_wi, 1);
|
||||||
wi->path = s;
|
|
||||||
|
|
||||||
// We don't use access() or euidaccess() because they don't work with ACL's
|
// We don't use access() or euidaccess() because they don't work with ACL's
|
||||||
// - this also means we can't check for executable permission, which stat()
|
// - this also means we can't check for executable permission, which stat()
|
||||||
@ -1237,7 +1233,7 @@ process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
|
|||||||
DPRINTF(E_INFO, L_SCAN, "Directory event, but '%s' already being watched\n", path);
|
DPRINTF(E_INFO, L_SCAN, "Directory event, but '%s' already being watched\n", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd > 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1321,7 +1317,7 @@ process_inotify_file(struct watch_info *wi, char *path, struct inotify_event *ie
|
|||||||
ie->mask |= IN_CLOSE_WRITE;
|
ie->mask |= IN_CLOSE_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd > 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1336,7 +1332,7 @@ process_inotify_file(struct watch_info *wi, char *path, struct inotify_event *ie
|
|||||||
ret = virtual_path_make(dir_vpath, sizeof(dir_vpath), path);
|
ret = virtual_path_make(dir_vpath, sizeof(dir_vpath), path);
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
ptr = strrchr(dir_vpath, '/');
|
CHECK_NULL(L_SCAN, ptr = strrchr(dir_vpath, '/'));
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
|
||||||
dir_id = db_directory_id_byvirtualpath(dir_vpath);
|
dir_id = db_directory_id_byvirtualpath(dir_vpath);
|
||||||
@ -1539,8 +1535,7 @@ inotify_cb(int fd, short event, void *arg)
|
|||||||
* the memory space for ie[1+] contains the name of the file
|
* the memory space for ie[1+] contains the name of the file
|
||||||
* see the inotify documentation
|
* see the inotify documentation
|
||||||
*/
|
*/
|
||||||
wi.wd = ie->wd;
|
ret = db_watch_get_bywd(&wi, ie->wd);
|
||||||
ret = db_watch_get_bywd(&wi);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
if (!(ie->mask & IN_IGNORED))
|
if (!(ie->mask & IN_IGNORED))
|
||||||
@ -1554,30 +1549,30 @@ inotify_cb(int fd, short event, void *arg)
|
|||||||
DPRINTF(E_DBG, L_SCAN, "%s deleted or backing filesystem unmounted!\n", wi.path);
|
DPRINTF(E_DBG, L_SCAN, "%s deleted or backing filesystem unmounted!\n", wi.path);
|
||||||
|
|
||||||
db_watch_delete_bywd(ie->wd);
|
db_watch_delete_bywd(ie->wd);
|
||||||
free(wi.path);
|
free_wi(&wi, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
|
|
||||||
ret = snprintf(path, PATH_MAX, "%s", wi.path);
|
ret = snprintf(path, sizeof(path), "%s", wi.path);
|
||||||
if ((ret < 0) || (ret >= PATH_MAX))
|
if ((ret < 0) || (ret >= sizeof(path)))
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Skipping event under %s, PATH_MAX exceeded\n", wi.path);
|
DPRINTF(E_LOG, L_SCAN, "Skipping event under %s, PATH_MAX exceeded\n", wi.path);
|
||||||
|
|
||||||
free(wi.path);
|
free_wi(&wi, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ie->len > 0)
|
if (ie->len > 0)
|
||||||
{
|
{
|
||||||
namelen = PATH_MAX - ret;
|
namelen = sizeof(path) - ret;
|
||||||
ret = snprintf(path + ret, namelen, "/%s", ie->name);
|
ret = snprintf(path + ret, namelen, "/%s", ie->name);
|
||||||
if ((ret < 0) || (ret >= namelen))
|
if ((ret < 0) || (ret >= namelen))
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Skipping %s/%s, PATH_MAX exceeded\n", wi.path, ie->name);
|
DPRINTF(E_LOG, L_SCAN, "Skipping %s/%s, PATH_MAX exceeded\n", wi.path, ie->name);
|
||||||
|
|
||||||
free(wi.path);
|
free_wi(&wi, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1595,7 +1590,7 @@ inotify_cb(int fd, short event, void *arg)
|
|||||||
#else
|
#else
|
||||||
process_inotify_file_defer(&wi, path, ie);
|
process_inotify_file_defer(&wi, path, ie);
|
||||||
#endif
|
#endif
|
||||||
free(wi.path);
|
free_wi(&wi, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -749,40 +749,40 @@ process_pl_items(plist_t items, int pl_id, const char *name, struct itml_to_db_m
|
|||||||
db_transaction_end();
|
db_transaction_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
ignore_pl(plist_t pl, const char *name)
|
ignore_pl(plist_t pl, const char *name)
|
||||||
{
|
{
|
||||||
uint64_t kind;
|
uint64_t kind;
|
||||||
int smart;
|
|
||||||
uint8_t master;
|
uint8_t master;
|
||||||
uint8_t party;
|
uint8_t party;
|
||||||
|
|
||||||
kind = 0;
|
if (get_dictval_int_from_key(pl, "Distinguished Kind", &kind) == 0 && kind > 0)
|
||||||
smart = 0;
|
{
|
||||||
master = 0;
|
DPRINTF(E_INFO, L_SCAN, "Ignoring iTunes builtin playlist '%s' (k %" PRIu64 ")\n", name, kind);
|
||||||
party = 0;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Special (builtin) playlists */
|
if (get_dictval_bool_from_key(pl, "Master", &master) == 0 && master)
|
||||||
get_dictval_int_from_key(pl, "Distinguished Kind", &kind);
|
{
|
||||||
|
DPRINTF(E_INFO, L_SCAN, "Ignoring iTunes Master playlist '%s'\n", name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_dictval_bool_from_key(pl, "Party Shuffle", &party) == 0 && party)
|
||||||
|
{
|
||||||
|
DPRINTF(E_INFO, L_SCAN, "Ignoring iTunes Party Shuffle playlist '%s'\n", name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Import smart playlists (optional) */
|
/* Import smart playlists (optional) */
|
||||||
if (!cfg_getbool(cfg_getsec(cfg, "library"), "itunes_smartpl")
|
if (!cfg_getbool(cfg_getsec(cfg, "library"), "itunes_smartpl")
|
||||||
&& (plist_dict_get_item(pl, "Smart Info") || plist_dict_get_item(pl, "Smart Criteria")))
|
&& (plist_dict_get_item(pl, "Smart Info") || plist_dict_get_item(pl, "Smart Criteria")))
|
||||||
smart = 1;
|
|
||||||
|
|
||||||
/* Not interested in the Master playlist */
|
|
||||||
get_dictval_bool_from_key(pl, "Master", &master);
|
|
||||||
/* Not interested in Party Shuffle playlists */
|
|
||||||
get_dictval_bool_from_key(pl, "Party Shuffle", &party);
|
|
||||||
|
|
||||||
if ((kind > 0) || smart || party || master)
|
|
||||||
{
|
{
|
||||||
DPRINTF(E_INFO, L_SCAN, "Ignoring playlist '%s' (k %" PRIu64 " s%d p%d m%d)\n", name, kind, smart, party, master);
|
DPRINTF(E_INFO, L_SCAN, "Ignoring iTunes smart playlist as set in config '%s'\n", name);
|
||||||
|
return true;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user