all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox-backup v5 1/2] fix #5439: allow to reuse existing datastore
Date: Thu, 29 Aug 2024 14:58:25 +0200	[thread overview]
Message-ID: <20240829125825.lmouyfxmaha3ffvr@luna.proxmox.com> (raw)
In-Reply-To: <twav3jicywadkxfc7tuj7uvzqy5gaai6koufx4sscdru4jq4ao@eb2sxs42jr33>

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


      reply	other threads:[~2024-08-29 12:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-29 10:45 Gabriel Goller
2024-08-29 10:45 ` [pbs-devel] [PATCH proxmox-backup v5 2/2] web: disallow datastore in root, add reuse-datastore flag Gabriel Goller
2024-08-29 11:56 ` [pbs-devel] [PATCH proxmox-backup v5 1/2] fix #5439: allow to reuse existing datastore Wolfgang Bumiller
2024-08-29 11:58   ` Wolfgang Bumiller
2024-08-29 12:58     ` Gabriel Goller [this message]

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=20240829125825.lmouyfxmaha3ffvr@luna.proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=w.bumiller@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal