| 977 | } |
| 978 | |
| 979 | void deserialize_file(const std::string &filename, off_t filesize, bool write_file, bool dryrun, bool do_direct_io) { |
| 980 | /* must be a multiple of 512! */ |
| 981 | #define DESERIALIZE_BUFSIZE 1024*1024 |
| 982 | static char buf[DESERIALIZE_BUFSIZE]; |
| 983 | int rb; // read bytes |
| 984 | const int bufsz = DESERIALIZE_BUFSIZE; |
| 985 | |
| 986 | std::unique_ptr<fdostream> out; |
| 987 | if (write_file && !dryrun) |
| 988 | out = output_file(filename, false, do_direct_io); |
| 989 | |
| 990 | for (int i = 0; i < filesize / sizeof(buf); i++) { |
| 991 | rb = readall(0, buf, sizeof(buf)); |
| 992 | if (rb != sizeof(buf)) { |
| 993 | std::ostringstream ss; |
| 994 | ss << "Unexpected eof reading " << filename; |
| 995 | throw Error(ss.str()); |
| 996 | } |
| 997 | if (write_file && !dryrun) |
| 998 | out->write(buf, bufsz); |
| 999 | else if (dryrun) { |
| 1000 | std::cout << filename << ": " << bufsz << " bytes written" << std::endl; |
| 1001 | } |
| 1002 | } |
| 1003 | if (filesize % bufsz) { |
| 1004 | int remnant = filesize % bufsz; |
| 1005 | rb = readall(0, buf, remnant); |
| 1006 | if (rb != remnant) { |
| 1007 | std::ostringstream ss; |
| 1008 | ss << "Unexpected eof (last buffer) for " << filename; |
| 1009 | throw Error(ss.str()); |
| 1010 | } |
| 1011 | if (write_file && !dryrun) |
| 1012 | out->write(buf, remnant); |
| 1013 | else if (dryrun) |
| 1014 | std::cout << filename << ": " << remnant << " bytes written (remnant)" << std::endl; |
| 1015 | if (remnant % 512) { |
| 1016 | remnant = 512 - (remnant % 512); |
| 1017 | rb = readall(0, buf, remnant); |
| 1018 | if (rb != remnant) { |
| 1019 | std::ostringstream ss; |
| 1020 | ss << "Unexpected eof (padding) for " << filename; |
| 1021 | throw Error(ss.str()); |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | void restore_partials( |
| 1028 | const std::string &lrlpath, const std::string& comdb2_task, bool run_full_recovery, bool do_direct_io, bool dryrun |
no test coverage detected