Skip to content

Commit

Permalink
Reinstate is_changed
Browse files Browse the repository at this point in the history
This reverts commit 02e513b.
  • Loading branch information
jbaublitz committed Oct 8, 2019
1 parent 155d5a9 commit e25ece6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ mod tests {
.changed()
.unwrap();
let pool = engine.get_mut_pool(uuid).unwrap().1;
assert_eq!(
pool.destroy_filesystems(pool_name, &[]).unwrap().changed(),
None
);
assert!(match pool.destroy_filesystems(pool_name, &[]) {
Ok(uuids) => !uuids.is_changed(),
_ => false,
});
}

#[test]
Expand Down
7 changes: 2 additions & 5 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,8 @@ impl Pool for StratPool {
) -> StratisResult<SetDeleteAction<FilesystemUuid>> {
let mut removed = Vec::new();
for &uuid in fs_uuids {
if let Some(uuid) = self
.thin_pool
.destroy_filesystem(pool_name, uuid)?
.changed()
{
let changed = self.thin_pool.destroy_filesystem(pool_name, uuid)?;
if changed.is_changed() {
removed.push(uuid);
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/engine/types/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
pub trait EngineAction {
type Return;

/// Returns whether or not the action changed state.
fn is_changed(&self) -> bool;

/// Returns the thing or things changed.
fn changed(self) -> Option<Self::Return>;
}
Expand All @@ -29,6 +32,13 @@ pub enum CreateAction<T> {
impl<T> EngineAction for CreateAction<T> {
type Return = T;

fn is_changed(&self) -> bool {
match *self {
CreateAction::Identity => false,
_ => true,
}
}

fn changed(self) -> Option<T> {
match self {
CreateAction::Created(t) => Some(t),
Expand All @@ -52,6 +62,10 @@ impl<T> SetCreateAction<T> {
impl<T> EngineAction for SetCreateAction<T> {
type Return = Vec<T>;

fn is_changed(&self) -> bool {
!self.changed.is_empty()
}

fn changed(self) -> Option<Vec<T>> {
if self.changed.is_empty() {
None
Expand All @@ -75,6 +89,13 @@ pub enum RenameAction<T> {
impl<T> EngineAction for RenameAction<T> {
type Return = T;

fn is_changed(&self) -> bool {
match *self {
RenameAction::Renamed(_) => true,
_ => false,
}
}

fn changed(self) -> Option<T> {
match self {
RenameAction::Renamed(t) => Some(t),
Expand All @@ -95,6 +116,13 @@ pub enum DeleteAction<T> {
impl<T> EngineAction for DeleteAction<T> {
type Return = T;

fn is_changed(&self) -> bool {
match *self {
DeleteAction::Deleted(_) => true,
_ => false,
}
}

fn changed(self) -> Option<T> {
match self {
DeleteAction::Deleted(t) => Some(t),
Expand Down

0 comments on commit e25ece6

Please sign in to comment.