Changeset 5e61643 in gignore


Ignore:
Timestamp:
21 Feb 2026, 19:27:29 (2 months ago)
Author:
Asher Mullaney <asher.mullaney@…>
Branches:
file_locations, help, logging, man, multi_arg, trunk
Children:
e36b2af
Parents:
eb42226
Message:

Completed template file location update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/template.rs

    reb42226 r5e61643  
    3939    }
    4040
    41     fn get_source_file(&self) -> &Path {
     41    fn get_source_file(&self) -> &PathBuf {
    4242        &self.source_file
    4343    }
     
    103103    let mut template_vec: Vec<Template> = lib_read().context("cannot read template library")?;
    104104
    105     match template_vec.extract_if(.., |item| item.get_name() == name).next() {
    106         None => { return Err(Error::msg(format!("No template under the name `{name}`"))) },
    107         _ => {},
     105    template_vec.extract_if(.., |item| item.get_name() == name).for_each(drop);
     106
     107    let template = match find_name(name).context(format!("cannot search for name {name} in /usr/lib/gignore/gignore_templates"))? {
     108        None => {
     109            eprintln!("No template exists in `/usr/lib/gignore/gignore_templates` under the name `{name}`.");
     110            process::exit(0);
     111        },
     112        Some(t) => t,
    108113    };
    109114
     
    111116
    112117    if template_vec.is_empty() {
    113         println!("template lib file is now empty.");
     118        println!("{path} is now empty.");
    114119        fs::write(path, b"").context("cannot write to `/usr/lib/gignore/gignore_templates`")?;
    115120    } else {
     
    118123        }
    119124    }
     125
     126    fs::remove_file(template.get_source_file()).context(format!("cannot remove `{}`", template.get_source_file().display()))?;
    120127    Ok(())
    121128}
     
    126133    }
    127134
    128     if (&*(template.get_source_file().to_string_lossy())).split_terminator('.').nth(2) != Some("ggnr") {
     135    if (*(template.get_source_file())).to_str().expect("FATAL: Could not convert source_file to string!").split_terminator('.').nth(2) != Some("ggnr") {
    129136        eprintln!("WARNING: specified source file, `{}`, does not have the file extension for gignore templates (`.ggnr`). Continue anyway? [y/N]", template.get_source_file().display());
    130137
     
    157164                eprintln!("Continuing...");
    158165
    159                 fs::remove(&new_template_path).
     166                fs::remove_file(&new_template_path).context(format!("cannot remove {new_template_path}"))?
    160167            },
    161168            _ => {
     
    163170                process::exit(0);
    164171            },
    165         }
     172        };
    166173    };
    167174
Note: See TracChangeset for help on using the changeset viewer.