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

Function GetFastFileHash

src/OpenColorIO/PathUtils.cpp:64–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64std::string GetFastFileHash(const std::string & filename, const Context & context)
65{
66 FileHashResultPtr fileHashResultPtr;
67 {
68 AutoMutex lock(g_fastFileHashCache_mutex);
69 FileCacheMap::iterator iter = g_fastFileHashCache.find(filename);
70 if(iter != g_fastFileHashCache.end())
71 {
72 fileHashResultPtr = iter->second;
73 }
74 else
75 {
76 fileHashResultPtr = std::make_shared<FileHashResult>();
77 g_fastFileHashCache[filename] = fileHashResultPtr;
78 }
79 }
80
81 std::string hash;
82 {
83 AutoMutex lock(fileHashResultPtr->mutex);
84 if(!fileHashResultPtr->ready)
85 {
86 // NB: OCIO does not attempt to detect if files have changed and caused the cache to
87 // become stale.
88 fileHashResultPtr->ready = true;
89
90 std::string h = "";
91 if (context.getConfigIOProxy())
92 {
93 // Case for when ConfigIOProxy is used (callbacks mechanism).
94 h = context.getConfigIOProxy()->getFastLutFileHash(filename.c_str());
95
96 // For absolute paths, if the proxy does not provide a hash, try the file system.
97 if (h.empty() && pystring::os::path::isabs(filename))
98 {
99 h = g_hashFunction(filename);
100 }
101 }
102 else
103 {
104 // Default case
105 h = g_hashFunction(filename);
106 }
107
108 fileHashResultPtr->hash = h;
109 }
110
111 hash = fileHashResultPtr->hash;
112 }
113
114 return hash;
115}
116
117bool FileExists(const std::string & filename, const Context & context)
118{

Callers 2

getCacheIDMethod · 0.85
FileExistsFunction · 0.85

Calls 4

endMethod · 0.45
getConfigIOProxyMethod · 0.45
getFastLutFileHashMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected