MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / CreateFileContentHash

Function CreateFileContentHash

src/OpenColorIO/Platform.cpp:333–357  ·  view source on GitHub ↗

That's the default hash method implementation to compute a hash key based on a file content.

Source from the content-addressed store, hash-verified

331
332// That's the default hash method implementation to compute a hash key based on a file content.
333std::string CreateFileContentHash(const std::string &filename)
334{
335#if defined(_WIN32) && defined(UNICODE)
336 struct _stat fileInfo;
337 if (_wstat(Platform::Utf8ToUtf16(filename).c_str(), &fileInfo) == 0)
338#else
339 struct stat fileInfo;
340 if (stat(filename.c_str(), &fileInfo) == 0)
341#endif
342 {
343 // Treat the st_dev (i.e. device) + st_ino (i.e. inode) as a proxy for the contents.
344
345 std::ostringstream fasthash;
346 fasthash << fileInfo.st_dev << ":";
347#ifdef _WIN32
348 // TODO: The hard-linked files are then not correctly supported on Windows platforms.
349 fasthash << std::hash<std::string>{}(filename);
350#else
351 fasthash << fileInfo.st_ino;
352#endif
353 return fasthash.str();
354 }
355
356 return "";
357}
358
359} // Platform
360

Callers

nothing calls this directly

Calls 2

Utf8ToUtf16Function · 0.85
statClass · 0.85

Tested by

no test coverage detected