Skip to content

Commit

Permalink
Revisions to PR - reverse some changes and resolve a code clarity issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Sep 24, 2019
1 parent 58e2bce commit 0795b56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
33 changes: 17 additions & 16 deletions src/dbus_api/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn destroy_filesystems(m: &MethodInfo<MTFn<TData>, TData>) -> MethodResult {
let message: &Message = m.msg;
let mut iter = message.iter_init();

let filesystem_paths: Array<dbus::Path, _> = get_next_arg(&mut iter, 0)?;
let filesystems: Array<dbus::Path<'static>, _> = get_next_arg(&mut iter, 0)?;

let dbus_context = m.tree.get_data();
let object_path = m.path.get_name();
Expand All @@ -127,14 +127,13 @@ fn destroy_filesystems(m: &MethodInfo<MTFn<TData>, TData>) -> MethodResult {
let mut engine = dbus_context.engine.borrow_mut();
let (pool_name, pool) = get_mut_pool!(engine; pool_uuid; default_return; return_message);

let filesystem_map: HashMap<FilesystemUuid, dbus::Path<'static>> = filesystem_paths
.filter_map(|path| m.tree.get(&path))
.filter_map(|op| {
op.get_data()
.as_ref()
.map(|d| (d.uuid, op.get_name().clone()))
})
.collect();
let mut filesystem_map: HashMap<FilesystemUuid, dbus::Path<'static>> = HashMap::new();
for op in filesystems {
if let Some(filesystem_path) = m.tree.get(&op) {
let filesystem_uuid = get_data!(filesystem_path; default_return; return_message).uuid;
filesystem_map.insert(filesystem_uuid, op);
}
}

let result = pool.destroy_filesystems(
&pool_name,
Expand All @@ -144,18 +143,20 @@ fn destroy_filesystems(m: &MethodInfo<MTFn<TData>, TData>) -> MethodResult {
Ok(uuids) => {
// Only get changed values here as non-existant filesystems will have been filtered out
// before calling destroy_filesystems
let changed = uuids.changed();
if let Some(ref uuids) = changed {
for uuid in uuids {
let uuid_vec: Vec<String> = if let Some(ref changed_uuids) = uuids.changed() {
for uuid in changed_uuids {
let op = filesystem_map
.get(uuid)
.expect("'uuids' is a subset of filesystem_map.keys()");
dbus_context.actions.borrow_mut().push_remove(op, m.tree);
}
}

let uuid_vec: Vec<String> =
changed.map_or_else(Vec::new, |v| v.iter().map(|n| uuid_to_string!(n)).collect());
changed_uuids
.iter()
.map(|uuid| uuid_to_string!(uuid))
.collect()
} else {
Vec::new()
};
return_message.append3((true, uuid_vec), msg_code_ok(), msg_string_ok())
}
Err(err) => {
Expand Down
3 changes: 0 additions & 3 deletions src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,10 @@ impl Pool for StratPool {
fs_uuids: &[FilesystemUuid],
) -> StratisResult<SetDeleteAction<FilesystemUuid>> {
let mut removed = Vec::new();
let mut asserted = Vec::new();
for &uuid in fs_uuids {
let changed = self.thin_pool.destroy_filesystem(pool_name, uuid)?;
if changed.is_changed() {
removed.push(uuid);
} else {
asserted.push(uuid);
}
}

Expand Down

0 comments on commit 0795b56

Please sign in to comment.