From: Jeff King <peff@peff.net>
To: Shawn Bohrer <shawn.bohrer@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH] Make git-clean a builtin
Date: Sun, 7 Oct 2007 22:04:35 -0400 [thread overview]
Message-ID: <20071008020435.GA20050@coredump.intra.peff.net> (raw)
In-Reply-To: <11917040461528-git-send-email-shawn.bohrer@gmail.com>
On Sat, Oct 06, 2007 at 03:54:06PM -0500, Shawn Bohrer wrote:
> +static int remove_directory(const char *path)
> +{
> [...]
> + chdir(path);
> [...]
> + chdir("..");
This doesn't always put you back where you started, due to symlinks. For
example:
cat >foo.c <<'EOF'
int main(int argc, char **argv) {
chdir(argv[1]);
chdir("..");
execlp("ls", 0);
}
EOF
gcc -o foo foo.c
ln -s /tmp sub
./foo sub
will show that you end up in the root directory. Something like this is
more robust:
fd = open(".", O_RDONLY);
chdir(path);
...
fchdir(fd);
In general, you shouldn't end up there because you don't actually
recurse for symlinks, but there is a race condition (and losing it means
you start recursively removing unintended directories -- oops).
On top of which, this line from the same function isn't very portable:
+ if (dir->d_type == DT_DIR)
since POSIX specifies nothing but dir->d_name (Solaris, for example,
doesn't define d_type). You need to stat the file.
All of that being said, I think a lot of this is already done in
dir.[ch]. At the very least, you should be able to use
remove_dir_recursively, and for bonus points you can get rid of the
start_command call to ls-files by just walking the dir tree yourself.
I don't know if the latter is required, but it's nice when the
C-ification actually cleans up a bit and uses the internal C interfaces
(which are more efficient and often more clear to read) rather than just
converting shell to C.
-Peff
next prev parent reply other threads:[~2007-10-08 2:04 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-06 20:54 [PATCH] Make git-clean a builtin Shawn Bohrer
2007-10-06 21:52 ` Frank Lichtenheld
2007-10-07 1:13 ` Shawn Bohrer
2007-10-08 2:04 ` Jeff King [this message]
2007-10-08 2:08 ` Jeff King
2007-10-08 2:17 ` Linus Torvalds
2007-10-08 2:22 ` Jeff King
2007-10-08 6:37 ` Johannes Sixt
2007-10-08 18:27 ` Linus Torvalds
-- strict thread matches above, loose matches on Subject: below --
2007-10-07 1:17 Shawn Bohrer
2007-10-07 1:31 ` Linus Torvalds
2007-10-07 15:41 ` Shawn Bohrer
2007-10-07 16:42 ` rae l
2007-10-07 16:38 ` Johannes Schindelin
2007-10-07 23:57 Shawn Bohrer
2007-10-08 3:57 ` Johannes Schindelin
2007-11-04 19:02 [RFC] Second attempt at making " Shawn Bohrer
2007-11-04 19:02 ` [PATCH] Add more tests for git-clean Shawn Bohrer
2007-11-04 19:02 ` [PATCH] Make git-clean a builtin Shawn Bohrer
2007-11-04 19:41 ` Pierre Habouzit
2007-11-05 21:14 ` Junio C Hamano
2007-11-05 22:10 ` Carlos Rica
2007-11-05 23:54 ` Junio C Hamano
2007-11-06 5:05 ` Shawn Bohrer
2007-11-06 5:30 ` Junio C Hamano
2007-11-07 5:18 Shawn Bohrer
2007-11-07 11:10 ` Johannes Schindelin
2007-11-07 13:29 ` Bill Lear
2007-11-07 14:17 ` Johannes Schindelin
2007-11-07 14:45 ` Matthieu Moy
2007-11-07 19:46 ` Jon Loeliger
2007-11-10 22:43 ` Miles Bader
2007-11-07 14:54 ` Shawn Bohrer
2007-11-07 15:04 ` Johannes Schindelin
2007-11-07 20:51 ` Brian Downing
2007-11-07 21:49 ` Junio C Hamano
2007-11-07 20:42 ` Junio C Hamano
2007-11-08 5:37 ` Shawn Bohrer
2007-11-12 1:48 Shawn Bohrer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071008020435.GA20050@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=shawn.bohrer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).