git: bd04537abb28 - main - archivers/py-borgbackup: unbreak on FreeBSD 13

From: Matthias Andree <mandree_at_FreeBSD.org>
Date: Fri, 26 Jul 2024 13:49:45 UTC
The branch main has been updated by mandree:

URL: https://cgit.FreeBSD.org/ports/commit/?id=bd04537abb28059580c84440c56a952d76067bd1

commit bd04537abb28059580c84440c56a952d76067bd1
Author:     Matthias Andree <mandree@FreeBSD.org>
AuthorDate: 2024-07-26 13:23:06 +0000
Commit:     Matthias Andree <mandree@FreeBSD.org>
CommitDate: 2024-07-26 13:43:31 +0000

    archivers/py-borgbackup: unbreak on FreeBSD 13
    
    import acl_extended_file_np.c from src/lib/libc/posix1e,
    taken from FreeBSD src branch as of 559a218c9b25, 2023-11-01T16:43:37Z
    and tell Cython to include it on FreeBSD before 1400033,
    i. e., before FreeBSD's libc had it.
    
    This fixes https://github.com/borgbackup/borg/issues/8269 and
    makes it unnecessary to look into
    PR:             280453
---
 UPDATING                                           | 10 +--
 archivers/py-borgbackup/Makefile                   | 21 ++++--
 .../py-borgbackup/files/acl_extended_file_np.c     | 83 ++++++++++++++++++++++
 archivers/py-borgbackup/files/extrapatch-setup.py  | 11 +++
 4 files changed, 116 insertions(+), 9 deletions(-)

diff --git a/UPDATING b/UPDATING
index b7a2281d0b74..79e0ecf9a398 100644
--- a/UPDATING
+++ b/UPDATING
@@ -5,15 +5,15 @@ they are unavoidable.
 You should get into the habit of checking this file for changes each time
 you update your ports collection, before attempting any port upgrades.
 
-20240724:
+20240726:
   AFFECTS: users of archivers/py-borgbackup
   AUTHOR: mandree@FreeBSD.org
 
-  Borgbackup has been upgraded to version 1.4.0, which does not yet
-  support FreeBSD 13.x, see https://github.com/borgbackup/borg/issues/8269
+  Borgbackup has been upgraded to version 1.4.0.
+  The FreeBSD port as of 2024-07-26 reinstates FreeBSD 13 compatibility.
 
-  For users who are on FreeBSD 13, or who wish to continue using
-  version 1.2, use either of these commands for upgrading:
+  For users who wish to continue using version 1.2,
+  use either of these commands for upgrading:
 
   With binary packages through pkg:
     pkg set -o archivers/py-borgbackup:archivers/py-borgbackup12
diff --git a/archivers/py-borgbackup/Makefile b/archivers/py-borgbackup/Makefile
index 774f1033d9cf..054fa3ee234d 100644
--- a/archivers/py-borgbackup/Makefile
+++ b/archivers/py-borgbackup/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	borgbackup
 DISTVERSION=	1.4.0
-PORTREVISION=	0
+PORTREVISION=	1
 CATEGORIES=	archivers python
 MASTER_SITES=	PYPI
 PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
@@ -12,8 +12,6 @@ WWW=		https://pypi.org/project/borgbackup/
 LICENSE=	BSD3CLAUSE
 LICENSE_FILE=	${WRKSRC}/LICENSE
 
-BROKEN_FreeBSD_13= uses acl_extended_link_np, see https://github.com/borgbackup/borg/issues/8269
-
 # note that borgbackup pins the msgpack version range per patchlevel version!
 _BB_DEPENDS=	${PYTHON_PKGNAMEPREFIX}msgpack>=1.0.2<1.1.0:devel/py-msgpack@${PY_FLAVOR}
 BUILD_DEPENDS=	${PYTHON_PKGNAMEPREFIX}pkgconfig>=0:devel/py-pkgconfig@${PY_FLAVOR} \
@@ -39,6 +37,21 @@ OPTIONS_DEFAULT=	FUSE
 FUSE_DESC=	Support to mount locally borg backup files
 FUSE_RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}llfuse>0:devel/py-llfuse@${PY_FLAVOR}
 
+.include <bsd.port.pre.mk>
+
+.if (${OPSYS} == FreeBSD) && ${OSVERSION} < 1400033 # why 1400033?
+# 1. check for the OLDEST (last in list) history entry on the file, when it was added:
+#    git -C /usr/src hist lib/libc/posix1e/acl_extended_file_np.c
+# 2. check for the version you have obtained what __FreeBSD_version was
+#    and increment by one. This is inaccurate for the interim between file addition
+#    and __FreeBSD_version bump back then, but those versions were no releases and
+#    should no longer be in the field.
+EXTRA_PATCHES	+= ${FILESDIR}/extrapatch-setup.py
+post-patch:
+	${CP} ${FILESDIR}/acl_extended_file_np.c ${WRKSRC}/src/borg/platform/
+.endif
+
+
 _BORGHOME=${WRKDIR}/testhome
 _BORGENV=-i BORG_PASSPHRASE=secret123 PYTHONPATH=${STAGEDIR}${PYTHON_SITELIBDIR} HOME=${_BORGHOME}
 post-install:
@@ -71,4 +84,4 @@ post-install:
 do-test:
 	cd ${WRKSRC} && ${SETENV} ${_BORGENV} ${TEST_ENV} tox-${PYTHON_VER} -e ${PY_FLAVOR} -vv
 
-.include <bsd.port.mk>
+.include <bsd.port.post.mk>
diff --git a/archivers/py-borgbackup/files/acl_extended_file_np.c b/archivers/py-borgbackup/files/acl_extended_file_np.c
new file mode 100644
index 000000000000..269ceeb56fe7
--- /dev/null
+++ b/archivers/py-borgbackup/files/acl_extended_file_np.c
@@ -0,0 +1,83 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Gleb Popov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* taken from FreeBSD src branch as of 559a218c9b25 Wed Nov 1 16:43:37 2023 -0600 */
+/*
+ * acl_extended_file_np: Check if the file has extended ACLs set.
+ */
+
+#include <sys/param.h>
+#include <sys/errno.h>
+#include <sys/acl.h>
+
+#include <unistd.h>
+
+typedef acl_t (*acl_get_func)(const char *, acl_type_t);
+typedef long (*pathconf_func)(const char *, int);
+
+static int
+_acl_extended_file(acl_get_func f, pathconf_func pathconf_f, const char* path_p);
+
+int
+acl_extended_file_np(const char *path_p)
+{
+	return (_acl_extended_file(acl_get_file, pathconf, path_p));
+}
+
+int
+acl_extended_file_nofollow_np(const char *path_p)
+{
+	return (_acl_extended_file(acl_get_link_np, lpathconf, path_p));
+}
+
+int
+acl_extended_link_np(const char *path_p)
+{
+	return (_acl_extended_file(acl_get_link_np, lpathconf, path_p));
+}
+
+int
+_acl_extended_file(acl_get_func acl_get, pathconf_func pathconf_f, const char* path_p)
+{
+	acl_t acl;
+	int retval, istrivial, acltype = ACL_TYPE_ACCESS;
+
+	retval = pathconf_f(path_p, _PC_ACL_NFS4);
+	if (retval > 0)
+		acltype = ACL_TYPE_NFS4;
+
+	acl = acl_get(path_p, acltype);
+	if (acl == NULL)
+		return (-1);
+
+	retval = acl_is_trivial_np(acl, &istrivial);
+	acl_free(acl);
+	if (retval == -1)
+		return (-1);
+
+	return (!istrivial);
+}
diff --git a/archivers/py-borgbackup/files/extrapatch-setup.py b/archivers/py-borgbackup/files/extrapatch-setup.py
new file mode 100644
index 000000000000..f0128d2bb589
--- /dev/null
+++ b/archivers/py-borgbackup/files/extrapatch-setup.py
@@ -0,0 +1,11 @@
+--- setup.py.orig	2024-07-02 22:06:38 UTC
++++ setup.py
+@@ -181,7 +181,7 @@ if not on_rtd:
+     syncfilerange_ext = Extension(
+         "borg.platform.syncfilerange", [platform_syncfilerange_source], extra_compile_args=cflags
+     )
+-    freebsd_ext = Extension("borg.platform.freebsd", [platform_freebsd_source], extra_compile_args=cflags)
++    freebsd_ext = Extension("borg.platform.freebsd", [platform_freebsd_source, 'src/borg/platform/acl_extended_file_np.c'], extra_compile_args=cflags)
+     darwin_ext = Extension("borg.platform.darwin", [platform_darwin_source], extra_compile_args=cflags)
+     windows_ext = Extension("borg.platform.windows", [platform_windows_source], extra_compile_args=cflags)
+