Skip to content

Commit

Permalink
Rename lib/inheritLevels.pm to lib/ZnapZend/InheritLevels.pm to m…
Browse files Browse the repository at this point in the history
…inimize confusion

From issue oetiker#646 discussion follow-up

Signed-off-by: Jim Klimov <jimklimov@gmail.com>
  • Loading branch information
jimklimov committed May 28, 2024
1 parent a5480d1 commit 086b6d0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
* Fix make install of Perl modules with a custom DESTDIR and/or libdir @jimklimov
* Renamed `lib/inheritLevels.pm` to `lib/ZnapZend/InheritLevels.pm`
to minimize confusion (especially in OS-wide Perl module
installations) -- @jimklimov

znapzend (0.22.0) unstable; urgency=medium

Expand Down
19 changes: 10 additions & 9 deletions lib/inheritLevels.pm → lib/ZnapZend/InheritLevels.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package inheritLevels;
package ZnapZend::InheritLevels;
# Note: classes made by Class::Struct may not be sub-namespaced
# (UPDATE: comment might be valid at least in older Perl versions?)

use Class::Struct;

Expand All @@ -10,7 +11,7 @@ use Class::Struct;
### For "usual" datasets (filesystem,volume) `zfs` returns the
### properties inherited from higher level datasets; but for
### snapshots it only returns the same - not from higher snaps.
struct ('inheritLevels' => {
struct ('ZnapZend::InheritLevels' => {
zfs_local => '$', # set to ask for properties defined locally in dataset
zfs_inherit => '$', # set to ask for properties inherited from higher datasets
zfs_received => '$', # set to ask for properties received during "zfs send|recv" (no-op for now, mentioned for completeness)
Expand Down Expand Up @@ -59,17 +60,17 @@ sub getInhMode {
sub reset {
# Without args, just resets all fields back to undef so they can be
# re-assigned later. With an arg tries to import a legacy setting by
# number or string, or copy from another instance of inheritLevels.
# number or string, or copy from another instance of InheritLevels.
my $self = shift;

$self->zfs_local(undef);
$self->zfs_inherit(undef);
$self->zfs_received(undef);
$self->snapshot_recurse_parent(undef);
if (@_) {
my $arg = shift;
# Assign from legacy values
if ($arg->isa('inheritLevels')) {
if ($arg->isa('ZnapZend::InheritLevels') or $arg->isa('InheritLevels')) {
$self->zfs_local($arg->zfs_local);
$self->zfs_inherit($arg->zfs_inherit);
$self->zfs_received($arg->zfs_received);
Expand All @@ -89,7 +90,7 @@ sub reset {
} elsif (!defined($arg) or $arg == undef) {
1; # No-op, keep fields undef
} else {
warn "inheritLevels::reset() got unsupported argument '$arg'\n";
warn "ZnapZend::InheritLevels::reset() got unsupported argument '$arg'\n";
return 0;
}
}
Expand All @@ -102,14 +103,14 @@ __END__
=head1 NAME
inheritLevels - helper struct for various options of ZFS property inheritance
ZnapZend::InheritLevels - helper struct for various options of ZFS property inheritance
=head1 SYNOPSIS
use inheritLevels;
use ZnapZend::InheritLevels;
use ZnapZend::ZFS;
...
my $inherit = new inheritLevels;
my $inherit = new ZnapZend::InheritLevels;
$inherit->zfs_local(1);
$inherit->zfs_inherit(1);
my $properties = $self->getSnapshotProperties($snapshot, $recurse, $inherit, @dstSyncedProps);
Expand Down
20 changes: 10 additions & 10 deletions lib/ZnapZend/ZFS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base -base;
use Mojo::Exception;
use Mojo::IOLoop::Subprocess;
use Data::Dumper;
use inheritLevels;
use ZnapZend::InheritLevels;

### attributes ###
has debug => sub { 0 };
Expand Down Expand Up @@ -547,13 +547,13 @@ sub mostRecentCommonSnapshot {
# deletion of "protected" last-known-synced snapshots, we consider both
# local and inherited values of the dst_X_synced flag, if present.
# See definition of recognized $inherit values for this context in
# getSnapshotProperties() code and struct inheritLevels.
# getSnapshotProperties() code and struct ZnapZend::InheritLevels.
my $inherit = shift; # May be not passed => undef
if (!defined($inherit)) {
# We leave defined but invalid values of $inherit to
# getSnapshotProperties() to figure out and complain,
# but for this routine's purposes set a specific default.
$inherit = new inheritLevels;
$inherit = new ZnapZend::InheritLevels;
$inherit->zfs_local(1);
$inherit->zfs_inherit(1);
$inherit->snapshot_recurse_parent(1);
Expand Down Expand Up @@ -1300,8 +1300,8 @@ sub getSnapshotProperties {
# 1 = local + inherit as defined by zfs
# 2 = local + recurse into parent that has same snapname
# 3 = local + inherit as defined by zfs + recurse into parent
# See struct inheritLevels for reusable definitions.
my $inherit = shift; # May be not passed => undef => will make a new inheritLevels instance below
# See struct ZnapZend::InheritLevels for reusable definitions.
my $inherit = shift; # May be not passed => undef => will make a new InheritLevels instance below

# Limit the request to `zfs get` to only pick out certain properties
# and save time not-processing stuff the caller will ignore?..
Expand All @@ -1321,13 +1321,13 @@ sub getSnapshotProperties {
}

if (!defined($inherit)) {
$inherit = new inheritLevels;
$inherit = new ZnapZend::InheritLevels;
$inherit->zfs_local(1);
} else {
# Data type check
if ( ! $inherit->isa('inheritLevels') ) {
$self->zLog->warn("getSnapshotProperties(): inherit argument is not an instance of struct inheritLevels");
my $newInherit = new inheritLevels;
if ( ! ($inherit->isa('ZnapZend::InheritLevels') or $inherit->isa('InheritLevels')) ) {
$self->zLog->warn("getSnapshotProperties(): inherit argument is not an instance of struct ZnapZend::InheritLevels");
my $newInherit = new ZnapZend::InheritLevels;
if (!$newInherit->reset($inherit)) {
# caller DID set something, so set a default... local_zfsinherit
$newInherit->zfs_local(1);
Expand Down Expand Up @@ -1459,7 +1459,7 @@ sub getSnapshotProperties {
# Go up to root of the pool, without recursing into other children
# of the parent datasets/snapshots, and without inheriting stuff
# that is not locally defined properties of a parent (or its parent).
my $inherit_local_recurseparent = new inheritLevels;
my $inherit_local_recurseparent = new ZnapZend::InheritLevels;
$inherit_local_recurseparent->snapshot_recurse_parent(1);
$inherit_local_recurseparent->zfs_local(1);
my $parentProperties = $self->getSnapshotProperties($parentSnapshot, 0, $inherit_local_recurseparent, $propnames);
Expand Down

0 comments on commit 086b6d0

Please sign in to comment.