From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 47829F7E0 for ; Fri, 29 Sep 2023 15:39:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2F009258B for ; Fri, 29 Sep 2023 15:39:26 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 29 Sep 2023 15:39:25 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E0E95446EC for ; Fri, 29 Sep 2023 15:39:24 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 29 Sep 2023 15:39:24 +0200 Message-Id: <20230929133924.2731714-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230929133924.2731714-1-d.csapak@proxmox.com> References: <20230929133924.2731714-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.011 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 2/2] fix #4977: ui: tape: restore: rework snapshot selection logic X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Sep 2023 13:39:26 -0000 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 --- 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