From: Ray Andrews <rayandrews@eastlink.ca>
To: Zsh Users <zsh-users@zsh.org>
Subject: exit to shell from nested function calls.
Date: Thu, 16 May 2024 07:21:18 -0700 [thread overview]
Message-ID: <9b97bc99-1d92-46f1-8841-c757d1dcee68@eastlink.ca> (raw)
[-- Attachment #1: Type: text/plain, Size: 4945 bytes --]
Don't read this closely, there's only one thing that's relevant, see below:
# Create a directory:
_overlay_mkdir ()
{
# Create backup directory if it hasn't already been done.
[ -d $1 ] && { infomsg "\"$1\" already exists."; return 0 }
mkdir -vp $1 ||
{ errormsg "Couldn't create directory: \"$1\"." && return 1 }
return 0
}
# Synchronize two directories:
_overlay_rsync ()
{
actionmsg "Synching \"$1\" to \"$2\" ..."
# greysky uses: --delete-after
rsync -aX --del --inplace --no-whole-file $1/* $2 ||
{ errormsg "Can't rsync \"$1\" to \"$2\"." && return 1 }
return 0
}
# Run for each directory to be overlaid:
overlay ()
{
[[ ! "$1" || "$1" == '-h' ]] && _overlay_syntax && return 0
# NB, this check must run before initializing OR normal run.
# '-x' = exact match. Note, even the firefox 'can't find profile'
error msg. box triggers this:
[ -n "$( pgrep -x ${program} )" ] &&
errormsg "\"${program}\" is running, please quit before
continuing." && return 1
actionmsg "\nInitializing overlay for \"$1\" ..."
local subject="$1" # Full path of directory to be overlayed.
# renamed subject dir. (must borrow real name to create link to
overlay).
local active="${subject}-active"
local backup="/aMisc/Overlay$subject" # Backup.
local target="/run/user/0$subject" # The overlay directory.
local working="${target}-working" # Used by 'mount' internally.
# Rescue if we did not unoverlay properly, as when computer is shut down
without quitting facebook first. If subject is a link pointing to
target we almost surely did an improper shut down:
[[ -h "$subject" && $( readlink -m "$subject" ) == "$target" ]] &&
{
# Recreate target:
_overlay_mkdir ${target} || return 1
# And remount:
mount -vt overlay -o
lowerdir=${active},upperdir=${target},workdir=${working} overlay
${target} || return 1
return 0
}
[[ -d "$subject" ]] ||
{ errormsg "\"${subject}\" seems not to be a directory,\n but
we can only overlay directories!"; return 1 }
# rsync subject to the backup directory: Do this here so that we
get the backup no matter what. This way the pointer does not exist yet.
_overlay_mkdir ${backup} || return 1
_overlay_rsync "$subject" "$backup" || return 1
#"$subject" is: |/root/.mozilla|
#"$backup" is: |/aOverlay/root/.mozilla-backup|
#"$active" is: |/root/.mozilla-active|
#"$target" is: |/run/user/0/root/.mozilla|
#"$working" is: |/run/user/0/root/.mozilla-working|
if [[ -h "$subject" && $( readlink -m "$subject" ) == "$target" && \
-d "$backup" && -d "$active" && -d "$target" && -d "$working" ]]; then
infomsg "\"${subject}\" overlay is already initialized."
else
# Create directories if it hasn't already been done.
_overlay_mkdir ${target} || return 1
_overlay_mkdir ${working} || return 1
# Subject directory is renamed, and ...
mv -v "$subject" "$active" || return 1
# ... 'subject' is now a link to overlay.
ln -sv "$target" "$subject" ||
{ errormsg "Couldn't link \"$subject\" to \"$target\".";
return 1 }
actionmsg "\nCreating overlay: lowerdir=\"$active\"
overlay=\"$target\" ..."
# -v = verbose, -t overlay = type is overlay. lowerdir is
hidden by upperdir. workdir is internal to mount.
mount -vt overlay -o
lowerdir=${active},upperdir=${target},workdir=${working} overlay ${target}
fi
return 0
}
---------------------------------------------------------------------------------------
... the above is part of a function hierarchy can can be four levels
deep and if there's an error (it's being debugged so there's error tests
everywhere), I need these 'return 1 ... return 1 ... return 1 ... return
1 ... to break back to the shell. Now, didn't we discuss something like
this a few months back? ... to do with zmv ... 'err-exit' or something
like that. I was complaining that zmv should NOT crash -- but Bart
pointed out that it's not a crash it's a controlled thing, of course.
And zmv was modified accordingly IIRC.
Anyway, it occurs to me that in the above, I want the opposite -- I DO
want any of these errors, however many levels deep it might be, to
exit/return directly back to the shell (but 'exit' itself quits the
shell entirely) without having to return from each level one at a time.
As always I wish I could search the archives and dig this up, because it
was the same issue.
'err-exit'? Or can a trap do this? or, if it was run in a subshell then
'exit' would return to the calling shell?
[-- Attachment #2: Type: text/html, Size: 6424 bytes --]
next reply other threads:[~2024-05-16 14:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-16 14:21 Ray Andrews [this message]
2024-05-16 20:26 ` Roman Perepelitsa
2024-05-16 21:28 ` Ray Andrews
2024-05-17 15:40 ` Mark J. Reed
2024-05-17 15:58 ` Ray Andrews
2024-05-17 16:46 ` Mark J. Reed
2024-05-17 17:04 ` Bart Schaefer
2024-05-17 17:36 ` Bart Schaefer
2024-05-17 18:52 ` Ray Andrews
2024-05-17 19:00 ` Mark J. Reed
2024-05-17 20:28 ` Ray Andrews
2024-05-18 2:09 ` Bart Schaefer
2024-05-17 17:29 ` Thomas Lauer
2024-05-17 18:43 ` Ray Andrews
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9b97bc99-1d92-46f1-8841-c757d1dcee68@eastlink.ca \
--to=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).