Commit Diff


commit - 6d9d28c32eec189b3f26c36f5510c7c4513c8ffd
commit + 73a5ef678f0ee5f125fa5154baffb9cde3a1b133
blob - 5b44fb5c530b1eb6b406a95d0f5330136258c98d
blob + 3a8dd15749445c01ce379f9b5bae078a58365c39
--- lib/worktree.c
+++ lib/worktree.c
@@ -47,7 +47,7 @@ create_meta_file(const char *gotpath, const char *name
 		goto done;
 	}
 
-	fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_EXLOCK | O_NOFOLLOW,
+	fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW,
 	    GOT_DEFAULT_FILE_MODE);
 	if (fd == -1) {
 		err = got_error_from_errno();
@@ -94,9 +94,10 @@ read_meta_file(char **content, const char *gotpath, co
 		goto done;
 	}
 
-	fd = open(path, O_RDONLY | O_EXCL | O_EXLOCK | O_NOFOLLOW);
+	fd = open(path, O_RDONLY | O_EXLOCK | O_NONBLOCK | O_NOFOLLOW);
 	if (fd == -1) {
-		err = got_error_from_errno();
+		err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
+		    : got_error_from_errno());
 		goto done;
 	}
 
@@ -232,10 +233,11 @@ got_worktree_open(struct got_worktree **worktree, cons
 		goto done;
 	}
 
-	fd = open(path_fileindex, O_RDWR | O_EXCL | O_EXLOCK | O_NOFOLLOW,
+	fd = open(path_fileindex, O_RDWR | O_EXLOCK | O_NONBLOCK | O_NOFOLLOW,
 	    GOT_DEFAULT_FILE_MODE);
 	if (fd == -1) {
-		err = got_error(GOT_ERR_WORKTREE_BUSY);
+		err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
+		    : got_error_from_errno());
 		goto done;
 	}