From: Lukas Wagner <l.wagner@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>, Markus Frank <m.frank@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup] api: enhance directory existence check
Date: Wed, 29 Nov 2023 15:51:55 +0100 [thread overview]
Message-ID: <7854aa5a-9d94-418a-bbf8-43182235b023@proxmox.com> (raw)
In-Reply-To: <20231129140838.133066-1-m.frank@proxmox.com>
On 11/29/23 15:08, Markus Frank wrote:
> Instead of just checking the existence of the path, the code now also checks
> whether the directory is empty, continues if it is, and aborts if it is not.
>
> Previously, if a directory were deleted and a directory with the same name
> would be created, the old check prevented the creation even though the
> directory could be used as a mount point.
But that does not detect if another (empty) filesystem is already
mounted at that directory, right?
>
> Signed-off-by: Markus Frank <m.frank@proxmox.com>
> ---
> src/api2/node/disks/directory.rs | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs
> index 5e1cb124..cd7b44a3 100644
> --- a/src/api2/node/disks/directory.rs
> +++ b/src/api2/node/disks/directory.rs
> @@ -155,13 +155,17 @@ pub fn create_datastore_disk(
>
> let mount_point = format!("{}{}", BASE_MOUNT_DIR, &name);
>
> - // check if the default path does exist already and bail if it does
> + // check if the default path does exist already
> + // and bail if it does and is not empty
> let default_path = std::path::PathBuf::from(&mount_point);
>
> match std::fs::metadata(&default_path) {
> Err(_) => {} // path does not exist
> Ok(_) => {
> - bail!("path {:?} already exists", default_path);
> + let is_empty = default_path.read_dir()?.next().is_none();
> + if !is_empty {
> + bail!("path {:?} already exists and is not empty", default_path);
You can inline 'default_path' here: {default_path:?}
> + }
> }
> }
>
Also, I guess you could change the 'match' to a
'if std::fs::metadata(...).is_ok()', since we ignore the enclosed values
anyway.
--
- Lukas
next prev parent reply other threads:[~2023-11-29 14:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-29 14:08 Markus Frank
2023-11-29 14:51 ` Lukas Wagner [this message]
2023-11-29 15:00 ` Christian Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7854aa5a-9d94-418a-bbf8-43182235b023@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=m.frank@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.