| 72 | } |
| 73 | |
| 74 | NvmCacheState::NvmCacheState(uint32_t currentTimeSecs, |
| 75 | const std::string& cacheDir, |
| 76 | bool encryptionEnabled, |
| 77 | bool truncateAllocSize) |
| 78 | : cacheDir_(cacheDir), |
| 79 | creationTime_{currentTimeSecs}, |
| 80 | encryptionEnabled_{encryptionEnabled}, |
| 81 | truncateAllocSize_{truncateAllocSize} { |
| 82 | if (cacheDir_.empty()) { |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | if (!fileExists(cacheDir_)) { |
| 87 | util::makeDir(cacheDir_); |
| 88 | } else if (!util::isDir(cacheDir_)) { |
| 89 | throw std::invalid_argument( |
| 90 | fmt::format("Expected {} to be directory", cacheDir_)); |
| 91 | } |
| 92 | |
| 93 | restoreState(); |
| 94 | |
| 95 | // Keep a stream open for the metadata |
| 96 | metadataFile_ = std::make_unique<folly::File>(getFileNameFor(kNvmCacheState), |
| 97 | O_CREAT | O_TRUNC | O_RDWR); |
| 98 | XDCHECK(metadataFile_); |
| 99 | } |
| 100 | |
| 101 | void NvmCacheState::restoreState() { |
| 102 | // Read previous instance state from nvm state file |
nothing calls this directly
no test coverage detected