Commit Diff


commit - ddcd8544ed03d513d539a972b05a2c0140b48b90
commit + 49c7094fd1f4489f4e5880e2d649aa27ea65e2fd
blob - 0dd31b244f9c1bd18003cfa2eee85256fa951db5
blob + 8071dfb58a04a1feb6a27a782e1b5d9c5c2dcb88
--- lib/reference.c
+++ lib/reference.c
@@ -741,12 +741,10 @@ got_ref_write(struct got_reference *ref, struct got_re
 	}
 
 	err = got_opentemp_named(&tmppath, &f, path);
-	if (f == NULL) {
+	if (err) {
 		char *parent;
-		if (errno != ENOENT) {
-			err = got_error_from_errno();
+		if (!(err->code == GOT_ERR_ERRNO && errno == ENOENT))
 			goto done;
-		}
 		parent = dirname(path);
 		if (parent == NULL) {
 			err = got_error_from_errno();
@@ -756,10 +754,8 @@ got_ref_write(struct got_reference *ref, struct got_re
 		if (err)
 			goto done;
 		err = got_opentemp_named(&tmppath, &f, path);
-		if (f == NULL) {
-			err = got_error_from_errno();
+		if (err)
 			goto done;
-		}
 	}
 
 	if (ref->flags & GOT_REF_IS_SYMBOLIC) {