Commit c789dbac2f1f72c0eff66e7965cc55fc36113b39

Stefan Sperling 2019-03-11T16:26:28

fix bug in got_lockfile_lock() where it never succeeded

diff --git a/lib/lockfile.c b/lib/lockfile.c
index 2ea32df..5fb38e7 100644
--- a/lib/lockfile.c
+++ b/lib/lockfile.c
@@ -55,13 +55,13 @@ got_lockfile_lock(struct got_lockfile **lf, const char *path)
 
 	do {
 		(*lf)->fd = open((*lf)->path, flags, GOT_DEFAULT_FILE_MODE);
-		if ((*lf)->fd == -1) {
-			if (errno != EEXIST) {
-				err = got_error_from_errno();
-				goto done;
-			}
-			sleep(1);
+		if ((*lf)->fd != -1)
+			break;
+		if (errno != EEXIST) {
+			err = got_error_from_errno();
+			goto done;
 		}
+		sleep(1);
 	} while (--attempts > 0);
 
 	if ((*lf)->fd == -1)