Do not consider symlinks as directories in fs utils.

IsDirectory() is used in RecursivelyDelete(), which should not follow symlinks.
The only other use (syscalls/linux/rename.cc) is not affected by this change.

Updates #1366.

PiperOrigin-RevId: 284803968
This commit is contained in:
Dean Deng
2019-12-10 11:09:44 -08:00
committed by gVisor bot
parent c15be3f8cf
commit f47eaffd5c
+10 -1
View File
@@ -105,6 +105,15 @@ PosixErrorOr<struct stat> Stat(absl::string_view path) {
return stat_buf;
}
PosixErrorOr<struct stat> Lstat(absl::string_view path) {
struct stat stat_buf;
int res = lstat(std::string(path).c_str(), &stat_buf);
if (res < 0) {
return PosixError(errno, absl::StrCat("lstat ", path));
}
return stat_buf;
}
PosixErrorOr<struct stat> Fstat(int fd) {
struct stat stat_buf;
int res = fstat(fd, &stat_buf);
@@ -127,7 +136,7 @@ PosixErrorOr<bool> Exists(absl::string_view path) {
}
PosixErrorOr<bool> IsDirectory(absl::string_view path) {
ASSIGN_OR_RETURN_ERRNO(struct stat stat_buf, Stat(path));
ASSIGN_OR_RETURN_ERRNO(struct stat stat_buf, Lstat(path));
if (S_ISDIR(stat_buf.st_mode)) {
return true;
}