From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 40A1A1FF16B for ; Thu, 29 Aug 2024 13:56:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EDABE1B633; Thu, 29 Aug 2024 13:57:17 +0200 (CEST) Date: Thu, 29 Aug 2024 13:56:44 +0200 From: Wolfgang Bumiller To: Gabriel Goller Message-ID: <6iu2kyyiwkf3fy6vrhiwb6xfnwytua4a5a33k34pkvgs4urgbf@gsmi4u6oyotv> References: <20240829104511.160829-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240829104511.160829-1-g.goller@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.088 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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 - Subject: Re: [pbs-devel] [PATCH proxmox-backup v5 1/2] fix #5439: allow to reuse existing datastore 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: , Reply-To: Proxmox Backup Server development discussion Cc: pbs-devel@lists.proxmox.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Just noticed another thing... On Thu, Aug 29, 2024 at 12:45:10PM GMT, Gabriel Goller wrote: > @@ -70,21 +70,43 @@ pub(crate) fn do_create_datastore( > _lock: BackupLockGuard, > mut config: SectionConfigData, > datastore: DataStoreConfig, > + reuse_datastore: bool, > ) -> Result<(), Error> { > let path: PathBuf = datastore.path.clone().into(); > > + if path.parent().is_none() { > + bail!("cannot create datastore in root path"); > + } > + > let tuning: DatastoreTuning = serde_json::from_value( > DatastoreTuning::API_SCHEMA > .parse_property_string(datastore.tuning.as_deref().unwrap_or(""))?, > )?; > - let backup_user = pbs_config::backup_user()?; > - let _store = ChunkStore::create( > - &datastore.name, > - path, > - backup_user.uid, > - backup_user.gid, > - tuning.sync_level.unwrap_or_default(), > - )?; > + > + if reuse_datastore { > + ChunkStore::verify_chunkstore(&path)?; > + } else { > + let datastore_empty = std::fs::read_dir(path.clone()).map_or(true, |mut d| { No need to clone() path here. > + d.all(|dir| { > + dir.map_or(false, |file| { > + file.file_name() > + .to_str() > + .map_or(false, |name| name.starts_with('.')) IMO if we manage to open the directory, but the iteration fails, we should actually fail here as well. Also we should not just ignore *anything* starting with a `.`, but specifically only exactly `.` and `..`. Something like let datastore_empty = 'empty: { if let Ok(dir) = std::fs::read_dir(&path) { for file in dir { let name = file?.file_name(); let name = name.as_encoded_bytes(); if name != b"." && name != b".." { break 'empty false; } } } true }; > + }) > + }) > + }); > + if !datastore_empty { > + bail!("path not empty!"); > + } > + let backup_user = pbs_config::backup_user()?; > + let _store = ChunkStore::create( > + &datastore.name, > + path, > + backup_user.uid, > + backup_user.gid, > + tuning.sync_level.unwrap_or_default(), > + )?; > + } > > config.set_data(&datastore.name, "datastore", &datastore)?; > _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel