mirror of
https://github.com/simon987/sist2.git
synced 2025-04-18 17:56:44 +00:00
Support for rewind buffer
This commit is contained in:
parent
34b363bfd8
commit
17fda1e540
@ -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.filepath = job->filepath;
|
||||||
job->vfile.read = fs_read;
|
job->vfile.read = fs_read;
|
||||||
|
// Filesystem reads are always rewindable
|
||||||
|
job->vfile.read_rewindable = fs_read;
|
||||||
job->vfile.reset = fs_reset;
|
job->vfile.reset = fs_reset;
|
||||||
job->vfile.close = fs_close;
|
job->vfile.close = fs_close;
|
||||||
job->vfile.fd = -1;
|
job->vfile.fd = -1;
|
||||||
job->vfile.is_fs_file = TRUE;
|
job->vfile.is_fs_file = TRUE;
|
||||||
job->vfile.has_checksum = FALSE;
|
job->vfile.has_checksum = FALSE;
|
||||||
|
job->vfile.rewind_buffer_size = 0;
|
||||||
|
job->vfile.rewind_buffer = NULL;
|
||||||
job->vfile.calculate_checksum = ScanCtx.calculate_checksums;
|
job->vfile.calculate_checksum = ScanCtx.calculate_checksums;
|
||||||
|
|
||||||
return job;
|
return job;
|
||||||
|
@ -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, "read-subtitles", &scan_args->read_subtitles, "Read subtitles from media files."),
|
||||||
OPT_BOOLEAN(0, "fast-epub", &scan_args->fast_epub,
|
OPT_BOOLEAN(0, "fast-epub", &scan_args->fast_epub,
|
||||||
"Faster but less accurate EPUB parsing (no thumbnails, metadata)"),
|
"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_GROUP("Index options"),
|
||||||
OPT_INTEGER('t', "threads", &common_threads, "Number of threads. DEFAULT=1"),
|
OPT_INTEGER('t', "threads", &common_threads, "Number of threads. DEFAULT=1"),
|
||||||
|
@ -27,7 +27,7 @@ int fs_read(struct vfile *f, void *buf, size_t size) {
|
|||||||
|
|
||||||
if (ret != 0 && f->calculate_checksum) {
|
if (ret != 0 && f->calculate_checksum) {
|
||||||
f->has_checksum = TRUE;
|
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;
|
return ret;
|
||||||
@ -102,18 +102,17 @@ void parse(void *arg) {
|
|||||||
doc->mime = mime_get_mime_by_ext(ScanCtx.ext_table, job->filepath + job->ext);
|
doc->mime = mime_get_mime_by_ext(ScanCtx.ext_table, job->filepath + job->ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes_read = 0;
|
|
||||||
|
|
||||||
if (doc->mime == 0 && !ScanCtx.fast) {
|
if (doc->mime == 0 && !ScanCtx.fast) {
|
||||||
|
|
||||||
// Get mime type with libmagic
|
// Get mime type with libmagic
|
||||||
if (!job->vfile.is_fs_file) {
|
if (job->vfile.read_rewindable == NULL) {
|
||||||
LOG_WARNING(job->filepath,
|
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;
|
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 (bytes_read < 0) {
|
||||||
|
|
||||||
if (job->vfile.is_fs_file) {
|
if (job->vfile.is_fs_file) {
|
||||||
@ -144,7 +143,9 @@ void parse(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (job->vfile.reset != NULL) {
|
||||||
job->vfile.reset(&job->vfile);
|
job->vfile.reset(&job->vfile);
|
||||||
|
}
|
||||||
|
|
||||||
magic_close(magic);
|
magic_close(magic);
|
||||||
}
|
}
|
||||||
@ -158,7 +159,7 @@ void parse(void *arg) {
|
|||||||
} else if ((mmime == MimeVideo && doc->size >= MIN_VIDEO_SIZE) ||
|
} else if ((mmime == MimeVideo && doc->size >= MIN_VIDEO_SIZE) ||
|
||||||
(mmime == MimeImage && doc->size >= MIN_IMAGE_SIZE) || mmime == MimeAudio) {
|
(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)) {
|
} else if (IS_PDF(doc->mime)) {
|
||||||
parse_ebook(&ScanCtx.ebook_ctx, &job->vfile, mime_get_mime_text(doc->mime), doc);
|
parse_ebook(&ScanCtx.ebook_ctx, &job->vfile, mime_get_mime_text(doc->mime), doc);
|
||||||
|
2
third-party/libscan
vendored
2
third-party/libscan
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 52d7649322cd8db370774b70cda0448e7e20b0b6
|
Subproject commit da172823745b67662846cf1970a47ebcea8fe50e
|
Loading…
x
Reference in New Issue
Block a user