1 |
This includes numerous logic adjustments that are needed to support |
2 |
protected symlinks. The show_diff function now supports arbitrary |
3 |
file types. For example, a diff between two symlinks looks like this: |
4 |
|
5 |
-SYM: /foo/bar -> baz |
6 |
+SYM: /foo/bar -> blah |
7 |
|
8 |
X-Gentoo-Bug: 485598 |
9 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=485598 |
10 |
--- |
11 |
This updated patch fixes show_diff to handle files that don't exist. These |
12 |
are displayed as "/dev/null". |
13 |
|
14 |
bin/etc-update | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- |
15 |
1 file changed, 87 insertions(+), 8 deletions(-) |
16 |
|
17 |
diff --git a/bin/etc-update b/bin/etc-update |
18 |
index 7ac6f0b..1d78e96 100755 |
19 |
--- a/bin/etc-update |
20 |
+++ b/bin/etc-update |
21 |
@@ -51,11 +51,15 @@ do_mv_ln() { |
22 |
local src=${@:$(( $# - 1 )):1} |
23 |
local dst=${@:$(( $# - 0 )):1} |
24 |
|
25 |
- if [[ -L ${dst} ]] ; then #330221 |
26 |
+ if [[ ! -L ${src} && -L ${dst} ]] ; then #330221 |
27 |
local lfile=$(readlink "${dst}") |
28 |
[[ ${lfile} == /* ]] || lfile="${dst%/*}/${lfile}" |
29 |
echo " Target is a symlink; replacing ${lfile}" |
30 |
dst=${lfile} |
31 |
+ elif [[ -d ${dst} && ! -L ${dst} ]] ; then |
32 |
+ # If ${dst} is a directory, do not move the file |
33 |
+ # inside of it if this fails. |
34 |
+ rmdir "${dst}" || return |
35 |
fi |
36 |
|
37 |
mv "${opts[@]}" "${src}" "${dst}" |
38 |
@@ -115,6 +119,24 @@ scan() { |
39 |
continue 2 |
40 |
fi |
41 |
done |
42 |
+ if [[ -L ${file} ]] ; then |
43 |
+ if [[ -L ${live_file} && \ |
44 |
+ $(readlink "${live_file}") == $(readlink "${file}") ]] |
45 |
+ then |
46 |
+ rm -f "${file}" |
47 |
+ continue |
48 |
+ fi |
49 |
+ if [[ "${ofile:10}" != "${rfile:10}" ]] || |
50 |
+ [[ ${opath} != ${rpath} ]] |
51 |
+ then |
52 |
+ : $(( ++count )) |
53 |
+ echo "${live_file}" > "${TMP}"/files/${count} |
54 |
+ fi |
55 |
+ echo "${cfg_file}" >> "${TMP}"/files/${count} |
56 |
+ ofile="${rfile}" |
57 |
+ opath="${rpath}" |
58 |
+ continue |
59 |
+ fi |
60 |
if [[ ! -f ${file} ]] ; then |
61 |
${QUIET} || echo "Skipping non-file ${file} ..." |
62 |
continue |
63 |
@@ -124,7 +146,9 @@ scan() { |
64 |
[[ ${opath} != ${rpath} ]] |
65 |
then |
66 |
MATCHES=0 |
67 |
- if [[ ${eu_automerge} == "yes" ]] ; then |
68 |
+ if ! [[ -f ${cfg_file} && -f ${live_file} ]] ; then |
69 |
+ MATCHES=0 |
70 |
+ elif [[ ${eu_automerge} == "yes" ]] ; then |
71 |
if [[ ! -e ${cfg_file} || ! -e ${live_file} ]] ; then |
72 |
MATCHES=0 |
73 |
else |
74 |
@@ -377,17 +401,50 @@ do_file() { |
75 |
|
76 |
show_diff() { |
77 |
clear |
78 |
- local file1=$1 file2=$2 |
79 |
+ local file1=$1 file2=$2 files=("$1" "$2") \ |
80 |
+ diff_files=() file i tmpdir |
81 |
+ |
82 |
+ if [[ -L ${file1} && ! -L ${file2} && |
83 |
+ -f ${file1} && -f ${file2} ]] ; then |
84 |
+ # If a regular file replaces a symlink to a regular file, then |
85 |
+ # show the diff between the regular files (bug #330221). |
86 |
+ diff_files=("${file1}" "${file2}") |
87 |
+ else |
88 |
+ for i in 0 1 ; do |
89 |
+ if [[ ! -L ${files[$i]} && -f ${files[$i]} ]] ; then |
90 |
+ diff_files[$i]=${files[$i]} |
91 |
+ continue |
92 |
+ fi |
93 |
+ [[ -n ${tmpdir} ]] || \ |
94 |
+ tmpdir=$(mktemp -d "${TMP}/symdiff-XXX") |
95 |
+ diff_files[$i]=${tmpdir}/${i} |
96 |
+ if [[ ! -L ${files[$i]} && ! -e ${files[$i]} ]] ; then |
97 |
+ echo "/dev/null" > "${diff_files[$i]}" |
98 |
+ elif [[ -L ${files[$i]} ]] ; then |
99 |
+ echo "SYM: ${file1} -> $(readlink "${files[$i]}")" > \ |
100 |
+ "${diff_files[$i]}" |
101 |
+ elif [[ -d ${files[$i]} ]] ; then |
102 |
+ echo "DIR: ${file1}" > "${diff_files[$i]}" |
103 |
+ elif [[ -p ${files[$i]} ]] ; then |
104 |
+ echo "FIF: ${file1}" > "${diff_files[$i]}" |
105 |
+ else |
106 |
+ echo "DEV: ${file1}" > "${diff_files[$i]}" |
107 |
+ fi |
108 |
+ done |
109 |
+ fi |
110 |
+ |
111 |
if [[ ${using_editor} == 0 ]] ; then |
112 |
( |
113 |
echo "Showing differences between ${file1} and ${file2}" |
114 |
- diff_command "${file1}" "${file2}" |
115 |
+ diff_command "${diff_files[0]}" "${diff_files[1]}" |
116 |
) | ${pager} |
117 |
else |
118 |
echo "Beginning of differences between ${file1} and ${file2}" |
119 |
- diff_command "${file1}" "${file2}" |
120 |
+ diff_command "${diff_files[0]}" "${diff_files[1]}" |
121 |
echo "End of differences between ${file1} and ${file2}" |
122 |
fi |
123 |
+ |
124 |
+ [[ -n ${tmpdir} ]] && rm -rf "${tmpdir}" |
125 |
} |
126 |
|
127 |
do_cfg() { |
128 |
@@ -395,14 +452,14 @@ do_cfg() { |
129 |
local ofile=$2 |
130 |
local -i my_input=0 |
131 |
|
132 |
- until (( my_input == -1 )) || [ ! -f "${file}" ] ; do |
133 |
+ until (( my_input == -1 )) || [[ ! -f ${file} && ! -L ${file} ]] ; do |
134 |
if [[ "${OVERWRITE_ALL}" == "yes" ]] && ! user_special "${ofile}"; then |
135 |
my_input=1 |
136 |
elif [[ "${DELETE_ALL}" == "yes" ]] && ! user_special "${ofile}"; then |
137 |
my_input=2 |
138 |
else |
139 |
show_diff "${ofile}" "${file}" |
140 |
- if [[ -L ${file} ]] ; then |
141 |
+ if [[ -L ${file} && ! -L ${ofile} ]] ; then |
142 |
cat <<-EOF |
143 |
|
144 |
------------------------------------------------------------- |
145 |
@@ -461,6 +518,19 @@ do_merge() { |
146 |
local ofile="${2}" |
147 |
local mfile="${TMP}/${2}.merged" |
148 |
local -i my_input=0 |
149 |
+ |
150 |
+ if [[ -L ${file} && -L ${ofile} ]] ; then |
151 |
+ echo "Both files are symlinks, so they will not be merged." |
152 |
+ return 0 |
153 |
+ elif [[ ! -f ${file} ]] ; then |
154 |
+ echo "Non-regular file cannot be merged: ${file}" |
155 |
+ return 0 |
156 |
+ elif [[ ! -f ${ofile} ]] ; then |
157 |
+ echo "Non-regular file cannot be merged: ${ofile}" |
158 |
+ return 0 |
159 |
+ fi |
160 |
+ |
161 |
+ |
162 |
echo "${file} ${ofile} ${mfile}" |
163 |
|
164 |
if [[ -e ${mfile} ]] ; then |
165 |
@@ -533,9 +603,18 @@ do_distconf() { |
166 |
for (( count = 0; count <= 9999; ++count )) ; do |
167 |
suffix=$(printf ".dist_%04i" ${count}) |
168 |
efile="${ofile}${suffix}" |
169 |
- if [[ ! -f ${efile} ]] ; then |
170 |
+ if [[ ! -f ${efile} && ! -L ${efile} ]] ; then |
171 |
mv ${mv_opts} "${file}" "${efile}" |
172 |
break |
173 |
+ elif [[ -L ${efile} && -L ${file} ]] ; then |
174 |
+ if [[ $(readlink "${efile}") == $(readlink "${file}") ]] ; then |
175 |
+ # replace identical copy |
176 |
+ mv "${file}" "${efile}" |
177 |
+ break |
178 |
+ fi |
179 |
+ elif [[ -L ${efile} || -L ${file} ]] ; then |
180 |
+ # not the same file types |
181 |
+ continue |
182 |
elif diff_command "${file}" "${efile}" &> /dev/null; then |
183 |
# replace identical copy |
184 |
mv "${file}" "${efile}" |
185 |
-- |
186 |
2.0.4 |