From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 1BFE62652B for ; Thu, 16 May 2024 16:22:25 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1715869345; b=BeQc5Azaxg0ay13egjNQ0I8Foc3lPjSIIKCxvwzyEEImwgCmPZDSIY5TF0+1yfpd6mE3Y2yRiv M5szFx4r1sBFI3kbxD8XDvon8VwYqrFMQgUdlPswgi6Y17pSu2h09eXHkhCCUx4cbsAIa6ns7t IKrbjWKWcT3uLAKsmZ2fOnnUszKc7r9/+nwco66z8VEaUL5NjkZXKckEc09lNeAIiLEzKq4fTe SbPxk+jbxgWPhp19/HbBNDCScJhq9W+NaWajLv/mu1xnHWb7nt2cEpIbznec+NmUXZTPP6KLto nJnzScKb10qDIc30MgQWqxEAVh9W3ypzdvG/rVPR0vo/6w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1715869345; bh=lLQ1tbAU2rH8l8YQEtWfsX6G6gRm5NsvCBfkPkriu0w=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Subject:From:To:MIME-Version:Date:Message-ID:Content-Type: DKIM-Signature; b=DLgC5UiXwEuHVBGzKO43I/ENMywPBMpRHP7uEcCrOwMxInKzW1yu6PItyKYjmmSqcHU19cdtki OKfjCSmuCQYUevgc+wgUPMjcalcYOCL/iMXDWQRpp+9jFbCDU5ARgUjEQ38uOT1Q6JJ4U/5OC/ ELwOSsfbp18vtzSixYIDCZaIc5RAQQNhjZebcEP8gfPo3jTcg6rRBMElHxSfeDwoZgOh5r3iji 3QkRt1FAin/NVfORWwqhheP4PvvoMTN2vvPRe6vIGgb2xwLnjtVh6ksD22TJiZZb2jlF4l1AMk E32p5G5GlV1V9BiG/1/7/yi7CMe/Yy8Q4n3Xz0yWT4mCRQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Subject:From:To:MIME-version:Date: Message-id:Content-type:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=qFCC80t0A4aoJKKR4/zcx/8HlV7NAh5NpyOh2L5PRAY=; b=lzrmbmRbObnfatt8SQiD3oJmF1 MjRxGWxGXWvjyAu7KmB8bmEmii8dUtu2E5729Y6pG2ZOmkMi8la4h9xIFvpF6qDUcypaBX3Veb1Jh lmoVAxNy2NQPBflq3guHll3YEjDo8h73jzCDbV6Owib94jk8cvO9Ck4KS1fwsrj8mZ6PiFWkKt6II Fm6XlM9M9LH9WJ7Ru2iq4zrNghDZL7Yx0x8gW1FW2R3PJI9t1kv7vn1qiOtQcuxs1T8wYTNJRkkHe Lw+CleQJJVQBEWzVZpOyMtfQD6CZ1oDyLPLPb7FhY6923qQ+8KkyAkmsFpENLS50pddiIGbJkndUW knq6vaAA==; Received: by zero.zsh.org with local id 1s7c00-0001G0-Sx; Thu, 16 May 2024 14:22:24 +0000 Authentication-Results: zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; dmarc=none header.from=eastlink.ca; arc=none Received: from mta02.eastlink.ca ([24.224.136.13]:47429) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1s7byy-0000RI-OK; Thu, 16 May 2024 14:21:21 +0000 Received: from csp02.eastlink.ca ([71.7.199.167]) by mta02.eastlink.ca ([24.224.136.13]) with ESMTPS id <0SDL0V7720ZU9ZI0@mta02.eastlink.ca> for zsh-users@zsh.org; Thu, 16 May 2024 11:21:19 -0300 (ADT) Received: from [192.168.0.15] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp02.eastlink.ca ([71.7.199.167]) with ESMTPSA id 7byws2ghixAjx7byxs6Jqw (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Thu, 16 May 2024 11:21:19 -0300 X-Authority-Analysis: v=2.4 cv=EfprQ+mC c=1 sm=1 tr=0 ts=6646165f a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=6vG5yPWEP_G5bd9HvxkA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=LVGkrdzFjh7SI0u2tboA:9 a=vDUb9Cy2BUvVuUmh:21 a=_W_S_7VecoQA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehuddgjeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpegtkfffgggfvffhufesrgdtreertddvjeenucfhrhhomheptfgrhicutehnughrvgifshcuoehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgeqnecuggftrfgrthhtvghrnhepfeefiedvtdekvdfgteekveduhfdtledtgeettddtkeeifffhuefhkeehgedtveetnecukfhppedvgedrvddtjedrudelrddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvgedrvddtjedrudelrddufedphhgvlhhopegludelvddrudeikedrtddrudehngdpmhgrihhlfhhrohhmpehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgdpnhgspghrtghpthhtohepvddprhgtphhtthhopeerredprhgtphhtthhopeiishhhqdhushgvrhhsseiishhhrdhorhhgpdhgvghtqdgkihhprfgrshhsfigupehtrhhuvg X-Vade-Score: -100 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------AVmr4LRX6YWP2L03fKlL2Wxt" Message-id: <9b97bc99-1d92-46f1-8841-c757d1dcee68@eastlink.ca> Date: Thu, 16 May 2024 07:21:18 -0700 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Content-language: en-US To: Zsh Users From: Ray Andrews Subject: exit to shell from nested function calls. X-Seq: 29934 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: This is a multi-part message in MIME format. --------------AVmr4LRX6YWP2L03fKlL2Wxt Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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? --------------AVmr4LRX6YWP2L03fKlL2Wxt Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit 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? 


--------------AVmr4LRX6YWP2L03fKlL2Wxt--