public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names
@ 2023-09-29 13:39 Dominik Csapak
  2023-09-29 13:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic Dominik Csapak
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dominik Csapak @ 2023-09-29 13:39 UTC (permalink / raw)
  To: pbs-devel

some of the variable names did not really tell the full story, so extend
them a bit. This makes the intention much clearer.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/tape/window/TapeRestore.js | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/www/tape/window/TapeRestore.js b/www/tape/window/TapeRestore.js
index c1d3493c..3008f359 100644
--- a/www/tape/window/TapeRestore.js
+++ b/www/tape/window/TapeRestore.js
@@ -721,7 +721,7 @@ Ext.define('PBS.TapeManagement.SnapshotGrid', {
 	let me = this;
 	let snapshots = [];
 
-	let storeCounts = {};
+	let selectedStoreCounts = {};
 
 	me.getSelection().forEach((rec) => {
 	    let id = rec.get('id');
@@ -730,10 +730,10 @@ Ext.define('PBS.TapeManagement.SnapshotGrid', {
 	    // only add if not filtered
 	    if (me.store.findExact('id', id) !== -1) {
 		snapshots.push(`${store}:${snap}`);
-		if (storeCounts[store] === undefined) {
-		    storeCounts[store] = 0;
+		if (selectedStoreCounts[store] === undefined) {
+		    selectedStoreCounts[store] = 0;
 		}
-		storeCounts[store]++;
+		selectedStoreCounts[store]++;
 	    }
 	});
 
@@ -745,17 +745,17 @@ Ext.define('PBS.TapeManagement.SnapshotGrid', {
 	}
 
 	let wholeStores = [];
-	let wholeStoresSelected = true;
-	for (const [store, count] of Object.entries(storeCounts)) {
-	    if (me.storeCounts[store] === count) {
+	let onlyWholeStoresSelected = true;
+	for (const [store, selectedCount] of Object.entries(selectedStoreCounts)) {
+	    if (me.storeCounts[store] === selectedCount) {
 		wholeStores.push(store);
 	    } else {
-		wholeStoresSelected = false;
+		onlyWholeStoresSelected = false;
 		break;
 	    }
 	}
 
-	if (wholeStoresSelected) {
+	if (onlyWholeStoresSelected) {
 	    return wholeStores;
 	}
 
-- 
2.30.2





^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic
  2023-09-29 13:39 [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names Dominik Csapak
@ 2023-09-29 13:39 ` Dominik Csapak
  2023-09-29 15:30   ` Mira Limbeck
  2023-11-09  7:43 ` [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names Dominik Csapak
  2023-11-10 12:03 ` [pbs-devel] applied: " Thomas Lamprecht
  2 siblings, 1 reply; 8+ messages in thread
From: Dominik Csapak @ 2023-09-29 13:39 UTC (permalink / raw)
  To: pbs-devel

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>
---
 www/tape/window/TapeRestore.js | 44 ++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/www/tape/window/TapeRestore.js b/www/tape/window/TapeRestore.js
index 3008f359..fbc1858e 100644
--- a/www/tape/window/TapeRestore.js
+++ b/www/tape/window/TapeRestore.js
@@ -179,9 +179,6 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
 
 	updateDatastores: function(grid, values) {
 	    let me = this;
-	    if (values === 'all') {
-		values = [];
-	    }
 	    let datastores = {};
 	    values.forEach((snapshotOrDatastore) => {
 		let datastore = snapshotOrDatastore;
@@ -297,14 +294,12 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
 		    onGetValues: function(values) {
 			let me = this;
 
-			if (values !== "all" &&
-			    Ext.isString(values.snapshots) &&
-			    values.snapshots &&
-			    values.snapshots.indexOf(':') !== -1
-			) {
-			    values.snapshots = values.snapshots.split(',');
-			} else {
-			    delete values.snapshots;
+			// cannot use the string serialized one from onGetValues, so gather manually
+			delete values.snapshots;
+			let snapshots = me.down('pbsTapeSnapshotGrid').getValue();
+
+			if (snapshots.length > 0 && snapshots[0].indexOf(':') !== -1) {
+			    values.snapshots = snapshots;
 			}
 
 			return values;
@@ -378,12 +373,14 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
 			let vm = controller.getViewModel();
 			let datastores = [];
 			if (values.store.toString() !== "") {
+			    let target = values.store.toString();
+			    delete values.store;
+
+			    let source = [];
 			    if (vm.get('singleDatastore')) {
-				let source = controller.lookup('snapshotGrid').getValue();
-				if (source === 'all') {
-				    // all values are selected
-				    source = values.store;
-				} else if (Ext.isArray(source)) {
+				// can be '[]' (for all), a list of datastores, or a list of snapshots
+				source = controller.lookup('snapshotGrid').getValue();
+				if (source.length > 0) {
 				    if (source[0].indexOf(':') !== -1) {
 					// one or multiple snapshots are selected
 					// extract datastore from first
@@ -392,12 +389,19 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', {
 					// one whole datstore is selected
 					source = source[0];
 				    }
+				} else {
+				    // must be [] (all snapshots) so we use it as a default target
 				}
-				datastores.push(`${source}=${values.store}`);
 			    } 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;
@@ -741,7 +745,7 @@ Ext.define('PBS.TapeManagement.SnapshotGrid', {
 	let originalData = me.store.getData().getSource() || me.store.getData();
 
 	if (snapshots.length === originalData.length) {
-	    return "all";
+	    return [];
 	}
 
 	let wholeStores = [];
-- 
2.30.2





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic
  2023-09-29 13:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic Dominik Csapak
@ 2023-09-29 15:30   ` Mira Limbeck
  2023-10-02  6:47     ` Dominik Csapak
  0 siblings, 1 reply; 8+ messages in thread
From: Mira Limbeck @ 2023-09-29 15:30 UTC (permalink / raw)
  To: pbs-devel

I've tested it here and ran into an issue.
When you select a target namespace for one datastore, and none for the
other, the snapshots that are mapped to the root namespace won't be
restored, with the following warning:


2023-09-29T17:25:23+02:00: WARN: could not find target namespace for
test:vm/100/2023-01-24T10:47:49Z




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic
  2023-09-29 15:30   ` Mira Limbeck
@ 2023-10-02  6:47     ` Dominik Csapak
  2023-10-02  9:14       ` Mira Limbeck
  0 siblings, 1 reply; 8+ messages in thread
From: Dominik Csapak @ 2023-10-02  6:47 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Mira Limbeck

On 9/29/23 17:30, Mira Limbeck wrote:
> I've tested it here and ran into an issue.
> When you select a target namespace for one datastore, and none for the
> other, the snapshots that are mapped to the root namespace won't be
> restored, with the following warning:
> 
> 
> 2023-09-29T17:25:23+02:00: WARN: could not find target namespace for
> test:vm/100/2023-01-24T10:47:49Z
> 

thanks for the review!

while that behaviour is unexpected (and i'll see to it that i fix it in the
gui) it's not really related to this fix and it behaved like that before too.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic
  2023-10-02  6:47     ` Dominik Csapak
@ 2023-10-02  9:14       ` Mira Limbeck
  0 siblings, 0 replies; 8+ messages in thread
From: Mira Limbeck @ 2023-10-02  9:14 UTC (permalink / raw)
  To: Dominik Csapak, Proxmox Backup Server development discussion


On 10/2/23 08:47, Dominik Csapak wrote:
> On 9/29/23 17:30, Mira Limbeck wrote:
>> I've tested it here and ran into an issue.
>> When you select a target namespace for one datastore, and none for the
>> other, the snapshots that are mapped to the root namespace won't be
>> restored, with the following warning:
>>
>>
>> 2023-09-29T17:25:23+02:00: WARN: could not find target namespace for
>> test:vm/100/2023-01-24T10:47:49Z
>>
> 
> thanks for the review!
> 
> while that behaviour is unexpected (and i'll see to it that i fix it in the
> gui) it's not really related to this fix and it behaved like that before
> too.
> 

Since the original issue was fixed by the patch and I couldn't find any
issue other than the reported one for which you sent a fix already,
consider this patch:

Tested-by: Mira Limbeck <m.limbeck@proxmox.com>




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names
  2023-09-29 13:39 [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names Dominik Csapak
  2023-09-29 13:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic Dominik Csapak
@ 2023-11-09  7:43 ` Dominik Csapak
  2023-11-10 12:03 ` [pbs-devel] applied: " Thomas Lamprecht
  2 siblings, 0 replies; 8+ messages in thread
From: Dominik Csapak @ 2023-11-09  7:43 UTC (permalink / raw)
  To: pbs-devel

ping for both patches. they still apply and the issue mira found is unrelated
(so these two patches still fixes #4977)




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names
  2023-09-29 13:39 [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names Dominik Csapak
  2023-09-29 13:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic Dominik Csapak
  2023-11-09  7:43 ` [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names Dominik Csapak
@ 2023-11-10 12:03 ` Thomas Lamprecht
  2023-11-10 12:04   ` Dominik Csapak
  2 siblings, 1 reply; 8+ messages in thread
From: Thomas Lamprecht @ 2023-11-10 12:03 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

Am 29/09/2023 um 15:39 schrieb Dominik Csapak:
> some of the variable names did not really tell the full story, so extend
> them a bit. This makes the intention much clearer.
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  www/tape/window/TapeRestore.js | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
>

applied series with Mira's T-b, thanks!

ps. using --- as delimiter for code, as you did in the second patch, breaks
`git am` a bit, as that command then thinks the boundary between commit
message and git diff-stat was already hit and truncates the commit message.
I swapped the triple-minus with triple-backticks.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pbs-devel] applied: [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names
  2023-11-10 12:03 ` [pbs-devel] applied: " Thomas Lamprecht
@ 2023-11-10 12:04   ` Dominik Csapak
  0 siblings, 0 replies; 8+ messages in thread
From: Dominik Csapak @ 2023-11-10 12:04 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox Backup Server development discussion

On 11/10/23 13:03, Thomas Lamprecht wrote:
> Am 29/09/2023 um 15:39 schrieb Dominik Csapak:
>> some of the variable names did not really tell the full story, so extend
>> them a bit. This makes the intention much clearer.
>>
>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>> ---
>>   www/tape/window/TapeRestore.js | 18 +++++++++---------
>>   1 file changed, 9 insertions(+), 9 deletions(-)
>>
>>
> 
> applied series with Mira's T-b, thanks!
> 
> ps. using --- as delimiter for code, as you did in the second patch, breaks
> `git am` a bit, as that command then thinks the boundary between commit
> message and git diff-stat was already hit and truncates the commit message.
> I swapped the triple-minus with triple-backticks.

oops, sorry and good to know. thanks for the fixup!




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-10 12:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-29 13:39 [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names Dominik Csapak
2023-09-29 13:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic Dominik Csapak
2023-09-29 15:30   ` Mira Limbeck
2023-10-02  6:47     ` Dominik Csapak
2023-10-02  9:14       ` Mira Limbeck
2023-11-09  7:43 ` [pbs-devel] [PATCH proxmox-backup 1/2] ui: tape: restore: improve variable names Dominik Csapak
2023-11-10 12:03 ` [pbs-devel] applied: " Thomas Lamprecht
2023-11-10 12:04   ` Dominik Csapak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal