diff --git a/devel/got/Makefile b/devel/got/Makefile index a8faf6a176f3..ef8cb50efa41 100644 --- a/devel/got/Makefile +++ b/devel/got/Makefile @@ -2,6 +2,7 @@ PORTNAME= got PORTVERSION= 0.41 +PORTREVISION= 1 CATEGORIES= devel MASTER_SITES= https://gameoftrees.org/releases/ diff --git a/devel/got/files/openbsd-compat/Makefile b/devel/got/files/openbsd-compat/Makefile index d02773ebfb77..68efdd3bb100 100644 --- a/devel/got/files/openbsd-compat/Makefile +++ b/devel/got/files/openbsd-compat/Makefile @@ -7,6 +7,7 @@ SRCS= basename.c \ getdtablecount.c \ imsg.c \ imsg-buffer.c \ + open.c \ recallocarray.c CFLAGS+= -I${.CURDIR} diff --git a/devel/got/files/openbsd-compat/open.c b/devel/got/files/openbsd-compat/open.c new file mode 100644 index 000000000000..fa9207c0814e --- /dev/null +++ b/devel/got/files/openbsd-compat/open.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020 Christian Weisgerber + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +/* + * POSIX mandates that open(symlink, O_NOFOLLOW) fail with errno == ELOOP. + * FreeBSD chooses to deviate from this, but Got depends on it. + */ +int +open_posix(const char *path, int flags, ...) +{ + va_list ap; + mode_t mode; + int ret; + + if (flags & O_CREAT) { + va_start(ap, flags); + mode = va_arg(ap, int); + va_end(ap); + ret = open(path, flags, mode); + } else + ret = open(path, flags); + + if (ret == -1 && (flags & O_NOFOLLOW) && errno == EMLINK) + errno = ELOOP; + + return (ret); +} + +int +openat_posix(int fd, const char *path, int flags, ...) +{ + va_list ap; + mode_t mode; + int ret; + + if (flags & O_CREAT) { + va_start(ap, flags); + mode = va_arg(ap, int); + va_end(ap); + ret = openat(fd, path, flags, mode); + } else + ret = openat(fd, path, flags); + + if (ret == -1 && (flags & O_NOFOLLOW) && errno == EMLINK) + errno = ELOOP; + + return (ret); +} diff --git a/devel/got/files/openbsd-compat/openbsd-compat.h b/devel/got/files/openbsd-compat/openbsd-compat.h index fd66e6e8ef59..160184ac8bcd 100644 --- a/devel/got/files/openbsd-compat/openbsd-compat.h +++ b/devel/got/files/openbsd-compat/openbsd-compat.h @@ -47,6 +47,15 @@ #define SIMPLEQ_CONCAT(head1, head2) \ STAILQ_CONCAT(head1, head2) +/* + * + */ +#define open(...) open_posix(__VA_ARGS__) +#define openat(...) openat_posix(__VA_ARGS__) + +int open_posix(const char *path, int flags, ...); +int openat_posix(int fd, const char *path, int flags, ...); + /* * */ diff --git a/devel/got/files/patch-got_got.c b/devel/got/files/patch-got_got.c index 6cf6cdd2adfe..894e001416d3 100644 --- a/devel/got/files/patch-got_got.c +++ b/devel/got/files/patch-got_got.c @@ -10,24 +10,6 @@ if (Vflag) { got_version_print_str(); -@@ -4022,7 +4023,7 @@ print_diff(void *arg, unsigned char status, unsigned c - if (dirfd != -1) { - fd = openat(dirfd, de_name, O_RDONLY | O_NOFOLLOW); - if (fd == -1) { -- if (errno != ELOOP) { -+ if (errno != ELOOP && errno != EMLINK) { - err = got_error_from_errno2("openat", - abspath); - goto done; -@@ -4035,7 +4036,7 @@ print_diff(void *arg, unsigned char status, unsigned c - } else { - fd = open(abspath, O_RDONLY | O_NOFOLLOW); - if (fd == -1) { -- if (errno != ELOOP) { -+ if (errno != ELOOP && errno != EMLINK) { - err = got_error_from_errno2("open", - abspath); - goto done; @@ -9421,11 +9422,11 @@ cat_commit(struct got_object_id *id, struct got_reposi } fprintf(outfile, "%s%s %lld +0000\n", GOT_COMMIT_LABEL_AUTHOR, diff --git a/devel/got/files/patch-lib_object__create.c b/devel/got/files/patch-lib_object__create.c index d2fa398302ae..7c360b29acc8 100644 --- a/devel/got/files/patch-lib_object__create.c +++ b/devel/got/files/patch-lib_object__create.c @@ -1,14 +1,5 @@ --- lib/object_create.c.orig 2020-09-25 11:58:47 UTC +++ lib/object_create.c -@@ -131,7 +131,7 @@ got_object_blob_file_create(struct got_object_id **id, - - fd = open(ondisk_path, O_RDONLY | O_NOFOLLOW); - if (fd == -1) { -- if (errno != ELOOP) -+ if (errno != ELOOP && errno != EMLINK) - return got_error_from_errno2("open", ondisk_path); - - if (lstat(ondisk_path, &sb) == -1) { @@ -144,7 +144,7 @@ got_object_blob_file_create(struct got_object_id **id, } diff --git a/devel/got/files/patch-lib_worktree.c b/devel/got/files/patch-lib_worktree.c deleted file mode 100644 index dccdde2eff96..000000000000 --- a/devel/got/files/patch-lib_worktree.c +++ /dev/null @@ -1,50 +0,0 @@ ---- lib/worktree.c.orig 2020-09-25 11:58:47 UTC -+++ lib/worktree.c -@@ -1227,7 +1227,7 @@ replace_existing_symlink(const char *ondisk_path, cons - */ - fd = open(ondisk_path, O_RDWR | O_EXCL | O_NOFOLLOW); - if (fd == -1) { -- if (errno != ELOOP) -+ if (errno != ELOOP && errno != EMLINK) - return got_error_from_errno2("open", ondisk_path); - - /* We are updating an existing on-disk symlink. */ -@@ -1703,9 +1703,9 @@ get_file_status(unsigned char *status, struct stat *sb - } - } else { - fd = open(abspath, O_RDONLY | O_NOFOLLOW); -- if (fd == -1 && errno != ENOENT && errno != ELOOP) -+ if (fd == -1 && errno != ENOENT && errno != ELOOP && errno != EMLINK) - return got_error_from_errno2("open", abspath); -- else if (fd == -1 && errno == ELOOP) { -+ else if (fd == -1 && (errno == ELOOP || errno == EMLINK)) { - if (lstat(abspath, sb) == -1) - return got_error_from_errno2("lstat", abspath); - } else if (fd == -1 || fstat(fd, sb) == -1) { -@@ -3518,7 +3518,7 @@ worktree_status(struct got_worktree *worktree, const c - fd = open(ondisk_path, O_RDONLY | O_NOFOLLOW | O_DIRECTORY); - if (fd == -1) { - if (errno != ENOTDIR && errno != ENOENT && errno != EACCES && -- errno != ELOOP) -+ errno != ELOOP && errno != EMLINK) - err = got_error_from_errno2("open", ondisk_path); - else - err = report_single_file_status(path, ondisk_path, -@@ -4190,7 +4190,7 @@ create_patched_content(char **path_outfile, int revers - if (dirfd2 != -1) { - fd2 = openat(dirfd2, de_name2, O_RDONLY | O_NOFOLLOW); - if (fd2 == -1) { -- if (errno != ELOOP) { -+ if (errno != ELOOP && errno != EMLINK) { - err = got_error_from_errno2("openat", path2); - goto done; - } -@@ -4204,7 +4204,7 @@ create_patched_content(char **path_outfile, int revers - } else { - fd2 = open(path2, O_RDONLY | O_NOFOLLOW); - if (fd2 == -1) { -- if (errno != ELOOP) { -+ if (errno != ELOOP && errno != EMLINK) { - err = got_error_from_errno2("open", path2); - goto done; - }