From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 0A3B41FF164
	for <inbox@lore.proxmox.com>; Fri, 22 Nov 2024 17:57:35 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id AD34D180E5;
	Fri, 22 Nov 2024 17:57:42 +0100 (CET)
From: Daniel Herzig <d.herzig@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 22 Nov 2024 17:57:25 +0100
Message-Id: <20241122165725.10378-1-d.herzig@proxmox.com>
X-Mailer: git-send-email 2.39.5
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.054 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: [pve-devel] [PATCH storage v3] dirplugin: fix #3986: check for
 trailing slashes
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Currently, setting up a directory storage with trailing slashes in
the path results in log messages with double slashes, if this path
gets expanded by an action like vzdump.

This patch removes those trailing slashes once the directory storage
class config gets updated.

Signed-off-by: Daniel Herzig <d.herzig@proxmox.com>
---
changes since v2:
* make use of File::Spec->canonpath() for better readability

v2: https://lore.proxmox.com/pve-devel/20241122131305.59062-1-d.herzig@proxmox.com/

Thanks for the hint, Thomas!

Notes:

Functionality can be tested by adding new directory storage with trailing
slashes either via the GUI or `pvesm add dir $STORAGENAME --path /some/path/`.

`/new/path/` will show up as `/new/path` in `/etc/pve/storage.cfg`, and trailing
slashes from earlier defined directory storage paths will be removed.

 src/PVE/Storage/DirPlugin.pm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/PVE/Storage/DirPlugin.pm b/src/PVE/Storage/DirPlugin.pm
index fb23e0a..15b67ee 100644
--- a/src/PVE/Storage/DirPlugin.pm
+++ b/src/PVE/Storage/DirPlugin.pm
@@ -6,6 +6,7 @@ use warnings;
 use Cwd;
 use Encode qw(decode encode);
 use File::Path;
+use File::Spec;
 use IO::File;
 use POSIX;
 
@@ -245,6 +246,8 @@ sub check_config {
     if ($opts->{path} !~ m|^/[-/a-zA-Z0-9_.@]+$|) {
 	die "illegal path for directory storage: $opts->{path}\n";
     }
+    # remove trailing slashes from path
+    $opts->{path} = File::Spec->canonpath($opts->{path});
     return $opts;
 }
 
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel