| 291 | } |
| 292 | |
| 293 | bool HashedStorage::Init(const char * chars, size_t count) |
| 294 | { |
| 295 | try |
| 296 | { |
| 297 | if (!fs_lib::exists(root)) |
| 298 | fs_lib::create_directories(root); |
| 299 | |
| 300 | for (size_t i = 0; i < count; i++) |
| 301 | { |
| 302 | auto p = root + i2p::fs::dirSep + prefix1 + chars[i]; |
| 303 | if (fs_lib::exists(p)) |
| 304 | continue; |
| 305 | #if TARGET_OS_SIMULATOR |
| 306 | // ios simulator fs says it is case sensitive, but it is not |
| 307 | boost::system::error_code ec; |
| 308 | if (fs_lib::create_directory(p, ec)) |
| 309 | continue; |
| 310 | switch (ec.value()) { |
| 311 | case boost::system::errc::file_exists: |
| 312 | case boost::system::errc::success: |
| 313 | continue; |
| 314 | default: |
| 315 | throw boost::system::system_error( ec, __func__ ); |
| 316 | } |
| 317 | #else |
| 318 | if (fs_lib::create_directory(p)) |
| 319 | continue; /* ^ throws exception on failure */ |
| 320 | #endif |
| 321 | return false; |
| 322 | } |
| 323 | } |
| 324 | catch (std::exception& ex) |
| 325 | { |
| 326 | LogPrint (eLogCritical, "FS: Can't init storage ", root, ": ", ex.what()); |
| 327 | ThrowFatal ("Can't init FS storage ", root, ": ", ex.what()); |
| 328 | return false; |
| 329 | } |
| 330 | return true; |
| 331 | } |
| 332 | |
| 333 | std::string HashedStorage::Path(const std::string & ident) const { |
| 334 | std::string safe_ident = ident; |
no test coverage detected