Files
Roxana Nicolescu 6c70187239 UBUNTU: [Debian] autoreconstruct - Do not generate chmod -x for deleted files
BugLink: https://bugs.launchpad.net/bugs/2045562

Debian source format 1.0 cannot remove files, create symlinks and change
permission in the .diff.gz tarball. Therefore any changes in these 3
categories cannot be represented without any tricks. To solve this,
the `reconstruct` script is used every time we build the source package.
The script is generated by `gen-auto-reconstruct` script by the `cranky
close`. It checks if there has been any changes in the 3 categories
mentioned above between the upstream version (i.e v6.5) and the current one.
The problem with the script is that in case a file A was removed since the
upstream version was released, the `reconstruct` script will contains
these commands in this exact order:
        rm -f A
        chmod -x A
The second command will fail because file A does not exist anymore.
This is solved by generating the `chmod +/-x` commands before `rm`.
Which results in:
        chmod -x A
        rm -f A
But because the reconstruct script is used during `clean` rule which is
triggered pretty much during every cranky step which is run in the
source repo, the first command will always file because file is not
present anymore in the tree. To solve this, any `chmod` change is added
only if the file has not been deleted. Therefore if file A has been
deleted, the `reconstruct` script will contain only this:
        rm -f A

Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
Acked-by: Manuel Diewald <manuel.diewald@canonical.com>
Acked-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:41:09 +01:00

90 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <orig tag>|<base release> <reconstruct> <options>" 1>&2
exit 1
fi
tag="$1"
reconstruct="$2"
options="$3"
case "$tag" in
v*) ;;
*) tag="v${tag%.*}" ;;
esac
# Validate the tag.
count=$( git tag -l "$tag" | wc -l )
if [ "$count" != 1 ]; then
echo "$0: $tag: tag invalid" 1>&2
exit 1
fi
#git ls-tree -r --full-tree HEAD | grep ^120 | \
#while read mode type blobid name
(
# Identify all new symlinks since the proffered tag.
echo "# Recreate any symlinks created since the orig."
git diff "$tag.." --raw --no-renames | awk '(/^:000000 120000/ && $5 == "A") { print $NF }' | \
while read name
do
link=$( readlink "$name" )
echo "[ ! -L '$name' ] && ln -sf '$link' '$name'"
done
# Identify files with execute permissions added since the proffered tag.
git diff "$tag.." --raw --no-renames | awk -F '[: \t]' '{print $2, $3, $NF }' | \
while IFS=" " read old new name
do
old=$( printf "0%s" $old )
new=$( printf "0%s" $new )
changed=$(( (old ^ new) & 0111 ))
if [ "$changed" -ne 0 ]; then
added=$(( new & 0111 ))
if [ "$added" -ne 0 ]; then
echo "chmod +x '$name'"
elif [ "$new" -ne 0 ]; then
echo "chmod -x '$name'"
fi
fi
done
# Identify all removed files since the proffered tag.
echo "# Remove any files deleted from the orig."
git diff "$tag.." --raw --no-renames | awk '(/^:/ && $5 == "D") { print $NF }' | \
while read name
do
echo "rm -f '$name'"
done
# All done, make sure this does not complete in error.
echo "exit 0"
) >"$reconstruct"
(
# Identify all new symlinks since the proffered tag.
echo "# Ignore any symlinks created since the orig which are rebuilt by reconstruct."
git diff "$tag.." --raw --no-renames | awk '(/^:000000 120000/ && $5 == "A") { print $NF }' | \
while read name
do
echo "extend-diff-ignore=^$name\$"
done
) >"$options.update"
head='^## autoreconstruct -- begin$'
foot='^## autoreconstruct -- end$'
sed -i -e "
/$head/,/$foot/{
/$head/{
p;
r $options.update
};
/$foot/p;
d
}
" "$options"
rm -f "$options.update"