* Fix scanner crash bug if the first entry in a media directory is a file and not a directory.
This commit is contained in:
parent
0324818d86
commit
cc6a00b34d
10
scanner.c
10
scanner.c
@ -306,6 +306,7 @@ insert_directory(const char * name, const char * path, const char * base, const
|
|||||||
char * parent_buf = NULL;
|
char * parent_buf = NULL;
|
||||||
char **result;
|
char **result;
|
||||||
char *dir = NULL;
|
char *dir = NULL;
|
||||||
|
static char last_found[256] = "-1";
|
||||||
|
|
||||||
if( strcmp(base, BROWSEDIR_ID) != 0 )
|
if( strcmp(base, BROWSEDIR_ID) != 0 )
|
||||||
asprintf(&refID, "%s%s$%X", BROWSEDIR_ID, parentID, objectID);
|
asprintf(&refID, "%s%s$%X", BROWSEDIR_ID, parentID, objectID);
|
||||||
@ -318,11 +319,14 @@ insert_directory(const char * name, const char * path, const char * base, const
|
|||||||
asprintf(&parent_buf, "%s%s", base, parentID);
|
asprintf(&parent_buf, "%s%s", base, parentID);
|
||||||
while( !found )
|
while( !found )
|
||||||
{
|
{
|
||||||
|
if( strcmp(id_buf, last_found) == 0 )
|
||||||
|
break;
|
||||||
sql = sqlite3_mprintf("SELECT count(OBJECT_ID) from OBJECTS where OBJECT_ID = '%s'", id_buf);
|
sql = sqlite3_mprintf("SELECT count(OBJECT_ID) from OBJECTS where OBJECT_ID = '%s'", id_buf);
|
||||||
if( (sql_get_table(db, sql, &result, NULL, NULL) == SQLITE_OK) && atoi(result[1]) )
|
if( (sql_get_table(db, sql, &result, NULL, NULL) == SQLITE_OK) && atoi(result[1]) )
|
||||||
{
|
{
|
||||||
sqlite3_free_table(result);
|
sqlite3_free_table(result);
|
||||||
sqlite3_free(sql);
|
sqlite3_free(sql);
|
||||||
|
strcpy(last_found, id_buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sqlite3_free_table(result);
|
sqlite3_free_table(result);
|
||||||
@ -418,8 +422,6 @@ insert_file(char * name, const char * path, const char * parentID, int object)
|
|||||||
*baseid = '\0';
|
*baseid = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_directory(name, path, base, typedir_parentID, typedir_objectID);
|
|
||||||
|
|
||||||
sql = sqlite3_mprintf( "INSERT into OBJECTS"
|
sql = sqlite3_mprintf( "INSERT into OBJECTS"
|
||||||
" (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME) "
|
" (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME) "
|
||||||
"VALUES"
|
"VALUES"
|
||||||
@ -429,6 +431,8 @@ insert_file(char * name, const char * path, const char * parentID, int object)
|
|||||||
sql_exec(db, sql);
|
sql_exec(db, sql);
|
||||||
sqlite3_free(sql);
|
sqlite3_free(sql);
|
||||||
|
|
||||||
|
insert_directory(name, path, base, typedir_parentID, typedir_objectID);
|
||||||
|
|
||||||
sql = sqlite3_mprintf( "INSERT into OBJECTS"
|
sql = sqlite3_mprintf( "INSERT into OBJECTS"
|
||||||
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
|
||||||
"VALUES"
|
"VALUES"
|
||||||
@ -668,6 +672,6 @@ ScanDirectory(const char * dir, const char * parent, enum media_types type)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Scanning \"%s\" finished!\n", dir);
|
printf("Scanning %s finished!\n", dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user