a session to restore: the name itself is opened, never what a link or reparse point there points to; it must be an ordinary disk file with one name
| 174 | // a session to restore: the name itself is opened, never what a link or reparse point there points to; it must be |
| 175 | // an ordinary disk file with one name |
| 176 | bool open_session(const std::string& path, uint64_t& size) { |
| 177 | std::wstring w; |
| 178 | if (!wide(path, w)) { refused_ = true; error_ = "the path is not valid UTF-8"; return false; } |
| 179 | h_ = CreateFileW(w.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, |
| 180 | FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_SEQUENTIAL_SCAN, nullptr); |
| 181 | if (h_ == INVALID_HANDLE_VALUE) { { const DWORD c_ = GetLastError(); kind_ = win_kind(c_); error_ = last_error(c_); } return false; } |
| 182 | BY_HANDLE_FILE_INFORMATION info{}; |
| 183 | if (!GetFileInformationByHandle(h_, &info)) { { const DWORD c_ = GetLastError(); kind_ = win_kind(c_); error_ = last_error(c_); } return false; } |
| 184 | if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { refused_ = true; error_ = "a link or reparse point, not a file"; return false; } |
| 185 | if ((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || GetFileType(h_) != FILE_TYPE_DISK) { |
| 186 | refused_ = true; |
| 187 | error_ = "not a regular file"; |
| 188 | return false; |
| 189 | } |
| 190 | if (info.nNumberOfLinks != 1) { refused_ = true; error_ = "the file has more than one name (hard link)"; return false; } |
| 191 | size = (uint64_t(info.nFileSizeHigh) << 32) | info.nFileSizeLow; |
| 192 | return true; |
| 193 | } |
| 194 | // a model input: links followed (model folders are often linked) |
| 195 | bool open_model(const std::string& path, uint64_t& size) { |
| 196 | std::wstring w; |
no test coverage detected