Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Dec 1, 2022
1 parent 6570168 commit 82dc1b5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
website/** linguist-documentation
docs/** linguist-documentation
bats-tests/** linguist-documentation
ci/**linguist-documentation
config_examplesi/** linguist-documentation
Expand Down
3 changes: 2 additions & 1 deletion config_examples/vars.example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# - A var file MUST contains valid toml with only string key/value pair.
# - A var file MUST contains valid toml.
# - The name of the file can be anything (ex: color-scheme.toml).
# - A bombadil config can have many var files.
[theme]
terminal = "alacritty"
background = "#292C3E"
foreground = "#EBEBEB"
Expand Down
21 changes: 14 additions & 7 deletions src/dots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Dot {
profiles: &[String],
) -> Result<LinkResult> {
let source = &self.source()?;
let target = &self.build_copy_path();
let target = &self.copy_path_unchecked();
let source_str = source.to_str().unwrap_or_default();

let ignored_paths = if self.ignore.is_empty() {
Expand Down Expand Up @@ -87,12 +87,19 @@ impl Dot {
fs::create_dir_all(target.parent().unwrap())?;

match vars.to_dot(source, profiles) {
Ok(content) if target.exists() => self.update(source, target, content),
Ok(content) => self.create(source, target, content),
Ok(content) if target.exists() => {
self.update(source, target, content)
},
Ok(content) => {
self.create(source, target, content)
},
Err(e) if target.exists() => {
match e.kind {
ErrorKind::Utf8Conversion { .. } => {}
ErrorKind::Io(_) => {}
ErrorKind::Utf8Conversion { .. } | ErrorKind::Io(..) => {
// Skip non utf8 files like binaries, images etc.
// Those should be symlinked directly once this is implemented
// https://github.com/oknozor/toml-bombadil/issues/138
}
ErrorKind::Msg(message) => println!("\t{}", message.to_string().red()),
_ => {
if let Some(source) = e.source() {
Expand All @@ -103,7 +110,7 @@ impl Dot {
self.update_raw(source, target)
}
Err(_) => {
fs::copy(&source, &target)?;
fs::copy(&source, target)?;
Ok(LinkResult::Created {
target: target.clone(),
copy: self.copy_path()?,
Expand Down Expand Up @@ -312,7 +319,7 @@ mod tests {
mkdir .config;
tree -a;
)
.unwrap();
.unwrap();

Bombadil::link_self_config(Some(PathBuf::from(dotfiles))).unwrap();
}
Expand Down
7 changes: 3 additions & 4 deletions src/paths/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait DotPaths {
fn copy_path(&self) -> Result<PathBuf>;

/// Build the rendered template path, use this to create the rendered file
fn build_copy_path(&self) -> PathBuf;
fn copy_path_unchecked(&self) -> PathBuf;

/// Remove the dotfile target symlink
fn unlink(&self) -> Result<()>;
Expand Down Expand Up @@ -52,13 +52,12 @@ impl DotPaths for Dot {
}

fn copy_path(&self) -> Result<PathBuf> {
let path = self.build_copy_path();

let path = self.copy_path_unchecked();
path.canonicalize()
.map_err(|error| TemplateNotFound { path, error })
}

fn build_copy_path(&self) -> PathBuf {
fn copy_path_unchecked(&self) -> PathBuf {
dotfile_dir().join(".dots").join(&self.source)
}

Expand Down

0 comments on commit 82dc1b5

Please sign in to comment.