|
|
@ -42,9 +42,7 @@ impl SiloRepo {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn apply(&self) -> Result<()> {
|
|
|
|
pub fn apply(&self) -> Result<()> {
|
|
|
|
let cwd = env::current_dir()
|
|
|
|
let cwd = dirs::home_dir().unwrap_or(env::current_dir().into_diagnostic()?);
|
|
|
|
.into_diagnostic()
|
|
|
|
|
|
|
|
.context("get current dir")?;
|
|
|
|
|
|
|
|
let ctx = ApplyContext {
|
|
|
|
let ctx = ApplyContext {
|
|
|
|
config: self.config.clone(),
|
|
|
|
config: self.config.clone(),
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -141,16 +139,14 @@ impl DirEntry {
|
|
|
|
|
|
|
|
|
|
|
|
fn apply(&self, ctx: &ApplyContext, cwd: &Path) -> Result<()> {
|
|
|
|
fn apply(&self, ctx: &ApplyContext, cwd: &Path) -> Result<()> {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
DirEntry::File(file) => file.apply(ctx, cwd),
|
|
|
|
DirEntry::File(file) => {
|
|
|
|
|
|
|
|
ensure_cwd(cwd)?;
|
|
|
|
|
|
|
|
file.apply(ctx, cwd)
|
|
|
|
|
|
|
|
}
|
|
|
|
DirEntry::Dir(p, children) => {
|
|
|
|
DirEntry::Dir(p, children) => {
|
|
|
|
let cwd = if p != cwd {
|
|
|
|
let cwd = if p != cwd {
|
|
|
|
let cwd = cwd.join(p.file_name().unwrap());
|
|
|
|
let cwd = cwd.join(p.file_name().unwrap());
|
|
|
|
if !cwd.exists() {
|
|
|
|
ensure_cwd(&cwd)?;
|
|
|
|
log::info!("Creating {cwd:?}");
|
|
|
|
|
|
|
|
fs::create_dir_all(&cwd)
|
|
|
|
|
|
|
|
.into_diagnostic()
|
|
|
|
|
|
|
|
.with_context(|| format!("Creating directory {cwd:?}"))?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cwd
|
|
|
|
cwd
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
p.to_owned()
|
|
|
|
p.to_owned()
|
|
|
@ -162,15 +158,8 @@ impl DirEntry {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DirEntry::Root(_, data, children) => {
|
|
|
|
DirEntry::Root(_, data, children) => {
|
|
|
|
let rendered_path = templating::render(&data.path, &ctx.config.template_context)?;
|
|
|
|
let rendered_path = templating::render(&data.path, &ctx.config.template_context)?;
|
|
|
|
|
|
|
|
|
|
|
|
let cwd = PathBuf::from(rendered_path);
|
|
|
|
let cwd = PathBuf::from(rendered_path);
|
|
|
|
|
|
|
|
|
|
|
|
if !cwd.exists() {
|
|
|
|
|
|
|
|
log::info!("Creating {cwd:?}");
|
|
|
|
|
|
|
|
fs::create_dir_all(&cwd)
|
|
|
|
|
|
|
|
.into_diagnostic()
|
|
|
|
|
|
|
|
.with_context(|| format!("Creating directory {cwd:?}"))?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for child in children {
|
|
|
|
for child in children {
|
|
|
|
child.apply(ctx, &cwd)?;
|
|
|
|
child.apply(ctx, &cwd)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -303,3 +292,13 @@ fn confirm_write(diff_tool: &str, a: &Path, b: &Path) -> Result<bool> {
|
|
|
|
.interact()
|
|
|
|
.interact()
|
|
|
|
.into_diagnostic()
|
|
|
|
.into_diagnostic()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn ensure_cwd(cwd: &Path) -> Result<(), miette::ErrReport> {
|
|
|
|
|
|
|
|
if cwd.exists() {
|
|
|
|
|
|
|
|
return Ok(());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log::info!("Creating {cwd:?}");
|
|
|
|
|
|
|
|
fs::create_dir_all(&cwd)
|
|
|
|
|
|
|
|
.into_diagnostic()
|
|
|
|
|
|
|
|
.with_context(|| format!("Creating directory {cwd:?}"))
|
|
|
|
|
|
|
|
}
|
|
|
|