Merge pull request #54909 from tollb/fix/wrap-gapps-hook_unnecessary_symlink_wrap

wrap-gapps-hook.sh: only wrap links when required
This commit is contained in:
Jan Tojnar 2019-02-01 14:20:37 +01:00 committed by GitHub
commit d42ef371c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,16 +36,40 @@ wrapGAppsHook() {
done
if [[ -z "$dontWrapGApps" ]]; then
targetDirsThatExist=()
targetDirsRealPath=()
# wrap binaries
targetDirs=( "${prefix}/bin" "${prefix}/libexec" )
for targetDir in "${targetDirs[@]}"; do
if [[ -d "${targetDir}" ]]; then
find -L "${targetDir}" -type f -executable -print0 \
targetDirsThatExist+=("${targetDir}")
targetDirsRealPath+=("$(realpath "${targetDir}")/")
find "${targetDir}" -type f -executable -print0 \
| while IFS= read -r -d '' file; do
echo "Wrapping program ${file}"
echo "Wrapping program '${file}'"
wrapProgram "${file}" "${gappsWrapperArgs[@]}"
done
fi
done
# wrap links to binaries that point outside targetDirs
# Note: links to binaries within targetDirs do not need
# to be wrapped as the binaries have already been wrapped
if [[ ${#targetDirsThatExist[@]} -ne 0 ]]; then
find "${targetDirsThatExist[@]}" -type l -xtype f -executable -print0 \
| while IFS= read -r -d '' linkPath; do
linkPathReal=$(realpath "${linkPath}")
for targetPath in "${targetDirsRealPath[@]}"; do
if [[ "$linkPathReal" == "$targetPath"* ]]; then
echo "Not wrapping link: '$linkPath' (already wrapped)"
continue 2
fi
done
echo "Wrapping link: '$linkPath'"
wrapProgram "${linkPath}" "${gappsWrapperArgs[@]}"
done
fi
fi
}