From 1776ab28f0fb934d399361e6012945c70dcd996f Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Tue, 2 Apr 2019 17:27:30 -0700 Subject: Add test that symlinking over a directory returns EEXIST. Also remove comments in InodeOperations that required that implementation of some Create* operations ensure that the name does not already exist, since these checks are all centralized in the Dirent. PiperOrigin-RevId: 241637335 Change-Id: Id098dc6063ff7c38347af29d1369075ad1e89a58 --- test/syscalls/linux/symlink.cc | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'test/syscalls') diff --git a/test/syscalls/linux/symlink.cc b/test/syscalls/linux/symlink.cc index cfc87bc8f..ea6baf76a 100644 --- a/test/syscalls/linux/symlink.cc +++ b/test/syscalls/linux/symlink.cc @@ -113,23 +113,19 @@ TEST(SymlinkTest, CannotCreateSymlinkInReadOnlyDir) { } TEST(SymlinkTest, CannotSymlinkOverExistingFile) { - const std::string oldname = NewTempAbsPath(); - const std::string newname = NewTempAbsPath(); - - int oldfd; - int newfd; - ASSERT_THAT(oldfd = open(oldname.c_str(), O_CREAT | O_RDWR, 0666), - SyscallSucceeds()); - EXPECT_THAT(close(oldfd), SyscallSucceeds()); - ASSERT_THAT(newfd = open(newname.c_str(), O_CREAT | O_RDWR, 0666), - SyscallSucceeds()); - EXPECT_THAT(close(newfd), SyscallSucceeds()); + const auto oldfile = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); + const auto newfile = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); - EXPECT_THAT(symlink(oldname.c_str(), newname.c_str()), + EXPECT_THAT(symlink(oldfile.path().c_str(), newfile.path().c_str()), SyscallFailsWithErrno(EEXIST)); +} - EXPECT_THAT(unlink(oldname.c_str()), SyscallSucceeds()); - EXPECT_THAT(unlink(newname.c_str()), SyscallSucceeds()); +TEST(SymlinkTest, CannotSymlinkOverExistingDir) { + const auto oldfile = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); + const auto newdir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); + + EXPECT_THAT(symlink(oldfile.path().c_str(), newdir.path().c_str()), + SyscallFailsWithErrno(EEXIST)); } TEST(SymlinkTest, OldnameIsEmpty) { -- cgit v1.2.3