aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/LockFileManagerTest.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-03-21 01:25:37 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-03-21 01:25:37 +0000
commit37575693186976cf7828832e48b4b75edc469cd1 (patch)
tree9011d8b634b05732bd5ca382efbc65ef9784d888 /llvm/unittests/Support/LockFileManagerTest.cpp
parentf1b10242c071a049fb4fdf9cf332946ed8dee367 (diff)
downloadllvm-37575693186976cf7828832e48b4b75edc469cd1.zip
llvm-37575693186976cf7828832e48b4b75edc469cd1.tar.gz
llvm-37575693186976cf7828832e48b4b75edc469cd1.tar.bz2
[Support] Make sure sys::fs::remove can remove symbolic links and make sure LockFileManager can handle a symbolic link that points nowhere.
llvm-svn: 204422
Diffstat (limited to 'llvm/unittests/Support/LockFileManagerTest.cpp')
-rw-r--r--llvm/unittests/Support/LockFileManagerTest.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/unittests/Support/LockFileManagerTest.cpp b/llvm/unittests/Support/LockFileManagerTest.cpp
index 1f949a3..6392739 100644
--- a/llvm/unittests/Support/LockFileManagerTest.cpp
+++ b/llvm/unittests/Support/LockFileManagerTest.cpp
@@ -44,4 +44,36 @@ TEST(LockFileManagerTest, Basic) {
ASSERT_FALSE(EC);
}
+TEST(LockFileManagerTest, LinkLockExists) {
+ SmallString<64> TmpDir;
+ error_code EC;
+ EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
+ ASSERT_FALSE(EC);
+
+ SmallString<64> LockedFile(TmpDir);
+ sys::path::append(LockedFile, "file");
+
+ SmallString<64> FileLocK(TmpDir);
+ sys::path::append(FileLocK, "file.lock");
+
+ SmallString<64> TmpFileLock(TmpDir);
+ sys::path::append(TmpFileLock, "file.lock-000");
+
+ EC = sys::fs::create_link(TmpFileLock.str(), FileLocK.str());
+ ASSERT_FALSE(EC);
+
+ {
+ // The lock file doesn't point to a real file, so we should successfully
+ // acquire it.
+ LockFileManager Locked(LockedFile);
+ EXPECT_EQ(LockFileManager::LFS_Owned, Locked.getState());
+ }
+
+ // Now that the lock is out of scope, the file should be gone.
+ EXPECT_FALSE(sys::fs::exists(StringRef(LockedFile)));
+
+ EC = sys::fs::remove(StringRef(TmpDir));
+ ASSERT_FALSE(EC);
+}
+
} // end anonymous namespace