Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/pax use stat and not lstat to detect if we have a direct...
details: https://anonhg.NetBSD.org/src/rev/028c5348d2e3
branches: trunk
changeset: 584342:028c5348d2e3
user: christos <christos%NetBSD.org@localhost>
date: Tue Sep 13 20:09:55 2005 +0000
description:
use stat and not lstat to detect if we have a directory. refactor the mkpath()
code.
diffstat:
bin/pax/file_subs.c | 6 +++---
bin/pax/options.c | 29 ++++++++++++++++++-----------
2 files changed, 21 insertions(+), 14 deletions(-)
diffs (85 lines):
diff -r f92f22697c4f -r 028c5348d2e3 bin/pax/file_subs.c
--- a/bin/pax/file_subs.c Tue Sep 13 20:02:05 2005 +0000
+++ b/bin/pax/file_subs.c Tue Sep 13 20:09:55 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: file_subs.c,v 1.54 2005/09/13 15:50:17 christos Exp $ */
+/* $NetBSD: file_subs.c,v 1.55 2005/09/13 20:09:55 christos Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)file_subs.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: file_subs.c,v 1.54 2005/09/13 15:50:17 christos Exp $");
+__RCSID("$NetBSD: file_subs.c,v 1.55 2005/09/13 20:09:55 christos Exp $");
#endif
#endif /* not lint */
@@ -470,7 +470,7 @@
* Something's in the way.
* If it's a directory, say we're done.
*/
- if (lstat(nm, &sb) == 0 &&
+ if (stat(nm, &sb) == 0 &&
S_ISDIR(sb.st_mode)) {
res = 0;
break;
diff -r f92f22697c4f -r 028c5348d2e3 bin/pax/options.c
--- a/bin/pax/options.c Tue Sep 13 20:02:05 2005 +0000
+++ b/bin/pax/options.c Tue Sep 13 20:09:55 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: options.c,v 1.90 2005/09/13 15:50:17 christos Exp $ */
+/* $NetBSD: options.c,v 1.91 2005/09/13 20:09:55 christos Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
#else
-__RCSID("$NetBSD: options.c,v 1.90 2005/09/13 15:50:17 christos Exp $");
+__RCSID("$NetBSD: options.c,v 1.91 2005/09/13 20:09:55 christos Exp $");
#endif
#endif /* not lint */
@@ -1335,16 +1335,19 @@
done = (*slash == '\0');
*slash = '\0';
- if (mkdir(path, 0777) == -1) {
- /* Check if it was created it for us in the meantime */
- sverrno = errno;
-
- if (lstat(path, &sb) == -1 || !S_ISDIR(sb.st_mode)) {
- /* Can't create or or not a directory */
- syswarn(1, sverrno,
- "Cannot create directory `%s'", path);
- return -1;
+ if (stat(path, &sb) == -1) {
+ if ((sverrno = errno) != ENOENT)
+ goto out;
+ if (mkdir(path, 0777) == -1) {
+ sverrno = errno;
+ /* Check again, to avoid races */
+ if (stat(path, &sb) == -1
+ || !S_ISDIR(sb.st_mode))
+ goto out;
}
+ } else if (!S_ISDIR(sb.st_mode)) {
+ sverrno = ENOTDIR;
+ goto out;
}
if (!done)
@@ -1352,6 +1355,10 @@
}
return 0;
+out:
+ /* Can't create or or not a directory */
+ syswarn(1, sverrno, "Cannot create directory `%s'", path);
+ return -1;
}
Home |
Main Index |
Thread Index |
Old Index