[llvm] r204426 - [Support] Make sure LockFileManager works correctly with relative paths.

Aaron Ballman aaron at aaronballman.com
Fri Mar 21 13:37:36 PDT 2014


This seems to have broken things on Windows:

http://bb.pgr.jp/builders/ninja-clang-x64-mingw64-RA/builds/1640

I can confirm the behavior with MSVC 2013 as well -- backing this
revision out resolves the test breakages for me.

~Aaron

On Thu, Mar 20, 2014 at 10:31 PM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
> Author: akirtzidis
> Date: Thu Mar 20 21:31:56 2014
> New Revision: 204426
>
> URL: http://llvm.org/viewvc/llvm-project?rev=204426&view=rev
> Log:
> [Support] Make sure LockFileManager works correctly with relative paths.
>
> Modified:
>     llvm/trunk/lib/Support/LockFileManager.cpp
>     llvm/trunk/unittests/Support/LockFileManagerTest.cpp
>
> Modified: llvm/trunk/lib/Support/LockFileManager.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/LockFileManager.cpp?rev=204426&r1=204425&r2=204426&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/LockFileManager.cpp (original)
> +++ llvm/trunk/lib/Support/LockFileManager.cpp Thu Mar 20 21:31:56 2014
> @@ -11,6 +11,7 @@
>  #include "llvm/ADT/StringExtras.h"
>  #include "llvm/Support/FileSystem.h"
>  #include "llvm/Support/MemoryBuffer.h"
> +#include "llvm/Support/Path.h"
>  #include "llvm/Support/raw_ostream.h"
>  #include <sys/stat.h>
>  #include <sys/types.h>
> @@ -115,7 +116,8 @@ LockFileManager::LockFileManager(StringR
>    while (1) {
>      // Create a link from the lock file name. If this succeeds, we're done.
>      error_code EC =
> -        sys::fs::create_link(UniqueLockFileName.str(), LockFileName.str());
> +        sys::fs::create_link(sys::path::filename(UniqueLockFileName.str()),
> +                             LockFileName.str());
>      if (EC == errc::success)
>        return;
>
>
> Modified: llvm/trunk/unittests/Support/LockFileManagerTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/LockFileManagerTest.cpp?rev=204426&r1=204425&r2=204426&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Support/LockFileManagerTest.cpp (original)
> +++ llvm/trunk/unittests/Support/LockFileManagerTest.cpp Thu Mar 20 21:31:56 2014
> @@ -76,4 +76,41 @@ TEST(LockFileManagerTest, LinkLockExists
>    ASSERT_FALSE(EC);
>  }
>
> +
> +TEST(LockFileManagerTest, RelativePath) {
> +  SmallString<64> TmpDir;
> +  error_code EC;
> +  EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
> +  ASSERT_FALSE(EC);
> +
> +  char PathBuf[1024];
> +  const char *OrigPath = getcwd(PathBuf, 1024);
> +  chdir(TmpDir.c_str());
> +
> +  sys::fs::create_directory("inner");
> +  SmallString<64> LockedFile("inner");
> +  sys::path::append(LockedFile, "file");
> +
> +  SmallString<64> FileLock(LockedFile);
> +  FileLock += ".lock";
> +
> +  {
> +    // The lock file should not exist, so we should successfully acquire it.
> +    LockFileManager Locked(LockedFile);
> +    EXPECT_EQ(LockFileManager::LFS_Owned, Locked.getState());
> +    EXPECT_TRUE(sys::fs::exists(FileLock.str()));
> +  }
> +
> +  // Now that the lock is out of scope, the file should be gone.
> +  EXPECT_FALSE(sys::fs::exists(LockedFile.str()));
> +  EXPECT_FALSE(sys::fs::exists(FileLock.str()));
> +
> +  EC = sys::fs::remove("inner");
> +  ASSERT_FALSE(EC);
> +  EC = sys::fs::remove(StringRef(TmpDir));
> +  ASSERT_FALSE(EC);
> +
> +  chdir(OrigPath);
> +}
> +
>  } // end anonymous namespace
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list