Blame SOURCES/0527-dracut-Ajusting-variables-name-for-include.patch

18971c
From 7812b7a7b02cc5b4e66c6544f8f8c8748ada00bf Mon Sep 17 00:00:00 2001
18971c
From: Erwan Velu <erwan.velu@enovance.com>
18971c
Date: Fri, 19 Dec 2014 14:49:00 +0100
18971c
Subject: [PATCH] dracut: Ajusting variables name for --include
18971c
18971c
When reading the --include part of the script, we had the following
18971c
issues to make the code easy to read:
18971c
- src & tgt were extract for the original options
18971c
- i variable was a file or a directory from src
18971c
- s variable was the directory name in case $i was a directory
18971c
18971c
"s" sounds very close to "src" while "s" is on the "tgt" side. Very
18971c
confusing.
18971c
18971c
"s" was defined before the "if it's a directory" statement while it's
18971c
only used inside the "if".
18971c
18971c
"i" was commit from the "src" but wasn't really explicit.
18971c
18971c
Having some lines mixing "i" and "s" takes a little time to get read
18971c
properly.
18971c
18971c
This patch offer the following changes:
18971c
- "i" is renamed to "objectname" as we don't know if its a file or a
18971c
  directory
18971c
18971c
- "s" is renamed to "object_destdir" as the object name becomes a
18971c
  directory on the destdir
18971c
18971c
- "object_destdir" (former "s") is moved inside the "if" statement as it's
18971c
  only used here
18971c
18971c
- tgt is finally renamed to "target" to be more explicit. We are not all
18971c
  native english ;o)
18971c
18971c
My 2 (semantic) cents,
18971c
18971c
Cherry-picked from: c9364f6ea296a03073bc4096756e3a61ca095c0e
18971c
Resolves: #1489882
18971c
---
18971c
 dracut.sh | 29 ++++++++++++++++-------------
18971c
 1 file changed, 16 insertions(+), 13 deletions(-)
18971c
18971c
diff --git a/dracut.sh b/dracut.sh
18971c
index 3b91b5e8..873274c0 100755
18971c
--- a/dracut.sh
18971c
+++ b/dracut.sh
18971c
@@ -1433,26 +1433,29 @@ if [[ $kernel_only != yes ]]; then
18971c
     fi
18971c
 fi
18971c
 
18971c
-while pop include_src src && pop include_target tgt; do
18971c
-    if [[ $src && $tgt ]]; then
18971c
+while pop include_src src && pop include_target target; do
18971c
+    if [[ $src && $target ]]; then
18971c
         if [[ -f $src ]]; then
18971c
-            inst $src $tgt
18971c
+            inst $src $target
18971c
         else
18971c
             ddebug "Including directory: $src"
18971c
-            mkdir -p "${initdir}/${tgt}"
18971c
+            destdir="${initdir}/${target}"
18971c
+            mkdir -p "$destdir"
18971c
             # check for preexisting symlinks, so we can cope with the
18971c
             # symlinks to $prefix
18971c
-            for i in "$src"/*; do
18971c
-                [[ -e "$i" || -h "$i" ]] || continue
18971c
-                s=${initdir}/${tgt}/${i#$src/}
18971c
-                if [[ -d "$i" ]]; then
18971c
-                    if ! [[ -e "$s" ]]; then
18971c
-                        mkdir -m 0755 -p "$s"
18971c
-                        chmod --reference="$i" "$s"
18971c
+            # Objectname is a file or a directory
18971c
+            for objectname in "$src"/*; do
18971c
+                [[ -e "$objectname" || -h "$objectname" ]] || continue
18971c
+                if [[ -d "$objectname" ]]; then
18971c
+                    # objectname is a directory, let's compute the final directory name
18971c
+                    object_destdir=${destdir}/${objectname#$src/}
18971c
+                    if ! [[ -e "$object_destdir" ]]; then
18971c
+                        mkdir -m 0755 -p "$object_destdir"
18971c
+                        chmod --reference="$objectname" "$object_destdir"
18971c
                     fi
18971c
-                    cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
18971c
+                    cp --reflink=auto --sparse=auto -fa -t "$object_destdir" "$objectname"/*
18971c
                 else
18971c
-                    cp --reflink=auto --sparse=auto -fa -t "$s" "$i"
18971c
+                    cp --reflink=auto --sparse=auto -fa -t "$destdir" "$objectname"
18971c
                 fi
18971c
             done
18971c
         fi