d4a4eb
From b6d52b504fc7eefc3f405f75463d9e818471ee99 Mon Sep 17 00:00:00 2001
d4a4eb
From: Kairui Song <kasong@redhat.com>
d4a4eb
Date: Mon, 11 Mar 2019 19:46:19 +0800
d4a4eb
Subject: [PATCH] squash: fix and simplify required_in_root
d4a4eb
d4a4eb
If required target is a symbol link, create the link then following the
d4a4eb
link. If it's a directory, create new directory, else just move it.
d4a4eb
d4a4eb
Signed-off-by: Kairui Song <kasong@redhat.com>
d4a4eb
(cherry picked from commit 11ce69e4bd9172cf54251ea62bb4a5ead1700fd6)
d4a4eb
d4a4eb
Resolves: #1691705
d4a4eb
---
d4a4eb
 dracut.sh | 42 +++++++++++++++++++-----------------------
d4a4eb
 1 file changed, 19 insertions(+), 23 deletions(-)
d4a4eb
d4a4eb
diff --git a/dracut.sh b/dracut.sh
d4a4eb
index a0158f22..6de88b3e 100755
d4a4eb
--- a/dracut.sh
d4a4eb
+++ b/dracut.sh
d4a4eb
@@ -1811,30 +1811,26 @@ if dracut_module_included "squash"; then
d4a4eb
             required_in_root $(dirname $file)
d4a4eb
         fi
d4a4eb
 
d4a4eb
-        if [[ -d $_sqsh_file ]]; then
d4a4eb
-            if [[ -L $_sqsh_file ]]; then
d4a4eb
-                cp --preserve=all -P $_sqsh_file $_init_file
d4a4eb
-            else
d4a4eb
-                mkdir $_init_file
d4a4eb
-            fi
d4a4eb
+        if [[ -L $_sqsh_file ]]; then
d4a4eb
+          cp --preserve=all -P $_sqsh_file $_init_file
d4a4eb
+          _sqsh_file=$(realpath $_sqsh_file 2>/dev/null)
d4a4eb
+          if [[ -e $_sqsh_file ]] && [[ "$_sqsh_file" == "$squash_dir"* ]]; then
d4a4eb
+            # Relative symlink
d4a4eb
+            required_in_root ${_sqsh_file#$squash_dir/}
d4a4eb
+            return
d4a4eb
+          fi
d4a4eb
+          if [[ -e $squash_dir$_sqsh_file ]]; then
d4a4eb
+            # Absolute symlink
d4a4eb
+            required_in_root ${_sqsh_file#/}
d4a4eb
+            return
d4a4eb
+          fi
d4a4eb
+          required_in_root ${module_spec#$squash_dir/}
d4a4eb
         else
d4a4eb
-            if [[ -L $_sqsh_file ]]; then
d4a4eb
-                cp --preserve=all -P $_sqsh_file $_init_file
d4a4eb
-                _sqsh_file=$(realpath $_sqsh_file 2>/dev/null)
d4a4eb
-                if [[ -e $_sqsh_file ]] && [[ "$_sqsh_file" == "$squash_dir"* ]]; then
d4a4eb
-                    # Relative symlink
d4a4eb
-                    required_in_root ${_sqsh_file#$squash_dir/}
d4a4eb
-                    return
d4a4eb
-                fi
d4a4eb
-                if [[ -e $squash_dir$_sqsh_file ]]; then
d4a4eb
-                    # Absolute symlink
d4a4eb
-                    required_in_root ${_sqsh_file#/}
d4a4eb
-                    return
d4a4eb
-                fi
d4a4eb
-                required_in_root ${module_spec#$squash_dir/}
d4a4eb
-            else
d4a4eb
-                mv $_sqsh_file $_init_file
d4a4eb
-            fi
d4a4eb
+          if [[ -d $_sqsh_file ]]; then
d4a4eb
+            mkdir $_init_file
d4a4eb
+          else
d4a4eb
+            mv $_sqsh_file $_init_file
d4a4eb
+          fi
d4a4eb
         fi
d4a4eb
     }
d4a4eb
 
d4a4eb