[llvm] r184217 - Add a GetUniqueID that will replace the uniqueID of PathV1.h.

Aaron Ballman aaron at aaronballman.com
Wed Jun 19 11:11:51 PDT 2013


On Tue, Jun 18, 2013 at 3:34 PM, Rafael Espindola
<rafael.espindola at gmail.com> wrote:
> Author: rafael
> Date: Tue Jun 18 14:34:49 2013
> New Revision: 184217
>
> URL: http://llvm.org/viewvc/llvm-project?rev=184217&view=rev
> Log:
> Add a GetUniqueID that will replace the uniqueID of PathV1.h.
>
> Modified:
>     llvm/trunk/include/llvm/Support/FileSystem.h
>     llvm/trunk/lib/Support/Unix/PathV2.inc
>     llvm/trunk/lib/Support/Windows/PathV2.inc
>
> Modified: llvm/trunk/include/llvm/Support/FileSystem.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=184217&r1=184216&r2=184217&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/FileSystem.h (original)
> +++ llvm/trunk/include/llvm/Support/FileSystem.h Tue Jun 18 14:34:49 2013
> @@ -556,6 +556,8 @@ file_magic identify_magic(StringRef magi
>  ///          platform specific error_code.
>  error_code identify_magic(const Twine &path, file_magic &result);
>
> +error_code GetUniqueID(const Twine Path, uint64_t &Result);
> +
>  /// This class represents a memory mapped file. It is based on
>  /// boost::iostreams::mapped_file.
>  class mapped_file_region {
>
> Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=184217&r1=184216&r2=184217&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
> +++ llvm/trunk/lib/Support/Unix/PathV2.inc Tue Jun 18 14:34:49 2013
> @@ -350,6 +350,18 @@ error_code file_size(const Twine &path,
>    return error_code::success();
>  }
>
> +error_code GetUniqueID(const Twine Path, uint64_t &Result) {
> +  SmallString<128> Storage;
> +  StringRef P = Path.toNullTerminatedStringRef(Storage);
> +
> +  struct stat Status;
> +  if (::stat(P.begin(), &Status) != 0)
> +    return error_code(errno, system_category());
> +
> +  Result = Status.st_ino;
> +  return error_code::success();
> +}
> +
>  error_code status(const Twine &path, file_status &result) {
>    SmallString<128> path_storage;
>    StringRef p = path.toNullTerminatedStringRef(path_storage);
>
> Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=184217&r1=184216&r2=184217&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
> +++ llvm/trunk/lib/Support/Windows/PathV2.inc Tue Jun 18 14:34:49 2013
> @@ -413,6 +413,20 @@ error_code file_size(const Twine &path,
>    return error_code::success();
>  }
>
> +error_code GetUniqueID(const Twine Path, uint64_t &Result) {
> +  // FIXME: this is only unique if the file is accessed by the same file path.
> +  // How do we do this for C:\dir\file and ..\dir\file ? Unix has inode
> +  // numbers, but the concept doesn't exist in Windows.

You can use GetFileInformationByHandle (on an opened file handle) to
get this -- the volume serial number plus nFileIndexHigh and Low
uniquely identify the file on a machine.  Note that this identifier
isn't unique over time (the file system can reuse the ids), so
hopefully you don't need this for long periods of time.

~Aaron



More information about the llvm-commits mailing list