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