commit - dbc85498aa04f27ae3e011e0a75f8a73173970e616145f32b49967edbd36fc9d
commit + 3fb2130a1acdb6b75c8c39c903f845c49d835a2bed1f53efea0675903367e589
blob - 5f797f951539132a03c0e5589681a7692202a6ef0686363773396dd3fc220b28
blob + 455cb98413dcedd0f41144e8041661b24f4079bab2501680cc5b5d0b880d0ed2
--- include/got_worktree.h
+++ include/got_worktree.h
const struct got_error *got_worktree_open(struct got_worktree **,
const char *path, const char *meta_dir);
+/* As got_worktree_open except take a shared lock. */
+const struct got_error *got_worktree_open_shared(struct got_worktree **,
+ const char *path, const char *meta_dir);
+
/* Dispose of an open work tree. */
const struct got_error *got_worktree_close(struct got_worktree *);
blob - 56b3f6adb0e425c98b269eef35e87693e7d12335e02d83310f492baa70be95f0
blob + 15e1b914dde5169ed1c033152acf76fd92429783d3e969d58aa476ef74c7735f
--- lib/worktree_open.c
+++ lib/worktree_open.c
static const struct got_error *
open_worktree(struct got_worktree **worktree, const char *path,
- const char *meta_dir)
+ const char *meta_dir, int flags)
{
const struct got_error *err = NULL;
char *path_meta;
goto done;
}
- fd = open(path_lock, O_RDWR | O_EXLOCK | O_NONBLOCK | O_CLOEXEC);
+ fd = open(path_lock, O_RDWR | flags | O_NONBLOCK | O_CLOEXEC);
if (fd == -1) {
err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
: got_error_from_errno2("open", path_lock));
return err;
}
-const struct got_error *
-got_worktree_open(struct got_worktree **worktree, const char *path,
- const char *meta_dir)
+static const struct got_error *
+got_worktree_open_flags(struct got_worktree **worktree, const char *path,
+ const char *meta_dir, int flags)
{
const struct got_error *err = NULL;
char *worktree_path;
if (meta_dir == NULL) {
for (i = 0; i < nitems(meta_dirs); i++) {
err = open_worktree(worktree, worktree_path,
- meta_dirs[i]);
+ meta_dirs[i], flags);
if (err == NULL ||
err->code == GOT_ERR_WORKTREE_BUSY)
break;
}
}
} else
- err = open_worktree(worktree, worktree_path, meta_dir);
+ err = open_worktree(worktree, worktree_path, meta_dir,
+ flags);
if (err && !(err->code == GOT_ERR_ERRNO && errno == ENOENT)) {
free(worktree_path);
return err;
}
const struct got_error *
+got_worktree_open(struct got_worktree **worktree, const char *path,
+ const char *meta_dir)
+{
+ return got_worktree_open_flags(worktree, path, meta_dir, O_EXLOCK);
+}
+
+const struct got_error *
+got_worktree_open_shared(struct got_worktree **worktree, const char *path,
+ const char *meta_dir)
+{
+ return got_worktree_open_flags(worktree, path, meta_dir, O_SHLOCK);
+}
+
+const struct got_error *
got_worktree_close(struct got_worktree *worktree)
{
const struct got_error *err = NULL;