From 3f5c5026909af023c8a3885a4a3d97c669302c1b Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 1 Oct 2021 00:34:16 +0200 Subject: Global repository cursor --- src/files.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 41dbad1..a2b1db4 100644 --- a/src/files.rs +++ b/src/files.rs @@ -15,6 +15,10 @@ pub struct Locations { } impl Locations { + pub fn get_repository_index(&self) -> PathBuf { + return self.ka_path.join("index") + } + pub fn get_repository_files(&self) -> Result, Error> { let working_entries = fs::read_dir(&self.repository_path) .context("Failed reading working file entries.")? @@ -124,10 +128,18 @@ impl FileState { }) }) } + + pub fn get_working_path(&self, locations: &Locations) -> Result { + match self { + FileState::Deleted(deleted) => locations.working_from_history(&deleted.history_path), + FileState::Untracked(untracked) => Ok(untracked.path.clone()), + FileState::Tracked(tracked) => Ok(tracked.working_path.clone()), + } + } } pub struct FileDeleted { - history_path: PathBuf, + pub history_path: PathBuf, } impl FileDeleted { @@ -146,7 +158,7 @@ impl FileDeleted { } pub struct FileUntracked { - path: PathBuf, + pub path: PathBuf, } impl FileUntracked { @@ -168,8 +180,8 @@ impl FileUntracked { } pub struct FileTracked { - history_path: PathBuf, - working_path: PathBuf, + pub history_path: PathBuf, + pub working_path: PathBuf, } impl FileTracked { -- cgit 1.4.1