Skip to content

Commit

Permalink
fix: fix availability check + test
Browse files Browse the repository at this point in the history
Signed-off-by: Yato202010 <61349049+Yato202010@users.noreply.github.com>
  • Loading branch information
Yato202010 committed Jan 31, 2025
1 parent 0f28ccd commit 320d452
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/os/linux/fuseoverlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ impl FuseOverlayFs {
impl Filesystem for FuseOverlayFs {
#[inline]
fn mount(&mut self) -> Result<PathBuf> {
#[cfg(not(feature = "fuse-overlayfs-vendored"))]
if !Self::is_available() {
return Err(Error::new(
ErrorKind::NotFound,
"fuse-overlayfs is not available",
));
}
if matches!(self.id,Some(x) if x == PartitionID::try_from(self.target.as_path())?) {
debug!("Damascus: partition already mounted");
return Ok(PathBuf::from(&self.target.as_path()));
Expand Down Expand Up @@ -480,10 +487,10 @@ impl Drop for FuseOverlayFs {

#[cfg(test)]
mod tests {
use super::*;

#[cfg(feature = "fuse-overlayfs-vendored")]
#[test]
fn availability() {
use super::{Filesystem, FuseOverlayFs};
assert!(FuseOverlayFs::is_available())
}
}
16 changes: 6 additions & 10 deletions src/os/linux/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ impl OverlayFs {
impl Filesystem for OverlayFs {
#[inline]
fn mount(&mut self) -> Result<PathBuf> {
if !Self::is_available() {
return Err(Error::new(
ErrorKind::NotFound,
"overlayfs is not available",
));
}
if matches!(self.id,Some(x) if x == PartitionID::try_from(self.target.as_path())?) {
debug!("Damascus: partition already mounted");
return Ok(self.target.as_path().to_path_buf());
Expand Down Expand Up @@ -377,13 +383,3 @@ impl Drop for OverlayFs {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn availability() {
assert!(OverlayFs::is_available())
}
}
11 changes: 9 additions & 2 deletions src/os/linux/unionfs_fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ impl UnionFsFuse {
impl Filesystem for UnionFsFuse {
#[inline]
fn mount(&mut self) -> Result<PathBuf> {
#[cfg(not(feature = "unionfs-fuse-vendored"))]
if !Self::is_available() {
return Err(Error::new(
ErrorKind::NotFound,
"unionfs-fuse is not available",
));
}
if matches!(self.id,Some(x) if x == PartitionID::try_from(self.target.as_path())?) {
debug!("Damascus: partition already mounted");
return Ok(PathBuf::from(&self.target.as_path()));
Expand Down Expand Up @@ -342,10 +349,10 @@ impl Drop for UnionFsFuse {

#[cfg(test)]
mod tests {
use super::*;

#[cfg(feature = "unionfs-fuse-vendored")]
#[test]
fn availability() {
use super::{Filesystem, UnionFsFuse};
assert!(UnionFsFuse::is_available())
}
}
12 changes: 12 additions & 0 deletions tests/linux/unionfs_fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::fs::create_dir_all;
use temp_testdir::TempDir;

pub fn mount_unionfs_fuse_r() {
if !UnionFsFuse::is_available() {
skip!("UnionFsFuse is not available");
return;
}
if geteuid().is_root() {
skip!("fuse mount can't be tested as root");
return;
Expand All @@ -26,6 +30,10 @@ pub fn mount_unionfs_fuse_r() {
}

pub fn mount_unionfs_fuse_rw() {
if !UnionFsFuse::is_available() {
skip!("UnionFsFuse is not available");
return;
}
if geteuid().is_root() {
skip!("fuse mount can't be tested as root");
return;
Expand All @@ -51,6 +59,10 @@ pub fn mount_unionfs_fuse_rw() {
}

pub fn mount_unionfs_fuse_rw_on_lower() {
if !UnionFsFuse::is_available() {
skip!("UnionFsFuse is not available");
return;
}
if geteuid().is_root() {
skip!("fuse mount can't be tested as root");
return;
Expand Down

0 comments on commit 320d452

Please sign in to comment.