diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2019-04-02 17:27:30 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-02 17:28:36 -0700 |
commit | 1776ab28f0fb934d399361e6012945c70dcd996f (patch) | |
tree | 4c4cdd0f8e9e528c852332b41b3271fb57cdab7a /test | |
parent | f9431fb20f24834dd1d5c450631bdfa04fe042f4 (diff) |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/syscalls/linux/symlink.cc | 24 |
1 files changed, 10 insertions, 14 deletions
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) { |