From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29414 invoked from network); 1 Jul 2020 04:42:17 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 1 Jul 2020 04:42:17 -0000 Received: (qmail 17468 invoked by alias); 1 Jul 2020 04:42:00 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: Sender: zsh-workers@zsh.org X-Seq: 46168 Received: (qmail 26240 invoked by uid 1010); 1 Jul 2020 04:42:00 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi1-f196.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25857. spamassassin: 3.4.4. Clear:RC:0(209.85.167.196):SA:0(-1.8/5.0):. Processed in 4.344582 secs); 01 Jul 2020 04:42:00 -0000 X-Envelope-From: phy1729@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.167.196 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=uxTBtTk+tgsqqUwWeVpejzpaYi5l3PTAbpWjZfa+NeU=; b=rl7LfRsYuI3+3HKXYA47qlnP6GwZUdlkTJjC5rxXe5MvWeRo4dVKEsHmPLT9cW+ZmO t1GfBE6zS5VC5NSu5xPDeRR7qoQBMLxgtByzuvC9k6f3sjLJs2awPWjxN9Ug3rGG5BgK o5i9ECY7i4PQ8qwd4ibloqode0FRJ9TpK+nestBuY2EQqNacVFwC8ZThViehXNYVHYhs R4KrB5hCPwIOBwMjMnnlMyvVLg5+v2WqvfgjY/PIODcZIII626bcDOcdGGZ2r1KUvNcN vrf8PBEB/CX7qKtY2HwLTmm3RA5Q/jOs650tM8f/erbr2WMw7iI0OWnnrA1Lq2S8gVRP jkCQ== X-Gm-Message-State: AOAM533hA5aliXaBO0swXssDlT3KxUf60UllKY4F8z1eDp7cQVU1Ltek UdmVNbG3SX9UHnzwH0YCUHpU0iORXJ0= X-Google-Smtp-Source: ABdhPJwBOxxnoLeX6wXax3TJKGsgfSnNj3nxxjPKdMfjDk5opDkFqRI4MEPTl3Qpeb3MQyMqO2zxwQ== X-Received: by 2002:a05:6808:8f5:: with SMTP id d21mr11219574oic.174.1593578483012; Tue, 30 Jun 2020 21:41:23 -0700 (PDT) Date: Tue, 30 Jun 2020 23:41:20 -0500 From: Matthew Martin To: zsh-workers@zsh.org Subject: Re: cd does not update $PWD in a timely fashion. Message-ID: <20200701044120.GA81164@CptOrmolo.darkstar> Mail-Followup-To: zsh-workers@zsh.org References: <20200626173248.GA31933@CptOrmolo.darkstar> <20200627072557.GA48532@CptOrmolo.darkstar> <20200627204208.2bd20e9b@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200627204208.2bd20e9b@tarpaulin.shahaf.local2> On Sat, Jun 27, 2020 at 08:42:08PM +0000, Daniel Shahaf wrote: > Matthew Martin wrote on Sat, 27 Jun 2020 02:25 -0500: > > + print $PWD > > Is the lack of «&&» on this line intentional? > > > + print $hook_pwd && > > Run «unset chpwd_functions» here so as not to affect subsequent tests > (once they're added)? Compare 46067. It wasn't and thanks for the pointer. diff --git a/Src/builtin.c b/Src/builtin.c index 770930579..ff84ce936 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -841,7 +841,6 @@ int bin_cd(char *nam, char **argv, Options ops, int func) { LinkNode dir; - struct stat st1, st2; if (isset(RESTRICTED)) { zwarnnam(nam, "restricted"); @@ -860,23 +859,6 @@ bin_cd(char *nam, char **argv, Options ops, int func) } cd_new_pwd(func, dir, OPT_ISSET(ops, 'q')); - if (stat(unmeta(pwd), &st1) < 0) { - setjobpwd(); - zsfree(pwd); - pwd = NULL; - pwd = metafy(zgetcwd(), -1, META_DUP); - } else if (stat(".", &st2) < 0) { - if (chdir(unmeta(pwd)) < 0) - zwarn("unable to chdir(%s): %e", pwd, errno); - } else if (st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev) { - if (chasinglinks) { - setjobpwd(); - zsfree(pwd); - pwd = NULL; - pwd = metafy(zgetcwd(), -1, META_DUP); - } else if (chdir(unmeta(pwd)) < 0) - zwarn("unable to chdir(%s): %e", pwd, errno); - } unqueue_signals(); return 0; } @@ -1210,6 +1192,7 @@ static void cd_new_pwd(int func, LinkNode dir, int quiet) { char *new_pwd, *s; + struct stat st1, st2; int dirstacksize; if (func == BIN_PUSHD) @@ -1239,6 +1222,22 @@ cd_new_pwd(int func, LinkNode dir, int quiet) } } + if (stat(unmeta(new_pwd), &st1) < 0) { + zsfree(new_pwd); + new_pwd = NULL; + new_pwd = metafy(zgetcwd(), -1, META_DUP); + } else if (stat(".", &st2) < 0) { + if (chdir(unmeta(new_pwd)) < 0) + zwarn("unable to chdir(%s): %e", new_pwd, errno); + } else if (st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev) { + if (chasinglinks) { + zsfree(new_pwd); + new_pwd = NULL; + new_pwd = metafy(zgetcwd(), -1, META_DUP); + } else if (chdir(unmeta(new_pwd)) < 0) + zwarn("unable to chdir(%s): %e", new_pwd, errno); + } + /* shift around the pwd variables, to make oldpwd and pwd relate to the current (i.e. new) pwd */ zsfree(oldpwd); diff --git a/Test/B01cd.ztst b/Test/B01cd.ztst index 21e751dcb..bc6757549 100644 --- a/Test/B01cd.ztst +++ b/Test/B01cd.ztst @@ -33,7 +33,7 @@ # # Tests should use subdirectories ending in `.tmp'. These will be # removed with all the contents even if the test is aborted. - mkdir cdtst.tmp cdtst.tmp/real cdtst.tmp/sub + mkdir cdtst.tmp cdtst.tmp/foo cdtst.tmp/real cdtst.tmp/sub ln -s ../real cdtst.tmp/sub/fake @@ -149,6 +149,23 @@ F:something is broken. But you already knew that. -f:(workers/45367) cd -P squashes multiple leading slashes >/dev + chpwd_hook() { hook_pwd=$PWD; } + chpwd_functions=(chpwd_hook) + cd $mydir/cdtst.tmp/foo && + (cd $mydir && mv $mydir/cdtst.tmp/{foo,bar}) && + print $PWD && + print $hook_pwd && + cd . && + print $PWD && + print $hook_pwd + chpwd_functions=() + unfunction chpwd_hook +0q:cd . with moved PWD +>$mydir/cdtst.tmp/foo +>$mydir/cdtst.tmp/foo +>$mydir/cdtst.tmp/bar +>$mydir/cdtst.tmp/bar + %clean # This optional section cleans up after the test, if necessary, # e.g. killing processes etc. This is in addition to the removal of *.tmp