fix(group): symlink warning for package operation
Until now, when symlink warnings were enabled, these were printed independent from the operation that was to be executed. This was annoying especially when 'pacdef group export' was used to fix exactly that. Now this warning is only printed when subcommands from 'pacdef package' are used.
This commit is contained in:
@@ -87,7 +87,10 @@ impl Pacdef {
|
|||||||
match args {
|
match args {
|
||||||
Clean(args::Noconfirm(noconfirm)) => self.clean_packages(*noconfirm),
|
Clean(args::Noconfirm(noconfirm)) => self.clean_packages(*noconfirm),
|
||||||
Review => review::review(self.get_unmanaged_packages()?, self.groups),
|
Review => review::review(self.get_unmanaged_packages()?, self.groups),
|
||||||
Search(args::Regex(regex)) => search::search_packages(regex, &self.groups),
|
Search(args::Regex(regex)) => {
|
||||||
|
self.warn_about_groups_that_arent_symlinks();
|
||||||
|
search::search_packages(regex, &self.groups)
|
||||||
|
}
|
||||||
Sync(args::Noconfirm(noconfirm)) => self.install_packages(*noconfirm),
|
Sync(args::Noconfirm(noconfirm)) => self.install_packages(*noconfirm),
|
||||||
Unmanaged => self.show_unmanaged_packages(),
|
Unmanaged => self.show_unmanaged_packages(),
|
||||||
}
|
}
|
||||||
@@ -150,6 +153,8 @@ impl Pacdef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn install_packages(&mut self, noconfirm: bool) -> Result<()> {
|
fn install_packages(&mut self, noconfirm: bool) -> Result<()> {
|
||||||
|
self.warn_about_groups_that_arent_symlinks();
|
||||||
|
|
||||||
let to_install = self.get_missing_packages()?;
|
let to_install = self.get_missing_packages()?;
|
||||||
|
|
||||||
if to_install.nothing_to_do_for_all_backends() {
|
if to_install.nothing_to_do_for_all_backends() {
|
||||||
@@ -170,7 +175,20 @@ impl Pacdef {
|
|||||||
to_install.install_missing_packages(noconfirm)
|
to_install.install_missing_packages(noconfirm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn warn_about_groups_that_arent_symlinks(&self) {
|
||||||
|
for group in &self.groups {
|
||||||
|
if group.warn_symlink {
|
||||||
|
eprintln!(
|
||||||
|
"WARNING: group file {} is not a symlink",
|
||||||
|
group.path.to_string_lossy()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn edit_groups(&self, groups: &[String]) -> Result<()> {
|
fn edit_groups(&self, groups: &[String]) -> Result<()> {
|
||||||
|
self.warn_about_groups_that_arent_symlinks();
|
||||||
|
|
||||||
if self.groups.is_empty() {
|
if self.groups.is_empty() {
|
||||||
eprintln!("WARNING: no group files found");
|
eprintln!("WARNING: no group files found");
|
||||||
}
|
}
|
||||||
@@ -211,6 +229,8 @@ impl Pacdef {
|
|||||||
///
|
///
|
||||||
/// This function will propagate errors from the individual backends.
|
/// This function will propagate errors from the individual backends.
|
||||||
fn get_unmanaged_packages(&mut self) -> Result<ToDoPerBackend> {
|
fn get_unmanaged_packages(&mut self) -> Result<ToDoPerBackend> {
|
||||||
|
self.warn_about_groups_that_arent_symlinks();
|
||||||
|
|
||||||
if self.groups.is_empty() {
|
if self.groups.is_empty() {
|
||||||
eprintln!("WARNING: no group files found");
|
eprintln!("WARNING: no group files found");
|
||||||
}
|
}
|
||||||
@@ -247,6 +267,8 @@ impl Pacdef {
|
|||||||
/// with other methods.
|
/// with other methods.
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn show_groups(self) -> Result<()> {
|
fn show_groups(self) -> Result<()> {
|
||||||
|
self.warn_about_groups_that_arent_symlinks();
|
||||||
|
|
||||||
if self.groups.is_empty() {
|
if self.groups.is_empty() {
|
||||||
eprintln!("WARNING: no group files found");
|
eprintln!("WARNING: no group files found");
|
||||||
}
|
}
|
||||||
@@ -282,6 +304,8 @@ impl Pacdef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_group_content(&self, args: &[String]) -> Result<()> {
|
fn show_group_content(&self, args: &[String]) -> Result<()> {
|
||||||
|
self.warn_about_groups_that_arent_symlinks();
|
||||||
|
|
||||||
if self.groups.is_empty() {
|
if self.groups.is_empty() {
|
||||||
eprintln!("WARNING: no group files found");
|
eprintln!("WARNING: no group files found");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ pub struct Group {
|
|||||||
pub(crate) sections: HashSet<Section>,
|
pub(crate) sections: HashSet<Section>,
|
||||||
/// The absolute path of the original file.
|
/// The absolute path of the original file.
|
||||||
pub(crate) path: PathBuf,
|
pub(crate) path: PathBuf,
|
||||||
|
/// Whether the main program should warn this group being loaded from a symlink.
|
||||||
|
pub(crate) warn_symlink: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Group {
|
impl Group {
|
||||||
@@ -57,15 +59,11 @@ impl Group {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if warn_not_symlinks && !path.is_symlink() && !is_child_of_any_dir(&path, &symlink_dirs)
|
let should_warn_about_symlinks = warn_not_symlinks
|
||||||
{
|
&& !path.is_symlink()
|
||||||
eprintln!(
|
&& !is_child_of_any_dir(&path, &symlink_dirs);
|
||||||
"WARNING: group file {} is not a symlink",
|
|
||||||
path.to_string_lossy()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let group = Self::try_from(path.as_path(), group_dir)
|
let group = Self::try_from(path.as_path(), group_dir, should_warn_about_symlinks)
|
||||||
.with_context(|| format!("reading group file {path:?}"))?;
|
.with_context(|| format!("reading group file {path:?}"))?;
|
||||||
|
|
||||||
result.insert(group);
|
result.insert(group);
|
||||||
@@ -132,7 +130,7 @@ impl Group {
|
|||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// This function will return an error if the group file cannot be read.
|
/// This function will return an error if the group file cannot be read.
|
||||||
fn try_from<P>(path: P, group_dir: P) -> Result<Self>
|
fn try_from<P>(path: P, group_dir: P, warn_symlink: bool) -> Result<Self>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
@@ -167,6 +165,7 @@ impl Group {
|
|||||||
name,
|
name,
|
||||||
sections,
|
sections,
|
||||||
path,
|
path,
|
||||||
|
warn_symlink,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user