MCPcopy Create free account
hub / github.com/Niko1221/Strata / open_session

Method open_session

engine/src/core/conversation_file.cpp:176–193  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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;

Callers 1

read_implFunction · 0.80

Calls 6

wideFunction · 0.85
win_kindFunction · 0.85
last_errorFunction · 0.85
errno_kindFunction · 0.85
openFunction · 0.50
stringFunction · 0.50

Tested by

no test coverage detected