diff --git a/src/io/walk.c b/src/io/walk.c index 330f7b4..2aec195 100644 --- a/src/io/walk.c +++ b/src/io/walk.c @@ -24,11 +24,15 @@ parse_job_t *create_fs_parse_job(const char *filepath, const struct stat *info, job->vfile.filepath = job->filepath; job->vfile.read = fs_read; + // Filesystem reads are always rewindable + job->vfile.read_rewindable = fs_read; job->vfile.reset = fs_reset; job->vfile.close = fs_close; job->vfile.fd = -1; job->vfile.is_fs_file = TRUE; job->vfile.has_checksum = FALSE; + job->vfile.rewind_buffer_size = 0; + job->vfile.rewind_buffer = NULL; job->vfile.calculate_checksum = ScanCtx.calculate_checksums; return job; diff --git a/src/main.c b/src/main.c index 7667d86..c6ca0dd 100644 --- a/src/main.c +++ b/src/main.c @@ -576,7 +576,7 @@ int main(int argc, const char *argv[]) { OPT_BOOLEAN(0, "read-subtitles", &scan_args->read_subtitles, "Read subtitles from media files."), OPT_BOOLEAN(0, "fast-epub", &scan_args->fast_epub, "Faster but less accurate EPUB parsing (no thumbnails, metadata)"), - OPT_BOOLEAN(0, "checksum", &scan_args->calculate_checksums, "Calculate file checksums when scanning."), + OPT_BOOLEAN(0, "checksums", &scan_args->calculate_checksums, "Calculate file checksums when scanning."), OPT_GROUP("Index options"), OPT_INTEGER('t', "threads", &common_threads, "Number of threads. DEFAULT=1"), diff --git a/src/parsing/parse.c b/src/parsing/parse.c index 4ca7fe7..844ecaf 100644 --- a/src/parsing/parse.c +++ b/src/parsing/parse.c @@ -27,7 +27,7 @@ int fs_read(struct vfile *f, void *buf, size_t size) { if (ret != 0 && f->calculate_checksum) { f->has_checksum = TRUE; - safe_sha1_update(&f->sha1_ctx, (unsigned char*)buf, ret); + safe_sha1_update(&f->sha1_ctx, (unsigned char *) buf, ret); } return ret; @@ -102,18 +102,17 @@ void parse(void *arg) { doc->mime = mime_get_mime_by_ext(ScanCtx.ext_table, job->filepath + job->ext); } - int bytes_read = 0; if (doc->mime == 0 && !ScanCtx.fast) { // Get mime type with libmagic - if (!job->vfile.is_fs_file) { + if (job->vfile.read_rewindable == NULL) { LOG_WARNING(job->filepath, - "Guessing mime type with libmagic inside archive files is not currently supported"); + "File does not support rewindable reads, cannot guess Media type"); goto abort; } - bytes_read = job->vfile.read(&job->vfile, buf, MAGIC_BUF_SIZE); + int bytes_read = job->vfile.read_rewindable(&job->vfile, buf, MAGIC_BUF_SIZE); if (bytes_read < 0) { if (job->vfile.is_fs_file) { @@ -144,7 +143,9 @@ void parse(void *arg) { } } - job->vfile.reset(&job->vfile); + if (job->vfile.reset != NULL) { + job->vfile.reset(&job->vfile); + } magic_close(magic); } @@ -158,7 +159,7 @@ void parse(void *arg) { } else if ((mmime == MimeVideo && doc->size >= MIN_VIDEO_SIZE) || (mmime == MimeImage && doc->size >= MIN_IMAGE_SIZE) || mmime == MimeAudio) { - parse_media(&ScanCtx.media_ctx, &job->vfile, doc); + parse_media(&ScanCtx.media_ctx, &job->vfile, doc, mime_get_mime_text(doc->mime)); } else if (IS_PDF(doc->mime)) { parse_ebook(&ScanCtx.ebook_ctx, &job->vfile, mime_get_mime_text(doc->mime), doc); diff --git a/third-party/libscan b/third-party/libscan index 52d7649..da17282 160000 --- a/third-party/libscan +++ b/third-party/libscan @@ -1 +1 @@ -Subproject commit 52d7649322cd8db370774b70cda0448e7e20b0b6 +Subproject commit da172823745b67662846cf1970a47ebcea8fe50e