From 489cbcc824b25486fa13dc5c1b9fcdf3bd1e2c06 Mon Sep 17 00:00:00 2001 From: rowan Date: Wed, 5 Mar 2025 19:05:36 -0600 Subject: [PATCH] feat: fixed delimiter differences between overlay and fuse-overlay --- src/fs/mount.rs | 147 +++++-------------------------- src/fs/stackable/fuse_overlay.rs | 6 +- src/fs/stackable/mod.rs | 10 +-- src/fs/stackable/overlay.rs | 6 +- 4 files changed, 33 insertions(+), 136 deletions(-) diff --git a/src/fs/mount.rs b/src/fs/mount.rs index 7644f4e..875ada1 100644 --- a/src/fs/mount.rs +++ b/src/fs/mount.rs @@ -379,6 +379,26 @@ impl From for GidRange { #[derive(Clone, Debug, PartialEq, Eq)] pub struct DelimitedList(Vec); +impl Deref for DelimitedList { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl Default for DelimitedList { + fn default() -> Self { + Self(Default::default()) + } +} + +impl DerefMut for DelimitedList { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + impl FromStr for DelimitedList { type Err = T::Err; @@ -431,129 +451,6 @@ impl Display for DelimitedList { } } -#[derive(Debug)] -pub struct Options { - options: Vec, - delimiter: char, -} - -impl Options { - pub fn new(options: Vec, delimiter: char) -> Self { - Self { options, delimiter } - } -} - -impl Deref for Options { - type Target = Vec; - - fn deref(&self) -> &Self::Target { - &self.options - } -} - -impl DerefMut for Options { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.options - } -} - -impl Default for Options { - fn default() -> Self { - Self { - options: Default::default(), - delimiter: ' ', - } - } -} - -impl AsRef> for Options { - fn as_ref(&self) -> &Vec { - &self.options - } -} - -impl Clone for Options { - fn clone(&self) -> Self { - Self { - options: self.options.clone(), - delimiter: self.delimiter, - } - } -} - -impl PartialEq for Options { - fn eq(&self, other: &Self) -> bool { - self.options.eq(&other.options) && self.delimiter.eq(&other.delimiter) - } -} - -impl Eq for Options {} - -impl FromStr for Options { - type Err = T::Err; - - fn from_str(s: &str) -> Result { - s.split(',') - .map(T::from_str) - .process_results(|iter| Options::from(iter.collect::>())) - } -} - -impl Display for Options { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut iter = self.options.iter(); - if let Some(head) = iter.next() { - write!(f, "{head}")?; - - for item in iter { - write!(f, "{}{item}", self.delimiter)?; - } - } - - Ok(()) - } -} - -impl FromIterator for Options { - fn from_iter>(iter: I) -> Self { - Self { - options: iter.into_iter().collect(), - ..Default::default() - } - } -} - -impl IntoIterator for Options { - type Item = T; - - type IntoIter = IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.options.into_iter() - } -} -impl<'a, T> IntoIterator for &'a Options { - type Item = &'a T; - - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Self::IntoIter { - self.options.as_slice().iter() - } -} - -impl From> for Options { - fn from(value: Vec) -> Self { - Self::from_iter(value) - } -} - -impl From for Options { - fn from(value: T) -> Self { - Self::from_iter([value]) - } -} - #[derive(Clone, Debug, PartialEq, Eq)] pub struct Sources(DelimitedList<',', OptionsSource>); @@ -1015,8 +912,8 @@ mod tests { }; use super::{ - Access, DeviceId, KeyValuePair, MapUsers, MountOperation, MountOption, Options, - OptionsMode, OptionsSource, ParseMountOptionError, Subtree, UncheckedOptions, + Access, DeviceId, KeyValuePair, MapUsers, MountOperation, MountOption, OptionsMode, + OptionsSource, ParseMountOptionError, Subtree, UncheckedOptions, }; #[test] diff --git a/src/fs/stackable/fuse_overlay.rs b/src/fs/stackable/fuse_overlay.rs index d2bce01..aa4572e 100644 --- a/src/fs/stackable/fuse_overlay.rs +++ b/src/fs/stackable/fuse_overlay.rs @@ -272,10 +272,10 @@ impl Display for FuseOverlayOption { } #[derive(Debug)] -pub struct FuseOverlay(StackFs); +pub struct FuseOverlay(StackFs<' ', FuseOverlayOption>); -impl_deref!(FuseOverlay(StackFs)); -impl_deref_mut!(FuseOverlay(StackFs)); +impl_deref!(FuseOverlay(StackFs<' ', FuseOverlayOption>)); +impl_deref_mut!(FuseOverlay(StackFs<' ', FuseOverlayOption>)); impl FuseOverlay { pub fn new(target: impl Into) -> Self { diff --git a/src/fs/stackable/mod.rs b/src/fs/stackable/mod.rs index 345bd70..914c704 100644 --- a/src/fs/stackable/mod.rs +++ b/src/fs/stackable/mod.rs @@ -9,7 +9,7 @@ use std::str::FromStr; use crate::macros::impl_deref; -use super::mount::Options; +use super::mount::DelimitedList; use super::Mountpoint; #[derive(Clone, Debug, Default)] @@ -76,12 +76,12 @@ impl FromStr for LowerDirs { } #[derive(Debug)] -pub struct StackFs { +pub struct StackFs { mountpoint: PathBuf, - options: Options, + options: DelimitedList, } -impl StackFs { +impl StackFs { pub fn new(target: impl Into) -> Self { Self { mountpoint: target.into(), @@ -105,7 +105,7 @@ impl StackFs { } } -impl Mountpoint for StackFs { +impl Mountpoint for StackFs { fn options(&self) -> impl Iterator { self.options.iter() } diff --git a/src/fs/stackable/overlay.rs b/src/fs/stackable/overlay.rs index 9527b57..4562272 100644 --- a/src/fs/stackable/overlay.rs +++ b/src/fs/stackable/overlay.rs @@ -247,10 +247,10 @@ impl Display for OverlayOption { } #[derive(Debug)] -pub struct Overlay(StackFs); +pub struct Overlay(StackFs<',', OverlayOption>); -impl_deref!(Overlay(StackFs)); -impl_deref_mut!(Overlay(StackFs)); +impl_deref!(Overlay(StackFs<',', OverlayOption>)); +impl_deref_mut!(Overlay(StackFs<',', OverlayOption>)); impl Stack for Overlay { fn lower_dirs(&self) -> impl Iterator {