Merge pull request #1556 from whatdoineed2do/before-epoch-date_released

[db,scan,jsonapi] bug fix to handle date_released before 1970
This commit is contained in:
ejurgensen 2022-12-14 22:38:58 +01:00 committed by GitHub
commit 10a51a0af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 8 deletions

View File

@ -187,7 +187,7 @@ static const struct col_type_map mfi_cols_map[] =
{ "song_length", mfi_offsetof(song_length), DB_TYPE_INT }, { "song_length", mfi_offsetof(song_length), DB_TYPE_INT },
{ "file_size", mfi_offsetof(file_size), DB_TYPE_INT64 }, { "file_size", mfi_offsetof(file_size), DB_TYPE_INT64 },
{ "year", mfi_offsetof(year), DB_TYPE_INT }, { "year", mfi_offsetof(year), DB_TYPE_INT },
{ "date_released", mfi_offsetof(date_released), DB_TYPE_INT }, { "date_released", mfi_offsetof(date_released), DB_TYPE_INT64 },
{ "track", mfi_offsetof(track), DB_TYPE_INT }, { "track", mfi_offsetof(track), DB_TYPE_INT },
{ "total_tracks", mfi_offsetof(total_tracks), DB_TYPE_INT }, { "total_tracks", mfi_offsetof(total_tracks), DB_TYPE_INT },
{ "disc", mfi_offsetof(disc), DB_TYPE_INT }, { "disc", mfi_offsetof(disc), DB_TYPE_INT },

View File

@ -190,7 +190,7 @@ struct media_file_info {
uint32_t song_length; uint32_t song_length;
int64_t file_size; int64_t file_size;
uint32_t year; /* TDRC */ uint32_t year; /* TDRC */
uint32_t date_released; int64_t date_released; // bumped to (signed) int64 since all 32bits are unsigned
uint32_t track; /* TRCK */ uint32_t track; /* TRCK */
uint32_t total_tracks; uint32_t total_tracks;

View File

@ -147,7 +147,7 @@ safe_json_add_time_from_string(json_object *obj, const char *key, const char *va
static inline void static inline void
safe_json_add_date_from_string(json_object *obj, const char *key, const char *value) safe_json_add_date_from_string(json_object *obj, const char *key, const char *value)
{ {
uint32_t tmp; int64_t tmp;
time_t timestamp; time_t timestamp;
struct tm tm; struct tm tm;
char result[32]; char result[32];
@ -155,9 +155,9 @@ safe_json_add_date_from_string(json_object *obj, const char *key, const char *va
if (!value) if (!value)
return; return;
if (safe_atou32(value, &tmp) != 0) if (safe_atoi64(value, &tmp) != 0)
{ {
DPRINTF(E_LOG, L_WEB, "Error converting timestamp to uint32_t: %s\n", value); DPRINTF(E_LOG, L_WEB, "Error converting timestamp to int64_t: %s\n", value);
return; return;
} }

View File

@ -98,7 +98,8 @@ parse_date(struct media_file_info *mfi, char *date_string)
{ {
char year_string[32]; char year_string[32];
uint32_t *year = (uint32_t *) ((char *) mfi + mfi_offsetof(year)); uint32_t *year = (uint32_t *) ((char *) mfi + mfi_offsetof(year));
uint32_t *date_released = (uint32_t *) ((char *) mfi + mfi_offsetof(date_released)); // signed in db.h to handle dates before 1970
int64_t *date_released = (int64_t *) ((char *) mfi + mfi_offsetof(date_released));
struct tm tm = { 0 }; struct tm tm = { 0 };
int ret = 0; int ret = 0;
@ -111,7 +112,7 @@ parse_date(struct media_file_info *mfi, char *date_string)
|| strptime(date_string, "%F", &tm) || strptime(date_string, "%F", &tm)
) )
{ {
*date_released = (uint32_t)mktime(&tm); *date_released = mktime(&tm);
ret++; ret++;
} }
@ -120,7 +121,7 @@ parse_date(struct media_file_info *mfi, char *date_string)
snprintf(year_string, sizeof(year_string), "%" PRIu32 "-01-01T12:00:00", *year); snprintf(year_string, sizeof(year_string), "%" PRIu32 "-01-01T12:00:00", *year);
if (strptime(year_string, "%FT%T", &tm)) if (strptime(year_string, "%FT%T", &tm))
{ {
*date_released = (uint32_t)mktime(&tm); *date_released = mktime(&tm);
ret++; ret++;
} }
} }