zsh-workers
 help / color / mirror / code / Atom feed
* mkdir -p buldtin is possibly incorrect?
@ 2005-07-14 19:02 George Kouryachy
  2005-07-14 20:18 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: George Kouryachy @ 2005-07-14 19:02 UTC (permalink / raw)
  To: zsh-workers

Hi.

Look at this, this is a part of zsh-4.3.0-20050611/Src/Modules/files.c:

    120 static int
    121 domkdir(char *nam, char *path, mode_t mode, int p)
    122 {
    123     int err;
    124     mode_t oumask;
    125     char const *rpath = unmeta(path);
    126 
    127     if(p) {
    128         struct stat st;
    129 
    130         if(!lstat(rpath, &st) && S_ISDIR(st.st_mode))
    131             return 0;
    132     }

Why do you use "lstat" instead of "stat" in line 130?
I have my $HOME symlinked as "/home -> /var/home",
so any first attempt to use completion smaps like tths:
_store_cache:mkdir:16: cannot make directory `/home': file exists

-- 
George V Kouryachy (aka Fr. Br. George)
mailto:george at gmail dot com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mkdir -p buldtin is possibly incorrect?
  2005-07-14 19:02 mkdir -p buldtin is possibly incorrect? George Kouryachy
@ 2005-07-14 20:18 ` Peter Stephenson
  2005-07-14 23:47   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2005-07-14 20:18 UTC (permalink / raw)
  To: Zsh hackers list

George Kouryachy wrote:
> Why do you use "lstat" instead of "stat" in line 130?
> I have my $HOME symlinked as "/home -> /var/home",
> so any first attempt to use completion smaps like tths:
> _store_cache:mkdir:16: cannot make directory `/home': file exists

Yes, it looks like you're right.

Index: Src/Modules/files.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/files.c,v
retrieving revision 1.12
diff -u -r1.12 files.c
--- Src/Modules/files.c	2 Jun 2004 22:15:00 -0000	1.12
+++ Src/Modules/files.c	14 Jul 2005 20:11:13 -0000
@@ -127,7 +127,7 @@
     if(p) {
 	struct stat st;
 
-	if(!lstat(rpath, &st) && S_ISDIR(st.st_mode))
+	if(!stat(rpath, &st) && S_ISDIR(st.st_mode))
 	    return 0;
     }
     oumask = umask(0);

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mkdir -p buldtin is possibly incorrect?
  2005-07-14 20:18 ` Peter Stephenson
@ 2005-07-14 23:47   ` Bart Schaefer
  2005-07-15  7:13     ` Alexey Tourbin
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2005-07-14 23:47 UTC (permalink / raw)
  To: Zsh hackers list

On Jul 14,  9:18pm, Peter Stephenson wrote:
}
} > Why do you use "lstat" instead of "stat" in line 130?
} > I have my $HOME symlinked as "/home -> /var/home",
} > so any first attempt to use completion smaps like tths:
} > _store_cache:mkdir:16: cannot make directory `/home': file exists
} 
} Yes, it looks like you're right.

Won't stat() return an error on a dangling symlink and therefore make
it appear that no file exists when in fact one does?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mkdir -p buldtin is possibly incorrect?
  2005-07-14 23:47   ` Bart Schaefer
@ 2005-07-15  7:13     ` Alexey Tourbin
  0 siblings, 0 replies; 4+ messages in thread
From: Alexey Tourbin @ 2005-07-15  7:13 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 704 bytes --]

On Thu, Jul 14, 2005 at 11:47:03PM +0000, Bart Schaefer wrote:
> Won't stat() return an error on a dangling symlink and therefore make
> it appear that no file exists when in fact one does?

There seems to be no problem with this, since subsequent mkdir() call
is going to fail with EEXIST.

   127      if(p) {
   128          struct stat st;
   129
   130          if(!stat(rpath, &st) && S_ISDIR(st.st_mode))
   131              return 0;
   132      }
   133      oumask = umask(0);
   134      err = mkdir(path, mode) ? errno : 0;
   135      umask(oumask);
   136      if(!err)
   137          return 0;
   138      zwarnnam(nam, "cannot make directory `%s': %e", path, err);
   139      return 1;

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-07-15  7:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-14 19:02 mkdir -p buldtin is possibly incorrect? George Kouryachy
2005-07-14 20:18 ` Peter Stephenson
2005-07-14 23:47   ` Bart Schaefer
2005-07-15  7:13     ` Alexey Tourbin

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).