diff options
-rw-r--r-- | stream/stream_libarchive.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/stream/stream_libarchive.c b/stream/stream_libarchive.c index fdcc9c3ce2..2dddb45832 100644 --- a/stream/stream_libarchive.c +++ b/stream/stream_libarchive.c @@ -142,7 +142,7 @@ static bool mp_archive_check_fatal(struct mp_archive *mpa, int r) { if (r > ARCHIVE_FATAL) return false; - MP_FATAL(mpa, "fatal error received - cllsing archive\n"); + MP_FATAL(mpa, "fatal error received - closing archive\n"); mp_archive_close(mpa); return true; } @@ -347,6 +347,7 @@ bool mp_archive_next_entry(struct mp_archive *mpa) struct priv { struct mp_archive *mpa; + bool broken_seek; struct stream *src; int64_t entry_size; char *entry_name; @@ -400,17 +401,16 @@ static int archive_entry_fill_buffer(stream_t *s, char *buffer, int max_len) static int archive_entry_seek(stream_t *s, int64_t newpos) { struct priv *p = s->priv; - if (!p->mpa) - return -1; - locale_t oldlocale = uselocale(p->mpa->locale); - int r = archive_seek_data(p->mpa->arch, newpos, SEEK_SET); - uselocale(oldlocale); - if (r >= 0) - return 1; - if (mp_archive_check_fatal(p->mpa, r)) { - mp_archive_free(p->mpa); - p->mpa = NULL; - return -1; + if (p->mpa && !p->broken_seek) { + locale_t oldlocale = uselocale(p->mpa->locale); + int r = archive_seek_data(p->mpa->arch, newpos, SEEK_SET); + uselocale(oldlocale); + if (r >= 0) + return 1; + MP_WARN(s, "possibly unsupported seeking - switching to reopening\n"); + p->broken_seek = true; + if (reopen_archive(s) < STREAM_OK) + return -1; } // libarchive can't seek in most formats. if (newpos < s->pos) { @@ -430,8 +430,8 @@ static int archive_entry_seek(stream_t *s, int64_t newpos) return -1; int size = MPMIN(newpos - s->pos, sizeof(buffer)); - oldlocale = uselocale(p->mpa->locale); - r = archive_read_data(p->mpa->arch, buffer, size); + locale_t oldlocale = uselocale(p->mpa->locale); + int r = archive_read_data(p->mpa->arch, buffer, size); if (r < 0) { MP_ERR(s, "%s\n", archive_error_string(p->mpa->arch)); uselocale(oldlocale); |