Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ impl Cache {
let directory = directory.as_ref();
if let Ok(mut transaction) = self.connection.borrow_mut().transaction() {
transaction.execute(
"DELETE FROM paths WHERE path LIKE ? || '%'",
params![path_to_bytes(directory)],
"DELETE FROM paths WHERE path = ? OR path LIKE ? || '/%'",
params![path_to_bytes(directory), path_to_bytes(directory)],
)?;
Self::set_last_update_transaction(&mut transaction)?;
transaction.commit()?;
Expand Down Expand Up @@ -241,8 +241,8 @@ impl Cache {
{
let connection = self.connection.borrow();
let mut select_stmt =
connection.prepare("SELECT path FROM paths WHERE path LIKE ? || '%'")?;
let paths = select_stmt.query_map(params![path_to_bytes(directory)], |row| {
connection.prepare("SELECT path FROM paths WHERE path = ? OR path LIKE ? || '/%'")?;
let paths = select_stmt.query_map(params![path_to_bytes(directory), path_to_bytes(directory)], |row| {
let bytes: Vec<u8> = row.get(0)?;

Ok(PathBuf::from(OsStr::from_bytes(&bytes)))
Expand Down Expand Up @@ -390,6 +390,27 @@ mod tests {
assert!(diff.removed.contains(&PathBuf::from("1").join("c")));
}

#[test]
fn test_find_diff_in_directory_does_not_affect_sibling_directory() {
let mut cache = Cache::open_in_memory().unwrap();
cache
.reset([
PathBuf::from("/repo/file"),
PathBuf::from("/repo-sibling/file"),
])
.unwrap();
let exclusions = BTreeSet::from([PathBuf::from("/repo/file")]);
let diff = cache
.find_diff_in_directory(&exclusions, PathBuf::from("/repo"))
.unwrap();

assert!(
diff.removed.is_empty(),
"/repo-sibling/file was incorrectly included in the diff for /repo"
);
assert!(diff.added.is_empty());
}

#[test]
fn test_remove_paths_in_directory() {
let mut cache = Cache::open_in_memory().unwrap();
Expand All @@ -409,6 +430,26 @@ mod tests {
);
}

#[test]
fn test_remove_paths_in_directory_does_not_affect_sibling_directory() {
let mut cache = Cache::open_in_memory().unwrap();

cache
.reset([
PathBuf::from("/repo/file"),
PathBuf::from("/repo-sibling/file"),
])
.unwrap();
cache.remove_paths_in_directory("/repo").unwrap();

let paths = cache.paths().unwrap();
assert_eq!(1, paths.len());
assert!(
paths.contains(&PathBuf::from("/repo-sibling/file")),
"/repo-sibling/file was incorrectly deleted when removing /repo"
);
}

#[test]
fn test_open_cache_no_parent_dir() {
let result = Cache::open_or_create("/");
Expand Down