pub fn canonical_model_path(path: &Path) -> Result<PathBuf>Expand description
Resolve path to the one form the library identifies a model file by.
Three separate places have to agree about what “the same file” means: the
file_path column a model is stored under, the model_key that decides
whether an insert is really an update, and the duplicate lookup an
explicit add performs before inserting. While they disagreed, the failure
was silent and destructive — two different files sharing a relative name
(model.gguf in two directories) hashed to one key, the duplicate check
compared resolved paths and saw no match, and the UPSERT merged them into
a single row carrying the first file’s name and the second file’s path.
Everything that needs that answer resolves it here, so the three cannot drift apart again.
§Errors
Returns the underlying std::io::Error when the path cannot be
resolved — most often because no file exists there.
Fallible on purpose. The infallible “canonicalise, or keep the literal path” shape reads as the convenient one and is precisely the shape of the bug: a caller asking is this file already in the library? gets a literal path back, compares it against a stored canonical one, matches nothing, and reports “no duplicate” for a file that is plainly there. Callers for which this genuinely cannot fail have already established that the file exists; they should say so by propagating rather than by swallowing.