aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2021-07-11 10:06:30 +0100
committerdiogo464 <[email protected]>2021-07-11 10:06:30 +0100
commitfcc5fbe564ee74e5f8434349424cbc4c646597df (patch)
tree43f73979e5e4c581c02b008a695874944a42ae53
parent54112bd8b0273948cfc4f8f718b2655096321be8 (diff)
Fixed find_archive_path function.
Fixed infinite loop if an archive file didnt exist.
-rw-r--r--dotup_cli/src/utils.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/dotup_cli/src/utils.rs b/dotup_cli/src/utils.rs
index 1ac8c95..fad37ae 100644
--- a/dotup_cli/src/utils.rs
+++ b/dotup_cli/src/utils.rs
@@ -15,15 +15,18 @@ pub fn home_directory() -> anyhow::Result<PathBuf> {
15} 15}
16 16
17pub fn find_archive_path() -> anyhow::Result<PathBuf> { 17pub fn find_archive_path() -> anyhow::Result<PathBuf> {
18 let cwd = std::env::current_dir()?;
19 let compn = cwd.components().count();
18 let mut start = PathBuf::new(); 20 let mut start = PathBuf::new();
19 while { 21 for _ in 0..=compn {
20 start.push(DEFAULT_DEPOT_NAME); 22 start.push(DEFAULT_DEPOT_NAME);
21 !start.is_file() 23 if dotup::archive_exists(&start) {
22 } { 24 return Ok(start);
25 }
23 start.pop(); 26 start.pop();
24 start.push(".."); 27 start.push("..");
25 } 28 }
26 Ok(start.canonicalize()?) 29 Ok(PathBuf::from(DEFAULT_DEPOT_NAME))
27} 30}
28 31
29pub fn write_archive(path: impl AsRef<Path>, archive: &Archive) -> anyhow::Result<()> { 32pub fn write_archive(path: impl AsRef<Path>, archive: &Archive) -> anyhow::Result<()> {