isDatabaseArtifact static method
Copy asset file to filesystem if it doesn't exist.
Whether candidateName (a file name in the database's directory) is an
on-disk artifact derived from the database file dbFileName: SQLite
sidecars, the mmap vector store, HNSW indexes of every collection
(current and legacy formats) and index dirty markers.
Implementation
@visibleForTesting
static bool isDatabaseArtifact(String dbFileName, String candidateName) {
// Matches Rust's Path::with_extension("vec") in db_pool.rs.
final dot = dbFileName.lastIndexOf('.');
final vectorStoreName =
'${dot > 0 ? dbFileName.substring(0, dot) : dbFileName}.vec';
if ({
dbFileName,
'$dbFileName-wal',
'$dbFileName-shm',
'$dbFileName-journal',
vectorStoreName,
}.contains(candidateName)) {
return true;
}
// Index and marker names use the Dart-side stem (known DB extension
// stripped); collections other than the default add an 8-hex FNV suffix.
final stem = RegExp.escape(_stripDbExtension(dbFileName));
final index = RegExp(
'^$stem(_hnsw(_[0-9a-f]{8})?)?'
r'(\.pbin|\.hnsw|\.hnsw\.tmp|\.hnsw\.data|\.hnsw\.graph)?$',
);
final dirtyMarker = RegExp(
'^$stem'
r'(\.[0-9a-f]{8})?\.dirty$',
);
return index.hasMatch(candidateName) || dirtyMarker.hasMatch(candidateName);
}