Skip to content

Commit

Permalink
dracut: Ajusting variables name for --include
Browse files Browse the repository at this point in the history
When reading the --include part of the script, we had the following
issues to make the code easy to read:
- src & tgt were extract for the original options
- i variable was a file or a directory from src
- s variable was the directory name in case $i was a directory

"s" sounds very close to "src" while "s" is on the "tgt" side. Very
confusing.

"s" was defined before the "if it's a directory" statement while it's
only used inside the "if".

"i" was commit from the "src" but wasn't really explicit.

Having some lines mixing "i" and "s" takes a little time to get read
properly.

This patch offer the following changes:
- "i" is renamed to "objectname" as we don't know if its a file or a
  directory

- "s" is renamed to "object_destdir" as the object name becomes a
  directory on the destdir

- "object_destdir" (former "s") is moved inside the "if" statement as it's
  only used here

- tgt is finally renamed to "target" to be more explicit. We are not all
  native english ;o)

My 2 (semantic) cents,
  • Loading branch information
Erwan Velu committed Dec 19, 2014
1 parent 332ecaa commit c9364f6
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions dracut.sh
Expand Up @@ -1487,27 +1487,29 @@ if [[ $kernel_only != yes ]]; then
done
fi

while pop include_src src && pop include_target tgt; do
if [[ $src && $tgt ]]; then
while pop include_src src && pop include_target target; do
if [[ $src && $target ]]; then
if [[ -f $src ]]; then
inst $src $tgt
inst $src $target
else
ddebug "Including directory: $src"
destdir="${initdir}/${tgt}"
destdir="${initdir}/${target}"
mkdir -p "$destdir"
# check for preexisting symlinks, so we can cope with the
# symlinks to $prefix
for i in "$src"/*; do
[[ -e "$i" || -h "$i" ]] || continue
s=${destdir}/${i#$src/}
if [[ -d "$i" ]]; then
if ! [[ -e "$s" ]]; then
mkdir -m 0755 -p "$s"
chmod --reference="$i" "$s"
# Objectname is a file or a directory
for objectname in "$src"/*; do
[[ -e "$objectname" || -h "$objectname" ]] || continue
if [[ -d "$objectname" ]]; then
# objectname is a directory, let's compute the final directory name
object_destdir=${destdir}/${objectname#$src/}
if ! [[ -e "$object_destdir" ]]; then
mkdir -m 0755 -p "$object_destdir"
chmod --reference="$objectname" "$object_destdir"
fi
cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
cp --reflink=auto --sparse=auto -fa -t "$object_destdir" "$objectname"/*
else
cp --reflink=auto --sparse=auto -fa -t "$destdir" "$i"
cp --reflink=auto --sparse=auto -fa -t "$destdir" "$objectname"
fi
done
fi
Expand Down

0 comments on commit c9364f6

Please sign in to comment.