ExtractSink writing under a destination root via FILE*.
| 220 | |
| 221 | // ExtractSink writing under a destination root via FILE*. |
| 222 | struct FileExtractSink : TransferProto::ExtractSink { |
| 223 | std::string destRoot; |
| 224 | FILE* output = nullptr; |
| 225 | explicit FileExtractSink(std::string root) : destRoot(std::move(root)) {} |
| 226 | bool makeDir(const std::string& relPath) override |
| 227 | { |
| 228 | std::string dirPath = destRoot + relPath; |
| 229 | if (!io::directoryExists(dirPath)) { |
| 230 | io::createDirectory(dirPath); |
| 231 | } |
| 232 | return true; |
| 233 | } |
| 234 | bool beginFile(const std::string& relPath, uint32_t) override |
| 235 | { |
| 236 | ensureDirectoryPath(destRoot, relPath); |
| 237 | output = fopen((destRoot + relPath).c_str(), "wb"); |
| 238 | return output != nullptr; |
| 239 | } |
| 240 | bool writeFile(const void* data, size_t n) override |
| 241 | { |
| 242 | fwrite(data, 1, n, output); |
| 243 | return true; |
| 244 | } |
| 245 | void endFile() override |
| 246 | { |
| 247 | if (output != nullptr) { |
| 248 | fclose(output); |
| 249 | output = nullptr; |
| 250 | } |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | // FileReader opening backup files via FILE* for the send. |
| 255 | struct StdFileReader : TransferProto::FileReader { |
nothing calls this directly
no outgoing calls
no test coverage detected