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 CC312BFB6E for ; Tue, 9 Jan 2024 09:29:28 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A5AF2144FA for ; Tue, 9 Jan 2024 09:28:58 +0100 (CET) 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 ; Tue, 9 Jan 2024 09:28:57 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 70C2B4902D for ; Tue, 9 Jan 2024 09:28:57 +0100 (CET) Date: Tue, 09 Jan 2024 09:28:49 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20231121135031.171323-1-m.sandoval@proxmox.com> In-Reply-To: <20231121135031.171323-1-m.sandoval@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1704788893.cvpe77hu0b.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.064 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 T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mirror.rs, proxmox.com] Subject: [pbs-devel] applied: [PATCH offline-mirror] mirror: Use PathBuf instead of strings for paths 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: Tue, 09 Jan 2024 08:29:28 -0000 with a small follow-up to replace another instance of `mirror_dir`'s code with a call to it ;)=20 On November 21, 2023 2:50 pm, Maximiliano Sandoval R wrote: > Joining the strings might results in a double `//` in a path. This was > experienced in a ticket at our customer support in the following error: >=20 > Error: unable to read > "/var/lib/proxmox-offline-mirror/mirrors//.pool/sha256/" > - Input/output error (os error 5) after downloading =C2=B160GB of dat= a. >=20 > Suggested-by: Stefan Sterz > Signed-off-by: Maximiliano Sandoval R > --- >=20 > One could also store .base_dir and .id as PathBuf instead of Strings in > MirrorConfig but that would constitute an API break. >=20 > src/mirror.rs | 20 +++++++++----------- > 1 file changed, 9 insertions(+), 11 deletions(-) >=20 > diff --git a/src/mirror.rs b/src/mirror.rs > index 3766f23..e26457b 100644 > --- a/src/mirror.rs > +++ b/src/mirror.rs > @@ -30,13 +30,13 @@ use proxmox_apt::{ > =20 > use crate::helpers; > =20 > -fn mirror_dir(config: &MirrorConfig) -> String { > - format!("{}/{}", config.base_dir, config.id) > +fn mirror_dir(config: &MirrorConfig) -> PathBuf { > + PathBuf::from(&config.base_dir).join(&config.id) > } > =20 > pub(crate) fn pool(config: &MirrorConfig) -> Result { > - let pool_dir =3D format!("{}/.pool", config.base_dir); > - Pool::open(Path::new(&mirror_dir(config)), Path::new(&pool_dir)) > + let pool_dir =3D PathBuf::from(&config.base_dir).join(".pool"); > + Pool::open(&mirror_dir(config), &pool_dir) > } > =20 > /// `MirrorConfig`, but some fields converted/parsed into usable types. > @@ -450,11 +450,11 @@ fn fetch_plain_file( > =20 > /// Initialize a new mirror (by creating the corresponding pool). > pub fn init(config: &MirrorConfig) -> Result<(), Error> { > - let pool_dir =3D format!("{}/.pool", config.base_dir); > + let pool_dir =3D PathBuf::from(&config.base_dir).join(".pool"); > =20 > - let dir =3D format!("{}/{}", config.base_dir, config.id); > + let dir =3D PathBuf::from(&config.base_dir).join(&config.id); > =20 > - Pool::create(Path::new(&dir), Path::new(&pool_dir))?; > + Pool::create(&dir, &pool_dir)?; > Ok(()) > } > =20 > @@ -472,13 +472,11 @@ pub fn list_snapshots(config: &MirrorConfig) -> Res= ult, Error> { > =20 > let mut list: Vec =3D vec![]; > =20 > - let dir =3D mirror_dir(config); > - > - let path =3D Path::new(&dir); > + let path =3D mirror_dir(config); > =20 > proxmox_sys::fs::scandir( > libc::AT_FDCWD, > - path, > + &path, > &SNAPSHOT_REGEX, > |_l2_fd, snapshot, file_type| { > if file_type !=3D nix::dir::Type::Directory { > --=20 > 2.39.2 >=20 >=20 >=20 > _______________________________________________ > pbs-devel mailing list > pbs-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel >=20