Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions engine/src/handlers/restore/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::index::{FileMode, index_entry::IndexEntry, stage::Stage};
use crate::objects::{MevaBlob, MevaObject, ObjectEntry};
use crate::{CommitTreeWalker, Index, ObjectStorage, RevisionResolver, WorkingDir};
use chrono::Utc;
use path_absolutize::Absolutize;
use shared::{PathToString, StripBase};
use std::collections::{HashMap, HashSet};
use std::fs;
Expand Down Expand Up @@ -135,6 +136,8 @@ impl RestoreHandler {
let index_entries_to_remove =
Self::build_index_entries_to_remove(&index_entries_map, &source_files_map);

drop(index_read_guard);

let mut index_write_guard = self.index.write().unwrap();
index_write_guard.insert_entries(index_entries_to_add);
index_write_guard.remove_entries(index_entries_to_remove);
Expand All @@ -152,10 +155,14 @@ impl RestoreHandler {
.working_dir
.collect_files(path, false)
.into_iter()
.map(|(entry_path, _)| {
.filter_map(|(entry_path, _)| {
entry_path
.strip_base(&self.working_dir.layout().working_dir())
.to_path_buf()
.absolutize()
.map(|path| {
path.strip_base(&self.working_dir.layout().working_dir())
.to_path_buf()
})
.ok()
})
.collect();
workdir_files.extend(collected_files);
Expand Down
2 changes: 1 addition & 1 deletion engine/src/index/working_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub trait WorkingDir: Send + Sync {
/// # Returns
///
/// A vector of tuples of type `(PathBuf, bool)`:
/// - `PathBuf`: the absolute file path.
/// - `PathBuf`: file path.
/// - `bool`: whether the file is ignored (`true` if ignored).
fn collect_files(&self, path: &Path, include_ignored: bool) -> Vec<(PathBuf, bool)>;

Expand Down
17 changes: 11 additions & 6 deletions engine/src/traversal/meva_commit_tree_walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use super::CommitTreeWalker;
use crate::errors::EngineResult;
use crate::object_storage::ObjectStorage;
use crate::objects::{MevaBlob, MevaCommit, MevaTree, ObjectEntry, TreeEntry, TreeEntryType};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use shared::IsWithin;
use std::{
path::{Path, PathBuf},
sync::Arc,
};

/// A concrete implementation of [`CommitTreeWalker`] for traversing commits
/// stored in a local Meva object database.
Expand Down Expand Up @@ -36,9 +39,9 @@ impl MevaCommitTreeWalker {
/// - The current entry path **starts with** or **is a prefix of** any of the filters.
fn should_traverse(&self, entry_path: &Path, path_filter: Option<&[PathBuf]>) -> bool {
match path_filter {
Some(filters) => filters
.iter()
.any(|f| f.starts_with(entry_path) || entry_path.starts_with(f)),
Some(filters) => filters.iter().any(|f| {
f.is_within(entry_path).unwrap_or(false) || entry_path.is_within(f).unwrap_or(false)
}),
None => true,
}
}
Expand All @@ -49,7 +52,9 @@ impl MevaCommitTreeWalker {
/// should be **included** in the traversal result.
fn matches_entry(&self, entry_path: &Path, path_filter: Option<&[PathBuf]>) -> bool {
match path_filter {
Some(filters) => filters.iter().any(|f| entry_path.starts_with(f)),
Some(filters) => filters
.iter()
.any(|f| entry_path.is_within(f).unwrap_or(false)),
None => true,
}
}
Expand Down