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 531631FF163 for ; Thu, 29 Aug 2024 14:58:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 371571C345; Thu, 29 Aug 2024 14:58:59 +0200 (CEST) Date: Thu, 29 Aug 2024 14:58:25 +0200 From: Gabriel Goller To: Wolfgang Bumiller Message-ID: <20240829125825.lmouyfxmaha3ffvr@luna.proxmox.com> References: <20240829104511.160829-1-g.goller@proxmox.com> <6iu2kyyiwkf3fy6vrhiwb6xfnwytua4a5a33k34pkvgs4urgbf@gsmi4u6oyotv> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20220429 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.042 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" On 29.08.2024 13:58, Wolfgang Bumiller wrote: >On Thu, Aug 29, 2024 at 01:56:46PM GMT, Wolfgang Bumiller wrote: >> 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; > >Ummm >Actually the `bail!()` could just be moved up here and the labeled block >skipped, duh ;-) Done! Also reverted to `starts_with('.')` as discussed offlist to accomodate for files such as '.zfs'. Thanks for reviewing! Posted a v6! _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel