[PATCH 1/2] unpack-trees: handle lstat failure for existing directory
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Jan 13, 2011, 02:26 UTC
- Message-ID
- <20110113022636.GB8635@burratino>
- In-Reply-To
- <20110113022415.GA8635@burratino>
When check_leading_path notices no file in the way of the new entry to be checked out, verify_absent checks whether there is a directory there or nothing at all. If that lstat call fails (for example due to ENOMEM), it assumes ENOENT, meaning a directory with untracked files would be clobbered in that case.
Check errno after calling lstat, and for conditions other than ENOENT, just error out.
This is a theoretical race condition. lstat has to succeed moments before it fails for there to be trouble.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> --- Does this need an o->gently check?
unpack-trees.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c index 1ca41b1..a795db5 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1382,7 +1382,9 @@ static int verify_absent_1(struct cache_entry *ce, return check_ok_to_remove(ce->name, ce_namelen(ce), ce_to_dtype(ce), ce, &st, error_type, o); - + if (errno != ENOENT) + return error("cannot stat '%s': %s", ce->name, + strerror(errno)); return 0; }
-- 1.7.4.rc1