public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* Re: [pbs-devel] applied: [PATCH proxmox-backup v2 1/2] pbs-config: add 'create_mocked_lock' helper
@ 2021-09-07  8:03 Dietmar Maurer
  0 siblings, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2021-09-07  8:03 UTC (permalink / raw)
  To: Dominik Csapak, Proxmox Backup Server development discussion,
	Wolfgang Bumiller


> On 9/7/21 09:49, Dietmar Maurer wrote:
> > I really do not like this solution :-(
> > 
> 
> was the trait approach better ?

> 
no, that was worse

> since the only remaining way i can can currently think of is to
> workaround the locks everywhere in src/tape/*.rs

I am also out of ideas ...

At least the tests works again.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pbs-devel] applied: [PATCH proxmox-backup v2 1/2] pbs-config: add 'create_mocked_lock' helper
  2021-09-07  7:49 Dietmar Maurer
@ 2021-09-07  8:01 ` Dominik Csapak
  0 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-09-07  8:01 UTC (permalink / raw)
  To: Dietmar Maurer, Proxmox Backup Server development discussion,
	Wolfgang Bumiller

On 9/7/21 09:49, Dietmar Maurer wrote:
> I really do not like this solution :-(
> 

was the trait approach better ?

since the only remaining way i can can currently think of is to
workaround the locks everywhere in src/tape/*.rs





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pbs-devel] applied: [PATCH proxmox-backup v2 1/2] pbs-config: add 'create_mocked_lock' helper
@ 2021-09-07  7:49 Dietmar Maurer
  2021-09-07  8:01 ` Dominik Csapak
  0 siblings, 1 reply; 4+ messages in thread
From: Dietmar Maurer @ 2021-09-07  7:49 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Wolfgang Bumiller,
	Dominik Csapak

I really do not like this solution :-(

> On 09/07/2021 9:05 AM Wolfgang Bumiller <w.bumiller@proxmox.com> wrote:
> 
>  
> applied both patches
> 
> On Mon, Sep 06, 2021 at 05:00:25PM +0200, Dominik Csapak wrote:
> > by making the field an option and making it None in the mocked case
> > this function is only intended for testing and hidden from the docs
> > 
> > Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> > ---
> > changes from v1:
> > * mark function unsafe, so that it is even more clear that this is not
> >   intended for 'normal' code
> >  pbs-config/src/lib.rs | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> > 
> > diff --git a/pbs-config/src/lib.rs b/pbs-config/src/lib.rs
> > index 29811164..bd5430a3 100644
> > --- a/pbs-config/src/lib.rs
> > +++ b/pbs-config/src/lib.rs
> > @@ -18,7 +18,13 @@ pub fn backup_group() -> Result<nix::unistd::Group, Error> {
> >      pbs_tools::sys::query_group(BACKUP_GROUP_NAME)?
> >          .ok_or_else(|| format_err!("Unable to lookup '{}' group.", BACKUP_GROUP_NAME))
> >  }
> > -pub struct BackupLockGuard(std::fs::File);
> > +pub struct BackupLockGuard(Option<std::fs::File>);
> > +
> > +#[doc(hidden)]
> > +/// Note: do not use for production code, this is only intended for tests
> > +pub unsafe fn create_mocked_lock() -> BackupLockGuard {
> > +    BackupLockGuard(None)
> > +}
> >  
> >  /// Open or create a lock file owned by user "backup" and lock it.
> >  ///
> > @@ -41,7 +47,7 @@ pub fn open_backup_lockfile<P: AsRef<std::path::Path>>(
> >      let timeout = timeout.unwrap_or(std::time::Duration::new(10, 0));
> >  
> >      let file = proxmox::tools::fs::open_file_locked(&path, timeout, exclusive, options)?;
> > -    Ok(BackupLockGuard(file))
> > +    Ok(BackupLockGuard(Some(file)))
> >  }
> >  
> >  /// Atomically write data to file owned by "root:backup" with permission "0640"
> > -- 
> > 2.30.2
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup v2 1/2] pbs-config: add 'create_mocked_lock' helper
  2021-09-06 15:00 [pbs-devel] " Dominik Csapak
@ 2021-09-07  7:05 ` Wolfgang Bumiller
  0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Bumiller @ 2021-09-07  7:05 UTC (permalink / raw)
  To: Dominik Csapak; +Cc: pbs-devel

applied both patches

On Mon, Sep 06, 2021 at 05:00:25PM +0200, Dominik Csapak wrote:
> by making the field an option and making it None in the mocked case
> this function is only intended for testing and hidden from the docs
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> changes from v1:
> * mark function unsafe, so that it is even more clear that this is not
>   intended for 'normal' code
>  pbs-config/src/lib.rs | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/pbs-config/src/lib.rs b/pbs-config/src/lib.rs
> index 29811164..bd5430a3 100644
> --- a/pbs-config/src/lib.rs
> +++ b/pbs-config/src/lib.rs
> @@ -18,7 +18,13 @@ pub fn backup_group() -> Result<nix::unistd::Group, Error> {
>      pbs_tools::sys::query_group(BACKUP_GROUP_NAME)?
>          .ok_or_else(|| format_err!("Unable to lookup '{}' group.", BACKUP_GROUP_NAME))
>  }
> -pub struct BackupLockGuard(std::fs::File);
> +pub struct BackupLockGuard(Option<std::fs::File>);
> +
> +#[doc(hidden)]
> +/// Note: do not use for production code, this is only intended for tests
> +pub unsafe fn create_mocked_lock() -> BackupLockGuard {
> +    BackupLockGuard(None)
> +}
>  
>  /// Open or create a lock file owned by user "backup" and lock it.
>  ///
> @@ -41,7 +47,7 @@ pub fn open_backup_lockfile<P: AsRef<std::path::Path>>(
>      let timeout = timeout.unwrap_or(std::time::Duration::new(10, 0));
>  
>      let file = proxmox::tools::fs::open_file_locked(&path, timeout, exclusive, options)?;
> -    Ok(BackupLockGuard(file))
> +    Ok(BackupLockGuard(Some(file)))
>  }
>  
>  /// Atomically write data to file owned by "root:backup" with permission "0640"
> -- 
> 2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-07  8:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07  8:03 [pbs-devel] applied: [PATCH proxmox-backup v2 1/2] pbs-config: add 'create_mocked_lock' helper Dietmar Maurer
  -- strict thread matches above, loose matches on Subject: below --
2021-09-07  7:49 Dietmar Maurer
2021-09-07  8:01 ` Dominik Csapak
2021-09-06 15:00 [pbs-devel] " Dominik Csapak
2021-09-07  7:05 ` [pbs-devel] applied: " Wolfgang Bumiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal