From f8369be0c2fb7941156cf6f5a1143c5f91c5eb1a Mon Sep 17 00:00:00 2001
From: Francesco Colista <fcolista@alpinelinux.org>
Date: Thu, 3 May 2018 18:23:08 +0000
Subject: [PATCH] testing/snapper: new aport

---
 testing/snapper/APKBUILD                    | 76 +++++++++++++++++++++
 testing/snapper/fix-poll_h.patch            | 13 ++++
 testing/snapper/musl-__isleap.patch         | 19 ++++++
 testing/snapper/musl-_nl_msg_cat_cntr.patch | 51 ++++++++++++++
 testing/snapper/musl-boost.patch            | 49 +++++++++++++
 testing/snapper/musl-mktime.patch           | 15 ++++
 testing/snapper/musl-mode_t.patch           | 12 ++++
 testing/snapper/musl-posix.patch            | 21 ++++++
 testing/snapper/musl-stdout_stderr.patch    | 15 ++++
 testing/snapper/musl-types.patch            | 13 ++++
 testing/snapper/remove-systemd.patch        | 21 ++++++
 11 files changed, 305 insertions(+)
 create mode 100644 testing/snapper/APKBUILD
 create mode 100644 testing/snapper/fix-poll_h.patch
 create mode 100644 testing/snapper/musl-__isleap.patch
 create mode 100644 testing/snapper/musl-_nl_msg_cat_cntr.patch
 create mode 100644 testing/snapper/musl-boost.patch
 create mode 100644 testing/snapper/musl-mktime.patch
 create mode 100644 testing/snapper/musl-mode_t.patch
 create mode 100644 testing/snapper/musl-posix.patch
 create mode 100644 testing/snapper/musl-stdout_stderr.patch
 create mode 100644 testing/snapper/musl-types.patch
 create mode 100644 testing/snapper/remove-systemd.patch

diff --git a/testing/snapper/APKBUILD b/testing/snapper/APKBUILD
new file mode 100644
index 000000000000..162194b9a472
--- /dev/null
+++ b/testing/snapper/APKBUILD
@@ -0,0 +1,76 @@
+# Contributor: Francesco Colista <fcolista@alpinelinux.org>
+# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
+pkgname=snapper
+pkgver=0.5.4
+pkgrel=0
+pkgdesc="Manage filesystem snapshots and allow undo of system modifications"
+url="https://snapper.io"
+arch="all"
+license="GPL"
+# 3 tests are failing
+options="!check"
+makedepends="automake autoconf libtool bash
+	btrfs-progs-dev e2fsprogs-dev dbus-dev acl-dev 
+	lvm2-dev libxml2-dev boost-dev bsd-compat-headers
+	boost-thread gettext-dev libxslt docbook-xsl"
+subpackages="$pkgname-dev $pkgname-doc $pkgname-lang"
+source="$pkgname-$pkgver.tar.gz::https://github.com/openSUSE/snapper/archive/v$pkgver.tar.gz
+	musl-posix.patch
+	musl-mode_t.patch
+	musl-mktime.patch
+	musl-stdout_stderr.patch
+	musl-_nl_msg_cat_cntr.patch
+	musl-__isleap.patch
+	musl-types.patch
+	musl-boost.patch
+	remove-systemd.patch
+	fix-poll_h.patch"
+
+builddir="$srcdir/$pkgname-$pkgver"
+
+prepare() {
+	default_prepare
+	autoreconf -fi
+    # rename cron scripts
+    sed -i -e 's@suse.de-@@g' scripts/Makefile.am
+    # fix config location in cron scripts
+    sed -i -e 's@/etc/sysconfig/@/etc/conf.d/@g' scripts/snapper-daily
+    sed -i -e 's@/etc/sysconfig/@/etc/conf.d/@g' scripts/snapper-hourly
+}
+
+build() {
+	cd "$builddir"
+	export LDFLAGS="$LDFLAGS -lintl"
+	./configure \
+		--build=$CBUILD \
+		--host=$CHOST \
+		--prefix=/usr \
+		--sbindir=/usr/sbin \
+		--disable-silent-rules \
+		--with-conf=/etc/conf.d \
+		--disable-pam \
+		--disable-zypp
+	make
+}
+
+check() {
+	cd "$builddir"
+	make check
+}
+
+package() {
+	cd "$builddir"
+	make DESTDIR="$pkgdir" install
+}
+
+sha512sums="fab50b09c46e0a45c81efa26b05b5898b0ec8e7e89da9c7db1014b204e9f50f829c6573d606b44e647a868961529f0cee7ac994e04e17d6ce58c2300d23d5288  snapper-0.5.4.tar.gz
+f6da045474d6d4836d62c57e5db445bc790c2c1d1e9336edabcb62164eed1790db7870b343c66835e7e5b12b740bf0a18dc0da0259ad22616bd4eafc85f81a80  musl-posix.patch
+ddcd279f77007fe905df27b904dc84c8c2eebf0cf42c9f992fdc992e2912ddaab59712c13a798243c4f81727c04ef8e0993773686ab0c682e41726a2bcad962b  musl-mode_t.patch
+57479b51c821f880c2fc6d50ac59a3f9c2dc49a1da509e643a4e3f93491fb50220b97cacf0c09943b5b3b9cce531a3d5d11b8d0d146aa06ef21c1acb139cb193  musl-mktime.patch
+ed393b476a679ebc8f130e34826958a30aa98dc7ac77c0c324a486cc3ed8539584552a305e2ddcb810626c6ab3478e634c77762395e2560abc935cd18e882beb  musl-stdout_stderr.patch
+d5305df362df7db3b882cb491d32d11f479d1d56b21a39bc5e0cbdf7cdf70341eb566e7374bb9acc6d4fa1db027d4f009857fed21ef48ed311efaaa1be7b6329  musl-_nl_msg_cat_cntr.patch
+8278c469def65e58cb2aee039882d1d237b4b404386472f9540da11a1d3cddd60dda08a99074f9f418b328ce2c4ac73d3190a74a6fe3e00eab9adb4fed87a4ec  musl-__isleap.patch
+8bc2b42bbee927ce88f77e71a9594da3b6e54e92008e5603c6d8db35b3ec37add456bcc52d7d6a913c69a395c73bd3f6a3934ea549d4cc0097cb65613f61ed48  musl-types.patch
+03fba131b3beca83cbe9432c4d297757dfa0d3f6172690c361860c19feae48b96fba625238118e5c3eec55385ab4b85faf6143507f3d12171a6870dc65844ed3  musl-boost.patch
+719c0dbc8c9c008928a496184a7d22d08afd25ababede62d73bf4df09d32e3f1ca92cab4437d73b183f9faefdfeeab69ec324ed4d3d0ce6c7647d85ef8bfb653  remove-systemd.patch
+2730b5d3d627e5d6140df1509a4676e4a8429f73a12804b88f0ef7dab46097f35ac209f3456bb0094a09843ebb810887a6392c3a6a308d27f43f2ea9621e586d  fix-poll_h.patch"
diff --git a/testing/snapper/fix-poll_h.patch b/testing/snapper/fix-poll_h.patch
new file mode 100644
index 000000000000..74de79892adb
--- /dev/null
+++ b/testing/snapper/fix-poll_h.patch
@@ -0,0 +1,13 @@
+The correct location is <poll.h>, not <sys/poll.h>
+
+--- a/snapper/SystemCmd.h	2014-02-05 14:22:06.000000000 +0100
++++ b/snapper/SystemCmd.h	2015-08-30 10:56:03.685179465 +0200
+@@ -23,7 +23,7 @@
+ #ifndef SNAPPER_SYSTEM_CMD_H
+ #define SNAPPER_SYSTEM_CMD_H
+ 
+-#include <sys/poll.h>
++#include <poll.h>
+ #include <stdio.h>
+ 
+ #include <string>
diff --git a/testing/snapper/musl-__isleap.patch b/testing/snapper/musl-__isleap.patch
new file mode 100644
index 000000000000..5997247cf1f6
--- /dev/null
+++ b/testing/snapper/musl-__isleap.patch
@@ -0,0 +1,19 @@
+The macro __isleap() is defined in glibc's time.h
+If it is not defined, define it the same (for musl libc).
+
+--- a/client/utils/equal-date.h	2014-12-11 18:21:17.000000000 +0100
++++ b/client/utils/equal-date.h	2015-08-30 11:18:08.181207315 +0200
+@@ -19,6 +19,13 @@
+  * find current contact information at www.novell.com.
+  */
+ 
++#if !defined(__isleap)
++/* Nonzero if YEAR is a leap year (every 4 years,
++   except every 100th isn't, and every 400th is).  */
++# define __isleap(year)	\
++  ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
++#endif
++
+ 
+ bool
+ equal_year(const struct tm& tmp1, const struct tm& tmp2);
diff --git a/testing/snapper/musl-_nl_msg_cat_cntr.patch b/testing/snapper/musl-_nl_msg_cat_cntr.patch
new file mode 100644
index 000000000000..d3f71064fe83
--- /dev/null
+++ b/testing/snapper/musl-_nl_msg_cat_cntr.patch
@@ -0,0 +1,51 @@
+There is no _nl_msg_cat_cntr in musl libc and optimizations
+based upon its unchanged value are not possible.
+
+--- a/snapper/Regex.cc	2014-01-29 16:48:30.000000000 +0100
++++ b/snapper/Regex.cc	2015-08-30 11:07:34.613193993 +0200
+@@ -22,7 +22,9 @@
+ 
+ #include "snapper/Regex.h"
+ 
++#if defined(__GLIBC__)
+ extern int _nl_msg_cat_cntr;
++#endif
+ 
+ 
+ namespace snapper
+@@ -34,7 +36,9 @@
+       nm (cflags & REG_NOSUB ? 0 : nm)
+ {
+     regcomp (&rx, pattern, cflags);
++#if defined(__GLIBC__)
+     my_nl_msg_cat_cntr = _nl_msg_cat_cntr;
++#endif
+     rm = new regmatch_t[nm];
+ }
+ 
+@@ -45,7 +49,9 @@
+       nm (cflags & REG_NOSUB ? 0 : nm)
+ {
+     regcomp (&rx, pattern.c_str (), cflags);
++#if defined(__GLIBC__)
+     my_nl_msg_cat_cntr = _nl_msg_cat_cntr;
++#endif
+     rm = new regmatch_t[nm];
+ }
+ 
+@@ -60,11 +66,15 @@
+ bool
+ Regex::match (const string& str, int eflags) const
+ {
++#if defined(__GLIBC__)
+     if (my_nl_msg_cat_cntr != _nl_msg_cat_cntr) {
++#endif
+ 	regfree (&rx);
+ 	regcomp (&rx, pattern.c_str (), cflags);
++#if defined(__GLIBC__)
+ 	my_nl_msg_cat_cntr = _nl_msg_cat_cntr;
+     }
++#endif
+ 
+     last_str = str;
+ 
diff --git a/testing/snapper/musl-boost.patch b/testing/snapper/musl-boost.patch
new file mode 100644
index 000000000000..a4e9177bcfeb
--- /dev/null
+++ b/testing/snapper/musl-boost.patch
@@ -0,0 +1,49 @@
+diff --git a/examples/c++-lib/Makefile.am b/examples/c++-lib/Makefile.am
+index 52c81e5..715de51 100644
+--- a/examples/c++-lib/Makefile.am
++++ b/examples/c++-lib/Makefile.am
+@@ -5,7 +5,7 @@
+ AM_CPPFLAGS = -I$(top_srcdir)
+ 
+ LDADD = ../../snapper/libsnapper.la
+-AM_LDFLAGS = -lboost_system
++AM_LDFLAGS = -lboost_system-mt
+ 
+ noinst_PROGRAMS = List ListAll Create CmpDirs CreateNumber CreateTimeline
+ 
+diff --git a/server/Makefile.am b/server/Makefile.am
+index 2a6a4c2..e007710 100644
+--- a/server/Makefile.am
++++ b/server/Makefile.am
+@@ -14,4 +14,4 @@ snapperd_SOURCES =					\
+ 	Types.cc		Types.h
+ 
+ snapperd_LDADD = ../snapper/libsnapper.la ../dbus/libdbus.la -lrt
+-snapperd_LDFLAGS = -lboost_system -lboost_thread
++snapperd_LDFLAGS = -lboost_system-mt -lboost_thread-mt
+diff --git a/testsuite-cmp/Makefile.am b/testsuite-cmp/Makefile.am
+index 81104bf..d88644e 100644
+--- a/testsuite-cmp/Makefile.am
++++ b/testsuite-cmp/Makefile.am
+@@ -3,7 +3,7 @@
+ #
+ 
+ AM_CPPFLAGS = -I$(top_srcdir)
+-AM_LDFLAGS = -lboost_system
++AM_LDFLAGS = -lboost_system-mt
+ 
+ LDADD = ../snapper/libsnapper.la
+ 
+diff --git a/snapper/Makefile.am b/snapper/Makefile.am
+index 36467da..cb05a3b 100644
+--- a/snapper/Makefile.am
++++ b/snapper/Makefile.am
+@@ -62,7 +62,7 @@ libsnapper_la_SOURCES +=				\
+ endif
+ 
+ libsnapper_la_LDFLAGS = -version-info @LIBVERSION_INFO@
+-libsnapper_la_LIBADD = -lboost_thread -lboost_system -lxml2 -lacl -lz -lm
++libsnapper_la_LIBADD = -lboost_thread-mt -lboost_system-mt -lxml2 -lacl -lz -lm
+ if ENABLE_ROLLBACK
+ libsnapper_la_LIBADD += -lmount
+ endif
diff --git a/testing/snapper/musl-mktime.patch b/testing/snapper/musl-mktime.patch
new file mode 100644
index 000000000000..48fbc0802e5f
--- /dev/null
+++ b/testing/snapper/musl-mktime.patch
@@ -0,0 +1,15 @@
+According to http://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_chapter/libc_21.html
+timelocal(2) is functionally identical to mktime(2), but more
+mnemonically named. There is no timelocal(2) defined in musl libc.
+
+--- a/snapper/AppUtil.cc	2015-02-18 18:54:03.000000000 +0100
++++ b/snapper/AppUtil.cc	2015-08-30 10:39:31.318158599 +0200
+@@ -274,7 +274,7 @@
+ 	const char* p = strptime(str.c_str(), "%F %T", &s);
+ 	if (!p || *p != '\0')
+ 	    return (time_t)(-1);
+-	return utc ? timegm(&s) : timelocal(&s);
++	return utc ? timegm(&s) : mktime(&s);
+     }
+ 
+ 
diff --git a/testing/snapper/musl-mode_t.patch b/testing/snapper/musl-mode_t.patch
new file mode 100644
index 000000000000..3c9b6e20074b
--- /dev/null
+++ b/testing/snapper/musl-mode_t.patch
@@ -0,0 +1,12 @@
+The mode_t type is defined in fcntl.h
+
+--- a/snapper/FileUtils.h	2015-02-18 18:54:03.000000000 +0100
++++ b/snapper/FileUtils.h	2015-08-30 10:45:43.285166420 +0200
+@@ -24,6 +24,7 @@
+ #define SNAPPER_FILE_UTILS_H
+ 
+ 
++#include <fcntl.h>
+ #include <string>
+ #include <vector>
+ #include <functional>
diff --git a/testing/snapper/musl-posix.patch b/testing/snapper/musl-posix.patch
new file mode 100644
index 000000000000..248ea74374b4
--- /dev/null
+++ b/testing/snapper/musl-posix.patch
@@ -0,0 +1,21 @@
+diff --git a/snapper/AppUtil.cc b/snapper/AppUtil.cc
+index 052235d..ab81983 100644
+--- a/snapper/AppUtil.cc
++++ b/snapper/AppUtil.cc
+@@ -223,16 +223,10 @@ namespace snapper
+     string
+     stringerror(int errnum)
+     {
+-#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+ 	char buf1[100];
+ 	if (strerror_r(errno, buf1, sizeof(buf1)-1) == 0)
+ 	    return string(buf1);
+ 	return string("strerror failed");
+-#else
+-	char buf1[100];
+-	const char* buf2 = strerror_r(errno, buf1, sizeof(buf1)-1);
+-	return string(buf2);
+-#endif
+     }
+ 
+ 
diff --git a/testing/snapper/musl-stdout_stderr.patch b/testing/snapper/musl-stdout_stderr.patch
new file mode 100644
index 000000000000..b53a15581b69
--- /dev/null
+++ b/testing/snapper/musl-stdout_stderr.patch
@@ -0,0 +1,15 @@
+In musl libc stdout and stderr are macros, thus we need to
+undefine them to be able to use SystemCmd::stdout() and ::stderr()
+members without renaming them - which may be a better choice.
+
+--- a/snapper/SystemCmd.h	2015-08-30 10:59:53.740184303 +0200
++++ b/snapper/SystemCmd.h	2015-08-30 11:02:34.229187677 +0200
+@@ -31,6 +31,8 @@
+ #include <list>
+ #include <boost/noncopyable.hpp>
+ 
++#undef stdout
++#undef stderr
+ 
+ namespace snapper
+ {
diff --git a/testing/snapper/musl-types.patch b/testing/snapper/musl-types.patch
new file mode 100644
index 000000000000..11a7896f823d
--- /dev/null
+++ b/testing/snapper/musl-types.patch
@@ -0,0 +1,13 @@
+diff --git a/snapper/Snapshot.h b/snapper/Snapshot.h
+index 776dabf..ab89fc7 100644
+--- a/snapper/Snapshot.h
++++ b/snapper/Snapshot.h
+@@ -26,6 +26,7 @@
+ 
+ 
+ #include <time.h>
++#include <sys/types.h>
+ #include <string>
+ #include <list>
+ #include <map>
+ 
diff --git a/testing/snapper/remove-systemd.patch b/testing/snapper/remove-systemd.patch
new file mode 100644
index 000000000000..5f39a3a254c0
--- /dev/null
+++ b/testing/snapper/remove-systemd.patch
@@ -0,0 +1,21 @@
+diff --git a/data/Makefile.am b/data/Makefile.am
+index e2036ba..0af20ff 100644
+--- a/data/Makefile.am
++++ b/data/Makefile.am
+@@ -18,16 +18,6 @@ install-data-local:
+ 	install -D -m 644 lvm.txt $(DESTDIR)/etc/snapper/filters/lvm.txt
+ 	install -D -m 644 x11.txt $(DESTDIR)/etc/snapper/filters/x11.txt
+ 
+-	install -D -m 644 org.opensuse.Snapper.conf $(DESTDIR)/etc/dbus-1/system.d/org.opensuse.Snapper.conf
+-	install -D -m 644 org.opensuse.Snapper.service $(DESTDIR)/usr/share/dbus-1/system-services/org.opensuse.Snapper.service
+-
+-	install -D -m 644 timeline.service $(DESTDIR)/usr/lib/systemd/system/snapper-timeline.service
+-	install -D -m 644 timeline.timer $(DESTDIR)/usr/lib/systemd/system/snapper-timeline.timer
+-	install -D -m 644 cleanup.service $(DESTDIR)/usr/lib/systemd/system/snapper-cleanup.service
+-	install -D -m 644 cleanup.timer $(DESTDIR)/usr/lib/systemd/system/snapper-cleanup.timer
+-	install -D -m 644 boot.service $(DESTDIR)/usr/lib/systemd/system/snapper-boot.service
+-	install -D -m 644 boot.timer $(DESTDIR)/usr/lib/systemd/system/snapper-boot.timer
+-
+ if HAVE_ZYPP
+ 	install -D -m 644 zypp-plugin.conf $(DESTDIR)/etc/snapper/zypp-plugin.conf
+ endif
-- 
GitLab