[pve-devel] [PATCH v2 storage] storage/plugin: factoring out regex for backup extension rey

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Aug 4 10:21:04 CEST 2021


On Wed, Aug 04, 2021 at 09:56:14AM +0200, Lorenz Stechauner wrote:
> 
> On 03.08.21 09:15, Wolfgang Bumiller wrote:
> > On Mon, Aug 02, 2021 at 12:52:36PM +0200, Lorenz Stechauner wrote:
> > > Signed-off-by: Lorenz Stechauner <l.stechauner at proxmox.com>
> > > ---
> > > changes to v1:
> > > * factored $compressor_extension_re out of $backup_extension_re
> > >      should now be less confusing
> > not sure about less confusing... but I suppose it'll have to do
> > 
> > >   PVE/Storage.pm        | 14 +++++++++-----
> > >   PVE/Storage/Plugin.pm |  4 ++--
> > >   2 files changed, 11 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> > > index c04b5a2..942246f 100755
> > > --- a/PVE/Storage.pm
> > > +++ b/PVE/Storage.pm
> > > @@ -105,6 +105,10 @@ our $iso_extension_re = qr/\.(?:iso|img)/i;
> > >   our $vztmpl_extension_re = qr/\.tar\.([gx]z)/i;
> > > +our $compressor_extension_re = qr/\.(${\PVE::Storage::Plugin::COMPRESSOR_RE})/i;
> > > +
> > > +our $backup_extension_re = qr/\.(tgz|(?:tar|vma)$compressor_extension_re?)/i;
> > The reason I don't find it less confusing is that both of these are
> > globals, and one introduces 1 capture group, the other introduces 2
> > capture groups.
> how about using on all three regex'es (iso, vztmpl, backup) two capture
> groups?
> it would be a bit less confusing, because it's more consistent (?)
> 
> ".tar.gz" -> $1 = "tar.gz"; $2 = "gz"
> ".iso" -> $1 = "iso"; $2 = ""
> 
> would something like this be a good (or at least better) idea?
> 
> our $ISO_EXT_RE = qr/\.(iso|img)()/i;

Part of me is making a 🤪 face here...

> our $VZTMPL_EXT_RE = qr/\.(tar\.([gx]z))/i;
> our $BACKUP_EXT_RE =
> qr/\.(tgz|(?:tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)/i;

BUt also, part of me *does* like this more (though maybe with
`((iso|img))` to have `$2 eq $1` on the ISO one... but I'm not sure
there'll ever be a "perfect" version anyway... I guess doc comments to
point out the differences are more important than the actual REs...

Your choice.





More information about the pve-devel mailing list