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