Mercurial > hg > toybox
comparison toys/cp.c @ 272:a5652aa22f38
Another cp -r fix, another test case...
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 26 Mar 2008 00:54:56 -0500 |
parents | 7d625cbdde25 |
children | a08f1affe016 |
comparison
equal
deleted
inserted
replaced
271:7d625cbdde25 | 272:a5652aa22f38 |
---|---|
67 // Yes, there's a race window between mkdir() and open() so it's | 67 // Yes, there's a race window between mkdir() and open() so it's |
68 // possible that -p can be made to chown a directory other than the one | 68 // possible that -p can be made to chown a directory other than the one |
69 // we created. The closest we can do to closing this is make sure | 69 // we created. The closest we can do to closing this is make sure |
70 // that what we open _is_ a directory rather than something else. | 70 // that what we open _is_ a directory rather than something else. |
71 | 71 |
72 if (mkdir(dst, srcst->st_mode | 0200) || 0>(fdout=open(dst, 0)) | 72 if ((mkdir(dst, srcst->st_mode | 0200) && errno != EEXIST) |
73 || fstat(fdout, &st2) || !S_ISDIR(st2.st_mode)) | 73 || 0>(fdout=open(dst, 0)) || fstat(fdout, &st2) |
74 || !S_ISDIR(st2.st_mode)) | |
74 { | 75 { |
75 perror_exit("mkdir '%s'", dst); | 76 perror_exit("mkdir '%s'", dst); |
76 } | 77 } |
77 } else if (TT.keep_symlinks && S_ISLNK(srcst->st_mode)) { | 78 } else if (TT.keep_symlinks && S_ISLNK(srcst->st_mode)) { |
78 char *link = xreadlink(src); | 79 char *link = xreadlink(src); |