mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
+10
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user