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 64C8368D57 for ; Mon, 3 Aug 2020 09:38:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5C32F2B20D for ; Mon, 3 Aug 2020 09:38:14 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id DF31B2B200 for ; Mon, 3 Aug 2020 09:38:13 +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 A6D66408D8 for ; Mon, 3 Aug 2020 09:38:13 +0200 (CEST) Date: Mon, 3 Aug 2020 09:38:08 +0200 (CEST) From: Dietmar Maurer To: Proxmox Backup Server development discussion , Dominik Csapak Message-ID: <1787681560.48.1596440288596@webmail.proxmox.com> In-Reply-To: <20200731124330.30576-4-d.csapak@proxmox.com> References: <20200731124330.30576-1-d.csapak@proxmox.com> <20200731124330.30576-4-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.3-Rev19 X-Originating-Client: open-xchange-appsuite X-SPAM-LEVEL: Spam detection results: 0 AWL 0.112 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pbs-devel] [PATCH proxmox-backup 3/8] config: add JobState helper 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: Mon, 03 Aug 2020 07:38:14 -0000 suggested cleanups: diff --git a/src/config/jobstate.rs b/src/config/jobstate.rs index fb5a8cb..974b8e9 100644 --- a/src/config/jobstate.rs +++ b/src/config/jobstate.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use std::time::Duration; use serde::{Serialize, Deserialize}; -use anyhow::{bail, Error, format_err}; +use anyhow::{Error, format_err}; use proxmox::tools::fs::{file_read_optional_string, replace_file, create_path, CreateOptions}; use crate::tools::{epoch_now_u64, open_file_locked}; @@ -48,19 +48,15 @@ where { let mut path = path.as_ref().to_path_buf(); path.set_extension("lck"); - let lock = open_file_locked(path, Duration::new(10, 0))?; - Ok(lock) + open_file_locked(path, Duration::new(10, 0)) } pub fn remove_state_file(jobtype: &str, jobname: &str) -> Result<(), Error> { let path = get_path(jobtype, jobname)?; let _lock = get_lock(&path)?; - match std::fs::remove_file(&path) { - Ok(()) => Ok(()), - Err(err) => { - bail!("cannot remove statefile for {} - {}: {}", jobtype, jobname, err); - } - } + std::fs::remove_file(&path).map_err(|err| { + format_err!("cannot remove statefile for {} - {}: {}", jobtype, jobname, err) + }) } impl JobState {