Only fail zip_source_read if a previous error occured during read. Fixes case where clonefile() fails (e.g. on HFS+).
diff --git a/lib/zip_source_function.c b/lib/zip_source_function.c index 06ce5c9..bc74608 100644 --- a/lib/zip_source_function.c +++ b/lib/zip_source_function.c
@@ -95,6 +95,7 @@ src->refcount = 1; zip_error_init(&src->error); src->eof = false; + src->had_read_error = false; return src; }
diff --git a/lib/zip_source_open.c b/lib/zip_source_open.c index a5712b2..e4cb0b3 100644 --- a/lib/zip_source_open.c +++ b/lib/zip_source_open.c
@@ -68,6 +68,7 @@ } src->eof = false; + src->had_read_error = false; _zip_error_clear(&src->error); src->open_count++;
diff --git a/lib/zip_source_read.c b/lib/zip_source_read.c index 267128b..cd935ad 100644 --- a/lib/zip_source_read.c +++ b/lib/zip_source_read.c
@@ -49,7 +49,7 @@ return -1; } - if (_zip_source_had_error(src)) { + if (src->had_read_error) { return -1; } @@ -60,6 +60,7 @@ bytes_read = 0; while (bytes_read < len) { if ((n = _zip_source_call(src, (zip_uint8_t *)data + bytes_read, len - bytes_read, ZIP_SOURCE_READ)) < 0) { + src->had_read_error = true; if (bytes_read == 0) { return -1; }
diff --git a/lib/zipint.h b/lib/zipint.h index e5f6095..a4e287c 100644 --- a/lib/zipint.h +++ b/lib/zipint.h
@@ -330,6 +330,7 @@ zip_t *source_archive; /* zip archive we're reading from, NULL if not from archive */ unsigned int refcount; bool eof; /* EOF reached */ + bool had_read_error; /* a previous ZIP_SOURCE_READ reported an error */ }; #define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)