fix #4977: ui: tape: restore: rework snapshot selection logic

previously, the snapshot grid returned one of three possible types of
values:
* a list of snapshots
* a list of datastores (if only whole datastores were selected)
* the string 'all' (when all snapshots were selected)

this led to some confusing and wrong code, especially the part:
```
  if (source === 'all') {
      source = values.store;
  }
```

which basically set the selected *target* store as a source.  (meaning
it tried restoring a datastore with the selected target name,
regardless if it existed or not)

This fell through in testing, since we most often only restored to the
same datastore anyway were the target and source name were the same.

Rework the return value to return the empty array in case all
snapshots are selected, since selecting none is not a valid anyway.

This means we always get an array back, which makes the code a bit
cleaner overall.

At the same time, we now differentiate correctly the 'all selected'
case, by setting the selected target as a default target.

So instead of previously having `target=target` as datastore
parameter, we now have `target` which is the correct behavior when we
want to restore the whole media set anyway.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Mira Limbeck <m.limbeck@proxmox.com>
This commit is contained in:
Dominik Csapak 2023-09-29 15:39:24 +02:00 committed by Thomas Lamprecht
parent 4206d6fadb
commit 3429304733

View File

@ -179,9 +179,6 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
updateDatastores: function(grid, values) { updateDatastores: function(grid, values) {
let me = this; let me = this;
if (values === 'all') {
values = [];
}
let datastores = {}; let datastores = {};
values.forEach((snapshotOrDatastore) => { values.forEach((snapshotOrDatastore) => {
let datastore = snapshotOrDatastore; let datastore = snapshotOrDatastore;
@ -297,14 +294,12 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
onGetValues: function(values) { onGetValues: function(values) {
let me = this; let me = this;
if (values !== "all" && // cannot use the string serialized one from onGetValues, so gather manually
Ext.isString(values.snapshots) && delete values.snapshots;
values.snapshots && let snapshots = me.down('pbsTapeSnapshotGrid').getValue();
values.snapshots.indexOf(':') !== -1
) { if (snapshots.length > 0 && snapshots[0].indexOf(':') !== -1) {
values.snapshots = values.snapshots.split(','); values.snapshots = snapshots;
} else {
delete values.snapshots;
} }
return values; return values;
@ -378,12 +373,14 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
let vm = controller.getViewModel(); let vm = controller.getViewModel();
let datastores = []; let datastores = [];
if (values.store.toString() !== "") { if (values.store.toString() !== "") {
let target = values.store.toString();
delete values.store;
let source = [];
if (vm.get('singleDatastore')) { if (vm.get('singleDatastore')) {
let source = controller.lookup('snapshotGrid').getValue(); // can be '[]' (for all), a list of datastores, or a list of snapshots
if (source === 'all') { source = controller.lookup('snapshotGrid').getValue();
// all values are selected if (source.length > 0) {
source = values.store;
} else if (Ext.isArray(source)) {
if (source[0].indexOf(':') !== -1) { if (source[0].indexOf(':') !== -1) {
// one or multiple snapshots are selected // one or multiple snapshots are selected
// extract datastore from first // extract datastore from first
@ -392,12 +389,19 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
// one whole datstore is selected // one whole datstore is selected
source = source[0]; source = source[0];
} }
} else {
// must be [] (all snapshots) so we use it as a default target
} }
datastores.push(`${source}=${values.store}`);
} else { } else {
datastores.push(values.store); // there is more than one datastore to be restored, so this is just
// the default fallback
}
if (Ext.isString(source)) {
datastores.push(`${source}=${target}`);
} else {
datastores.push(target);
} }
delete values.store;
} }
let defaultNs = values.defaultNs; let defaultNs = values.defaultNs;
@ -743,7 +747,7 @@ Ext.define('PBS.TapeManagement.SnapshotGrid', {
let originalData = me.store.getData().getSource() || me.store.getData(); let originalData = me.store.getData().getSource() || me.store.getData();
if (snapshots.length === originalData.length) { if (snapshots.length === originalData.length) {
return "all"; return [];
} }
let wholeStores = []; let wholeStores = [];