diff options
Diffstat (limited to 'dotup_cli/src/commands/utils.rs')
| -rw-r--r-- | dotup_cli/src/commands/utils.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/dotup_cli/src/commands/utils.rs b/dotup_cli/src/commands/utils.rs index 4160078..706266e 100644 --- a/dotup_cli/src/commands/utils.rs +++ b/dotup_cli/src/commands/utils.rs | |||
| @@ -2,6 +2,8 @@ use std::path::{Path, PathBuf}; | |||
| 2 | 2 | ||
| 3 | use crate::prelude::*; | 3 | use crate::prelude::*; |
| 4 | 4 | ||
| 5 | const DEFAULT_DEPOT_NAME: &str = "depot.toml"; | ||
| 6 | |||
| 5 | pub fn home_directory() -> anyhow::Result<PathBuf> { | 7 | pub fn home_directory() -> anyhow::Result<PathBuf> { |
| 6 | match std::env::var("HOME") { | 8 | match std::env::var("HOME") { |
| 7 | Ok(val) => Ok(PathBuf::from(val)), | 9 | Ok(val) => Ok(PathBuf::from(val)), |
| @@ -12,6 +14,18 @@ pub fn home_directory() -> anyhow::Result<PathBuf> { | |||
| 12 | } | 14 | } |
| 13 | } | 15 | } |
| 14 | 16 | ||
| 17 | pub fn find_archive_path() -> anyhow::Result<PathBuf> { | ||
| 18 | let mut start = PathBuf::new(); | ||
| 19 | while { | ||
| 20 | start.push(DEFAULT_DEPOT_NAME); | ||
| 21 | !start.is_file() | ||
| 22 | } { | ||
| 23 | start.pop(); | ||
| 24 | start.push(".."); | ||
| 25 | } | ||
| 26 | Ok(start.canonicalize()?) | ||
| 27 | } | ||
| 28 | |||
| 15 | pub fn write_archive(path: impl AsRef<Path>, archive: &Archive) -> anyhow::Result<()> { | 29 | pub fn write_archive(path: impl AsRef<Path>, archive: &Archive) -> anyhow::Result<()> { |
| 16 | let path = path.as_ref(); | 30 | let path = path.as_ref(); |
| 17 | log::debug!("Writing archive to {}", path.display()); | 31 | log::debug!("Writing archive to {}", path.display()); |
