commit ddbb3188dfcc3d488f561df80ff17b4783b00dd1 from: Stefan Sperling via: Thomas Adam date: Tue Oct 01 23:00:28 2024 UTC make got_object_open_loose_fd() return NO_OBJ error upon ENOENT Some callers were manually converting from ENOENT to NO_OBJ. Checking errno becomes increasingly unreliable the further up the call-chain we return to. Let's return NO_OBJ directly at the spot where the original error condition is detected. commit - 961964db5e0e6f4f1568b633d83807af65c922d5 commit + ddbb3188dfcc3d488f561df80ff17b4783b00dd1 blob - 615f66fabdd166d9721ab090fe1c364e1769bfbd blob + eab399777a9e609d5c47a051ccb6670648eb8fb3 --- lib/object.c +++ lib/object.c @@ -136,7 +136,10 @@ got_object_open_loose_fd(int *fd, struct got_object_id return err; *fd = open(path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); if (*fd == -1) { - err = got_error_from_errno2("open", path); + if (errno == ENOENT) + err = got_error_no_obj(id); + else + err = got_error_from_errno2("open", path); goto done; } done: blob - d6225e5adf9ab9758646a0e40580dc931306c7f4 blob + ea32f22e2f55de21f40313b7d5bfd7250fb8b166 --- lib/object_open_io.c +++ lib/object_open_io.c @@ -143,11 +143,8 @@ got_object_open(struct got_object **obj, struct got_re return NULL; err = got_object_open_loose_fd(&fd, id, repo); - if (err) { - if (err->code == GOT_ERR_ERRNO && errno == ENOENT) - err = got_error_no_obj(id); + if (err) return err; - } err = got_object_read_header(obj, fd); if (err) blob - c156857f4cc554d6633d9059a6c60e29c68bfdbd blob + 2bb64eceaff2476797ea46cd6e94349d6d17ae7e --- lib/object_open_privsep.c +++ lib/object_open_privsep.c @@ -438,11 +438,8 @@ got_object_open(struct got_object **obj, struct got_re } err = got_object_open_loose_fd(&fd, id, repo); - if (err) { - if (err->code == GOT_ERR_ERRNO && errno == ENOENT) - err = got_error_no_obj(id); + if (err) return err; - } err = got_object_read_header_privsep(obj, id, repo, fd); if (err) blob - 1b2025992be4d03420f106db1af5777b5bb84907 blob + 6f82982ad2e1d53c37ba2de0a2ebfaca01a77193 --- regress/cmdline/tree.sh +++ regress/cmdline/tree.sh @@ -90,9 +90,7 @@ test_tree_submodule() { local submodule_id=$(got tree -r $testroot/repo -i | \ grep 'repo2\$$' | cut -d ' ' -f1) - local objpath=`get_loose_object_path $testroot/repo $submodule_id` - # Currently fails in open(2) got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr ret=$? if [ $ret -eq 0 ]; then @@ -100,8 +98,7 @@ test_tree_submodule() { test_done "$testroot" "1" return 1 fi - echo "got: open: $objpath: No such file or directory" \ - > $testroot/stderr.expected + echo "got: object $submodule_id not found" > $testroot/stderr.expected cmp -s $testroot/stderr.expected $testroot/stderr ret=$?