Bug 1367587 - [PATCH] Adapt post/postun scripts to use atomic file replacement
Summary: [PATCH] Adapt post/postun scripts to use atomic file replacement
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: tmux
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Sven Lankes
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1352154
TreeView+ depends on / blocked
 
Reported: 2016-08-16 21:14 UTC by Colin Walters
Modified: 2016-10-28 11:39 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-10-28 11:39:51 UTC


Attachments (Terms of Use)

Description Colin Walters 2016-08-16 21:14:41 UTC
From 1ef0f170653b8eda10cab910c2b5fc5b5f241df0 Mon Sep 17 00:00:00 2001
From: Colin Walters <walters@verbum.org>
Date: Tue, 16 Aug 2016 17:12:58 -0400
Subject: [PATCH] Adapt post/postun scripts to use atomic file replacement

This ensures tmux works with rpm-ostree.  For more information,
see: https://bugzilla.redhat.com/show_bug.cgi?id=1352154
---
 tmux.spec | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tmux.spec b/tmux.spec
index 449bd64..5dd84c6 100644
--- a/tmux.spec
+++ b/tmux.spec
@@ -1,6 +1,6 @@
 Name:           tmux
 Version:        2.2
-Release:        3%{?dist}
+Release:        4%{?dist}
 Summary:        A terminal multiplexer
 
 Group:          Applications/System
@@ -38,18 +38,20 @@ install -Dpm 644 %{SOURCE1} %{buildroot}%{_datadir}/bash-completion/completions/
 %post
 if [ "$1" = 1 ]; then
   if [ ! -f %{_sysconfdir}/shells ] ; then
-    echo "%{_bindir}/tmux" > %{_sysconfdir}/shells
-    echo "/bin/tmux" >> %{_sysconfdir}/shells
-  else
-    grep -q "^%{_bindir}/tmux$" %{_sysconfdir}/shells || echo "%{_bindir}/tmux" >> %{_sysconfdir}/shells
-    grep -q "^/bin/tmux$" %{_sysconfdir}/shells || echo "/bin/tmux" >> %{_sysconfdir}/shells
+    touch %{_sysconfdir}/shells
   fi
+  for binpath in %{_bindir} /bin; do
+    if ! grep -q "^${binpath}/tmux$" %{_sysconfdir}/shells; then
+       (cat %{_sysconfdir}/shells; echo "$binpath/tmux") > %{_sysconfdir}/shells.new
+       mv %{_sysconfdir}/shells{.new,}
+    fi
+  done
 fi
 
 %postun
 if [ "$1" = 0 ] && [ -f %{_sysconfdir}/shells ] ; then
-  sed -i '\!^%{_bindir}/tmux$!d' %{_sysconfdir}/shells
-  sed -i '\!^/bin/tmux$!d' %{_sysconfdir}/shells
+    sed -e '\!^%{_bindir}/tmux$!d' -e '\!^/bin/tmux$!d' < %{_sysconfdir}/shells > %{_sysconfdir}/shells.new
+    mv %{_sysconfdir}/shells{.new,}
 fi
 
 %files
-- 
2.7.4

Comment 1 Sven Lankes 2016-10-28 11:39:51 UTC
Applied in latest rawhinde build.


Note You need to log in before you can comment on or make changes to this bug.