From: zmedico@gentoo.org
To: gentoo-portage-dev@lists.gentoo.org
Cc: Zac Medico <zmedico@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH 1/3] etc-update: symlink support for bug #485598
Date: Sun, 26 Oct 2014 04:12:14 -0700 [thread overview]
Message-ID: <1414321936-22851-1-git-send-email-zmedico@gentoo.org> (raw)
From: Zac Medico <zmedico@gentoo.org>
This includes numerous logic adjustments that are needed to support
protected symlinks. The show_diff function now supports arbitrary
file types. For example, a diff between two symlinks looks like this:
-SYM: /foo/bar -> baz
+SYM: /foo/bar -> blah
X-Gentoo-Bug: 485598
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=485598
---
bin/etc-update | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 85 insertions(+), 8 deletions(-)
diff --git a/bin/etc-update b/bin/etc-update
index 7ac6f0b..3c03d7a 100755
--- a/bin/etc-update
+++ b/bin/etc-update
@@ -51,11 +51,15 @@ do_mv_ln() {
local src=${@:$(( $# - 1 )):1}
local dst=${@:$(( $# - 0 )):1}
- if [[ -L ${dst} ]] ; then #330221
+ if [[ ! -L ${src} && -L ${dst} ]] ; then #330221
local lfile=$(readlink "${dst}")
[[ ${lfile} == /* ]] || lfile="${dst%/*}/${lfile}"
echo " Target is a symlink; replacing ${lfile}"
dst=${lfile}
+ elif [[ -d ${dst} && ! -L ${dst} ]] ; then
+ # If ${dst} is a directory, do not move the file
+ # inside of it if this fails.
+ rmdir "${dst}" || return
fi
mv "${opts[@]}" "${src}" "${dst}"
@@ -115,6 +119,24 @@ scan() {
continue 2
fi
done
+ if [[ -L ${file} ]] ; then
+ if [[ -L ${live_file} && \
+ $(readlink "${live_file}") == $(readlink "${file}") ]]
+ then
+ rm -f "${file}"
+ continue
+ fi
+ if [[ "${ofile:10}" != "${rfile:10}" ]] ||
+ [[ ${opath} != ${rpath} ]]
+ then
+ : $(( ++count ))
+ echo "${live_file}" > "${TMP}"/files/${count}
+ fi
+ echo "${cfg_file}" >> "${TMP}"/files/${count}
+ ofile="${rfile}"
+ opath="${rpath}"
+ continue
+ fi
if [[ ! -f ${file} ]] ; then
${QUIET} || echo "Skipping non-file ${file} ..."
continue
@@ -124,7 +146,9 @@ scan() {
[[ ${opath} != ${rpath} ]]
then
MATCHES=0
- if [[ ${eu_automerge} == "yes" ]] ; then
+ if ! [[ -f ${cfg_file} && -f ${live_file} ]] ; then
+ MATCHES=0
+ elif [[ ${eu_automerge} == "yes" ]] ; then
if [[ ! -e ${cfg_file} || ! -e ${live_file} ]] ; then
MATCHES=0
else
@@ -377,17 +401,48 @@ do_file() {
show_diff() {
clear
- local file1=$1 file2=$2
+ local file1=$1 file2=$2 files=("$1" "$2") \
+ diff_files=() file i tmpdir
+
+ if [[ -L ${file1} && ! -L ${file2} &&
+ -f ${file1} && -f ${file2} ]] ; then
+ # If a regular file replaces a symlink to a regular file, then
+ # show the diff between the regular files (bug #330221).
+ diff_files=("${file1}" "${file2}")
+ else
+ for i in 0 1 ; do
+ if [[ ! -L ${files[$i]} && -f ${files[$i]} ]] ; then
+ diff_files[$i]=${files[$i]}
+ continue
+ fi
+ [[ -n ${tmpdir} ]] || \
+ tmpdir=$(mktemp -d "${TMP}/symdiff-XXX")
+ diff_files[$i]=${tmpdir}/${i}
+ if [[ -L ${files[$i]} ]] ; then
+ echo "SYM: ${file1} -> $(readlink "${files[$i]}")" > \
+ "${diff_files[$i]}"
+ elif [[ -d ${files[$i]} ]] ; then
+ echo "DIR: ${file1}" > "${diff_files[$i]}"
+ elif [[ -p ${files[$i]} ]] ; then
+ echo "FIF: ${file1}" > "${diff_files[$i]}"
+ else
+ echo "DEV: ${file1}" > "${diff_files[$i]}"
+ fi
+ done
+ fi
+
if [[ ${using_editor} == 0 ]] ; then
(
echo "Showing differences between ${file1} and ${file2}"
- diff_command "${file1}" "${file2}"
+ diff_command "${diff_files[0]}" "${diff_files[1]}"
) | ${pager}
else
echo "Beginning of differences between ${file1} and ${file2}"
- diff_command "${file1}" "${file2}"
+ diff_command "${diff_files[0]}" "${diff_files[1]}"
echo "End of differences between ${file1} and ${file2}"
fi
+
+ [[ -n ${tmpdir} ]] && rm -rf "${tmpdir}"
}
do_cfg() {
@@ -395,14 +450,14 @@ do_cfg() {
local ofile=$2
local -i my_input=0
- until (( my_input == -1 )) || [ ! -f "${file}" ] ; do
+ until (( my_input == -1 )) || [[ ! -f ${file} && ! -L ${file} ]] ; do
if [[ "${OVERWRITE_ALL}" == "yes" ]] && ! user_special "${ofile}"; then
my_input=1
elif [[ "${DELETE_ALL}" == "yes" ]] && ! user_special "${ofile}"; then
my_input=2
else
show_diff "${ofile}" "${file}"
- if [[ -L ${file} ]] ; then
+ if [[ -L ${file} && ! -L ${ofile} ]] ; then
cat <<-EOF
-------------------------------------------------------------
@@ -461,6 +516,19 @@ do_merge() {
local ofile="${2}"
local mfile="${TMP}/${2}.merged"
local -i my_input=0
+
+ if [[ -L ${file} && -L ${ofile} ]] ; then
+ echo "Both files are symlinks, so they will not be merged."
+ return 0
+ elif [[ ! -f ${file} ]] ; then
+ echo "Non-regular file cannot be merged: ${file}"
+ return 0
+ elif [[ ! -f ${ofile} ]] ; then
+ echo "Non-regular file cannot be merged: ${ofile}"
+ return 0
+ fi
+
+
echo "${file} ${ofile} ${mfile}"
if [[ -e ${mfile} ]] ; then
@@ -533,9 +601,18 @@ do_distconf() {
for (( count = 0; count <= 9999; ++count )) ; do
suffix=$(printf ".dist_%04i" ${count})
efile="${ofile}${suffix}"
- if [[ ! -f ${efile} ]] ; then
+ if [[ ! -f ${efile} && ! -L ${efile} ]] ; then
mv ${mv_opts} "${file}" "${efile}"
break
+ elif [[ -L ${efile} && -L ${file} ]] ; then
+ if [[ $(readlink "${efile}") == $(readlink "${file}") ]] ; then
+ # replace identical copy
+ mv "${file}" "${efile}"
+ break
+ fi
+ elif [[ -L ${efile} || -L ${file} ]] ; then
+ # not the same file types
+ continue
elif diff_command "${file}" "${efile}" &> /dev/null; then
# replace identical copy
mv "${file}" "${efile}"
--
2.0.4
next reply other threads:[~2014-10-26 11:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-26 11:12 zmedico [this message]
2014-10-26 11:12 ` [gentoo-portage-dev] [PATCH 2/3] dispatch-conf: symlink support for bug #485598 zmedico
2014-10-26 11:12 ` [gentoo-portage-dev] [PATCH 3/3] CONFIG_PROTECT: protect symlinks, " zmedico
2014-10-27 8:08 ` Alexander Berntsen
2014-10-27 9:07 ` Zac Medico
2014-10-27 20:35 ` Zac Medico
2014-11-03 3:54 ` Brian Dolbec
2014-10-27 22:57 ` [gentoo-portage-dev] [PATCH 1/3] etc-update: symlink support for " Zac Medico
2014-10-27 23:04 ` [gentoo-portage-dev] [PATCH 2/3] dispatch-conf: " Zac Medico
2014-10-31 13:34 ` [gentoo-portage-dev] [PATCH] " Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1414321936-22851-1-git-send-email-zmedico@gentoo.org \
--to=zmedico@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox