unpack-trees: handle lstat failure for existing directory
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Jan 12, 2011 at 20:26 UTC
92fda79ed048d2d37e760e7a1b6055b2fc801ee3
1 file changed
+9
-5
unpack-trees.c
+9
-5
@@ -1197,12 +1197,16 @@ static int verify_absent_1(struct cache_entry *ce,
1197
1198
return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
1199
error_type, o);
1200
- } else if (!lstat(ce->name, &st))
1200
+ } else if (lstat(ce->name, &st)) {
1201
+ if (errno != ENOENT)
1202
+ return error("cannot stat '%s': %s", ce->name,
1203
+ strerror(errno));
1204
+ return 0;
1205
+ } else {
1206
return check_ok_to_remove(ce->name, ce_namelen(ce),
1202
- ce_to_dtype(ce), ce, &st,
1203
- error_type, o);
1204
-
1205
- return 0;
1207
+ ce_to_dtype(ce), ce, &st,
1208
+ error_type, o);
1209
+ }
1210
}
1211
1212
static int verify_absent(struct cache_entry *ce,