From 03729a1ecb3920dde8f256217a832bd0220d331eb545e39e137ec60383a644d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Wed, 13 Mar 2019 10:05:44 +0000 Subject: [PATCH] Accepting request 684638 from home:coolo:branches:openSUSE:Factory - my attempt to rewrite %post in lua (bsc#1129036) OBS-URL: https://build.opensuse.org/request/show/684638 OBS-URL: https://build.opensuse.org/package/show/system:packagemanager/dpkg?expand=0&rev=69 --- update-alternatives.changes | 5 +++++ update-alternatives.spec | 32 ++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/update-alternatives.changes b/update-alternatives.changes index 7496393..ce1f6d3 100644 --- a/update-alternatives.changes +++ b/update-alternatives.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Wed Mar 13 09:15:51 UTC 2019 - Stephan Kulow + +- my attempt to rewrite %post in lua (bsc#1129036) + ------------------------------------------------------------------- Mon Jan 14 15:49:09 CET 2019 - kukuk@suse.de diff --git a/update-alternatives.spec b/update-alternatives.spec index b23368a..5b4cf99 100644 --- a/update-alternatives.spec +++ b/update-alternatives.spec @@ -31,8 +31,6 @@ BuildRequires: automake BuildRequires: libtool BuildRequires: ncurses-devel BuildRequires: pkgconfig -Requires(post): coreutils -Requires(post): update-alternatives Provides: alternatives = %{version} %description @@ -71,18 +69,24 @@ install -pm 0755 utils/%{name} %{buildroot}/%{_sbindir} ln -s %{name} %{buildroot}/%{_sbindir}/alternatives install -pm 0644 man/%{name}.1 %{buildroot}/%{_mandir}/man1/ -%post -# Migrate to new location -if [ -d var/lib/rpm/alternatives ]; then - echo "migrating update alternatives database to new location" - # We proceed even if no alternatives directory exists, such situation - # occurs in buildroot environment (we can't buildrequire package - # itself). - mv -f var/lib/rpm/alternatives/* %{_localstatedir}/lib/alternatives/ || : - rmdir var/lib/rpm/alternatives ||: -fi - -touch %{_localstatedir}/log/alternatives.log +%post -p +-- Migrate to new location +if posix.access('var/lib/rpm/alternatives', 'x') then + print("migrating update alternatives database to new location") + -- We proceed even if no alternatives directory exists, such situation + -- occurs in buildroot environment + new_location=rpm.expand('%{_localstatedir}/lib/alternatives/') + for i,old_file in pairs(posix.dir("var/lib/rpm/alternatives/")) do + print(old_file.."\n") + new_file = string.gsub(old_file, "(.*/)(.*)", new_location .. "%2") + print(new_file.."\n") + os.rename(old_file, new_file) + end + posix.rmdir('var/lib/rpm/alternatives') +end +-- touch file +new_file = io.open(rpm.expand('%{_localstatedir}/log/alternatives.log'), "w") +new_file.close() %files %license COPYING