zzexe: fix some performance issues on large files

This commit is contained in:
Phantop 2022-07-24 20:36:24 -04:00
parent 49c5b59cfb
commit 4bf66c35dc
1 changed files with 15 additions and 10 deletions

View File

@ -36,9 +36,11 @@ unappimage() {
zzexe() { zzexe() {
[ "$1" = "-p" ] && p="$2" && shift 2 # save prefix if present [ "$1" = "-p" ] && p="$2" && shift 2 # save prefix if present
zstdmt -cq19 "$@" | ifne sponge "$1" tmp=$(mktemp) # make tmp file to avoid io operations
printfunc zzexe_header | cat - "$1" | ifne sponge "$1" printfunc zzexe_header | sed -e "2s/);$/${1##*[./]})/" -e "7s/^/$p /" > "$tmp"
sed -i -e "2s/);$/${1##*[./]})/" -e "7s/^/$p /" "$1" zstdmt -cq19 "$@" >> "$tmp"
mv "$tmp" "$1"
chmod +x "$1"
exit exit
} }
@ -64,8 +66,12 @@ case "$1" in
chmod +x "$2" chmod +x "$2"
exit ;; exit ;;
-d ) -d )
awk 'f;/^exit \$res$/{f=1}' "$2" | head -c-1 | zstd -cd | ifne sponge "$2" d=dwarfs-root # just to keep line shorter, extract if file is dwarfs
d=dwarfs-root; dwarfsck -d0 -i"$2" && mkdir $d && dwarfsextract -o $d -i "$2" dwarfsck -d0 -i"$2" && mkdir $d && dwarfsextract -o $d -i "$2" && exit
tmp=$(mktemp) # make tmp file to avoid io operations
awk 'f;/^exit \$res$/{f=1}' "$2" | head -c-1 | zstd -cd > "$tmp"
mv "$tmp" "$2"
chmod +x "$2"
exit ;; exit ;;
-p ) -p )
zzexe "$@" ;; zzexe "$@" ;;
@ -73,7 +79,7 @@ case "$1" in
shift shift
zzexe "$@" ;; zzexe "$@" ;;
--version | -v ) --version | -v )
tput setaf 2; echo appdwarf 2022.07.19 tput setaf 2; echo appdwarf 2022.07.24
tput setaf 6; echo Built by July 🏳️‍🌈; exit ;; tput setaf 6; echo Built by July 🏳️‍🌈; exit ;;
-* | '' ) -* | '' )
echo "Usage: appdwarf [option] [APP/FILE/FOLDER/URL] [compression options]" echo "Usage: appdwarf [option] [APP/FILE/FOLDER/URL] [compression options]"
@ -90,7 +96,7 @@ esac
if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
if [ ! -f "$1" ]; then # file doesn't exist, see if this is a url if [ ! -f "$1" ]; then # file doesn't exist, see if this is a url
if ! echo "$1" | grep / ; then # AppImageHub if ! echo "$1" | grep -q / ; then # AppImageHub
echo "Checking AppImageHub for this program..." echo "Checking AppImageHub for this program..."
app=https://github.com/AppImage/appimage.github.io/raw/master/apps/$1.md app=https://github.com/AppImage/appimage.github.io/raw/master/apps/$1.md
shift shift
@ -101,7 +107,7 @@ if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
set -- "https://github.com/$app" "$@" set -- "https://github.com/$app" "$@"
fi fi
if echo "$1" | grep 'https://github.com/[^/]*/[^/]*/*$'; then # GitHub url if echo "$1" | grep -q 'https://github.com/[^/]*/[^/]*/*$'; then # GitHub url
echo "Assuming this is a GitHub repo..." echo "Assuming this is a GitHub repo..."
app="$(echo "${1%/}"/releases | sed 's|github.com|api.github.com/repos|')" app="$(echo "${1%/}"/releases | sed 's|github.com|api.github.com/repos|')"
shift shift
@ -121,9 +127,8 @@ if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
rm -rf squashfs-root rm -rf squashfs-root
# this is a file, but it might be an existing dwarfs image # this is a file, but it might be an existing dwarfs image
if dwarfsck -d0 -i"$1"; then if dwarfsck -d0 -i"$1"; then
echo "Existing dwarfs image found. Adding header..."
set -- "$@" --recompress=none set -- "$@" --recompress=none
elif unappimage "$1"; then elif file "$1" | grep -q ELF && unappimage "$1"; then
echo "AppImage found. Converting..." echo "AppImage found. Converting..."
app="$(basename "$1" .AppImage)" app="$(basename "$1" .AppImage)"
rm -rf "$1" "$app" rm -rf "$1" "$app"