MCPcopy Create free account
hub / github.com/CppMicroServices/CppMicroServices / GetPersistentStoragePath

Function GetPersistentStoragePath

framework/src/util/Utils.cpp:125–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123 }
124
125 std::string
126 GetPersistentStoragePath(CoreBundleContext* ctx, std::string const& leafDir, bool create)
127 {
128 // See if we have a storage directory
129 std::string const fwdir(GetFrameworkDir(ctx));
130 if (fwdir.empty())
131 {
132 return fwdir;
133 }
134 std::string const dir = util::GetAbsolute(fwdir, ctx->workingDir) + util::DIR_SEP + leafDir;
135 if (!dir.empty())
136 {
137 if (util::Exists(dir))
138 {
139 if (!util::IsDirectory(dir))
140 {
141 throw std::runtime_error("Not a directory: " + dir);
142 }
143 }
144 else
145 {
146 if (create)
147 {
148 try
149 {
150 util::MakePath(dir);
151 }
152 catch (std::exception const& e)
153 {
154 throw std::runtime_error("Cannot create directory: " + dir + " (" + e.what() + ")");
155 }
156 }
157 }
158 }
159 return dir;
160 }
161
162 void
163 TerminateForDebug(std::exception_ptr const ex)

Callers 1

InitMethod · 0.85

Calls 7

GetFrameworkDirFunction · 0.85
GetAbsoluteFunction · 0.85
ExistsFunction · 0.85
IsDirectoryFunction · 0.85
MakePathFunction · 0.85
emptyMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected