[PATCH 5/7] odb/source-files: signal mark objects via positive return
Patrick Steinhardt <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <20260818-pks-odb-generic-corrupt-objects-v1-5-ec234567510f@pks.im> |
The files source conflates all failures of its child sources into a negative return value, so callers cannot tell apart whether an object is missing or whether reading it has failed. Both the packed and the loose source have been converted to adhere to the tri-state return convention of `read_object_info()` by now, so all that is left to do is to propagate their respective return values. Signed-off-by: Patrick Steinhardt <[email protected]> --- odb/source-files.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/odb/source-files.c b/odb/source-files.c index 5a68af7d84..1124a18091 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -65,12 +65,26 @@ static int odb_source_files_read_object_info(struct odb_source *source, enum object_info_flags flags) { struct odb_source_files *files = odb_source_files_downcast(source); + int ret_packed, ret_loose; - if (!odb_source_read_object_info(&files->packed->base, oid, oi, flags) || - !odb_source_read_object_info(&files->loose->base, oid, oi, flags)) + ret_packed = odb_source_read_object_info(&files->packed->base, oid, oi, flags); + if (!ret_packed) return 0; - return -1; + ret_loose = odb_source_read_object_info(&files->loose->base, oid, oi, flags); + if (!ret_loose) + return 0; + + /* + * Reading the packed object may have failed even though the object + * exists, for example because it is corrupt. Report this failure to + * the caller in case neither of the sources was able to read the + * object, and prefer the error of the packed source in case both + * reads have failed. + */ + if (ret_packed < 0) + return ret_packed; + return ret_loose; } static int odb_source_files_read_object_stream(struct odb_read_stream **out, -- 2.55.0.822.g20453c30eb.dirty