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 203156193F for ; Thu, 9 Jul 2020 18:15:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 120FD13F8E for ; Thu, 9 Jul 2020 18:15:36 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id D9D2813F83 for ; Thu, 9 Jul 2020 18:15:34 +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 A4313444AA for ; Thu, 9 Jul 2020 18:15:34 +0200 (CEST) From: Stoiko Ivanov To: pbs-devel@lists.proxmox.com Date: Thu, 9 Jul 2020 16:15:28 +0000 Message-Id: <20200709161528.22249-1-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 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: [pbs-devel] [PATCH proxmox-backup] datastore: chown base dir on creation 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: Thu, 09 Jul 2020 16:15:36 -0000 When creating a new datastore the basedir is only owned by the backup user if it did not exist beforehand (create_path chowns only if it creates the directory), and returns false if it did not create the directory). This improves the experience when adding a new datastore on a fresh disk or existing directory (not owned by backup) - backups/pulls can be run instead of terminating with EPERM. Tested on my local testinstall with a new disk, and a existing directory: Signed-off-by: Stoiko Ivanov --- src/backup/chunk_store.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index d21c232d..87000630 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -80,8 +80,9 @@ impl ChunkStore { let default_options = CreateOptions::new(); - if let Err(err) = create_path(&base, Some(default_options.clone()), Some(options.clone())) { - bail!("unable to create chunk store '{}' at {:?} - {}", name, base, err); + match create_path(&base, Some(default_options.clone()), Some(options.clone())) { + Err(err) => bail!("unable to create chunk store '{}' at {:?} - {}", name, base, err), + Ok(res) => if ! res { nix::unistd::chown(&base, Some(uid), Some(gid))? }, } if let Err(err) = create_dir(&chunk_dir, options.clone()) { -- 2.20.1