9f65cc
From f0f83da2c608202205f1092289a64de044ecc130 Mon Sep 17 00:00:00 2001
9f65cc
From: Hari Bathini <hbathini@linux.ibm.com>
9f65cc
Date: Fri, 11 Jun 2021 15:20:28 +0530
9f65cc
Subject: [PATCH] fix(dracut.sh): handle '-i' option to include files beginning
9f65cc
 with '.'
9f65cc
MIME-Version: 1.0
9f65cc
Content-Type: text/plain; charset=UTF-8
9f65cc
Content-Transfer-Encoding: 8bit
9f65cc
9f65cc
While including a directory using '--include' option, the file and
9f65cc
subdirectory names that begin with '.' are not included. Also, dracut
9f65cc
throws a warning message when a subdirectory is empty or only has
9f65cc
files or subdirectories that begin with '.'.
9f65cc
9f65cc
For example, while trying to include /tmpdata directory with the
9f65cc
below tree:
9f65cc
9f65cc
  # tree -a /tmpdata
9f65cc
  /tmpdata
9f65cc
  ├── .anothertestdir
9f65cc
  ├── testdir
9f65cc
  │   └── .testsubdir
9f65cc
  └── .testfile
9f65cc
9f65cc
dracut throws the below warning message:
9f65cc
9f65cc
  # dracut --include /tmpdata /root
9f65cc
  cp: cannot stat '/tmpdata/testdir/*': No such file or directory
9f65cc
  #
9f65cc
9f65cc
and this is how the included /tmpdata directory tree looks:
9f65cc
9f65cc
  # tree -a root
9f65cc
  root
9f65cc
  └── testdir
9f65cc
9f65cc
No file or directory beginning with '.' is included & also, copying
9f65cc
/tmpdata/testdir reported "No such file or directory" warning. Using
9f65cc
'.' instead of '*' in the below command will fix the warning whether
9f65cc
the directory being copied is empty or only has files or directories
9f65cc
that begin with dot:
9f65cc
9f65cc
  $DRACUT_CP -t "$object_destdir" "$dracutsysrootdir$objectname"/*
9f65cc
9f65cc
Also, enable 'dotglob' temporarily to include files and directories
9f65cc
beginning with a `.' in the results of pathname expansion of source
9f65cc
directory being included.
9f65cc
9f65cc
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
9f65cc
(cherry picked from commit f1138012c9dc44e6614466c0a8e929fc55e4a5dd)
9f65cc
9f65cc
Cherry-picked from: f1138012
9f65cc
Resolves: #1959336
9f65cc
---
9f65cc
 dracut.sh | 5 ++++-
9f65cc
 1 file changed, 4 insertions(+), 1 deletion(-)
9f65cc
9f65cc
diff --git a/dracut.sh b/dracut.sh
9f65cc
index bf79568c..3fd31e21 100755
9f65cc
--- a/dracut.sh
9f65cc
+++ b/dracut.sh
9f65cc
@@ -1606,6 +1606,8 @@ for ((i=0; i < ${#include_src[@]}; i++)); do
9f65cc
             # check for preexisting symlinks, so we can cope with the
9f65cc
             # symlinks to $prefix
9f65cc
             # Objectname is a file or a directory
9f65cc
+            reset_dotglob="$(shopt -p dotglob)"
9f65cc
+            shopt -q -s dotglob
9f65cc
             for objectname in "$src"/*; do
9f65cc
                 [[ -e "$objectname" || -h "$objectname" ]] || continue
9f65cc
                 if [[ -d "$objectname" ]]; then
9f65cc
@@ -1615,11 +1617,12 @@ for ((i=0; i < ${#include_src[@]}; i++)); do
9f65cc
                         mkdir -m 0755 -p "$object_destdir"
9f65cc
                         chmod --reference="$objectname" "$object_destdir"
9f65cc
                     fi
9f65cc
-                    $DRACUT_CP -t "$object_destdir" "$objectname"/*
9f65cc
+                    $DRACUT_CP -t "$object_destdir" "$objectname"/.
9f65cc
                 else
9f65cc
                     $DRACUT_CP -t "$destdir" "$objectname"
9f65cc
                 fi
9f65cc
             done
9f65cc
+            eval "$reset_dotglob"
9f65cc
         fi
9f65cc
     fi
9f65cc
 done
9f65cc