Skip to content

Commit

Permalink
No git compressed, --system-config, added_hash() deep. zsh-completion…
Browse files Browse the repository at this point in the history
… help
  • Loading branch information
vaeth committed Jul 31, 2017
1 parent 9f44caa commit 28defeb
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 74 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# ChangeLog for squashmount

*squashmount-16.0.0
Martin Väth <martin at mvath.de>:
- docs/examples: Exclude git compressed files for recompression
- New option --system-config and default to {/usr,}/lib/squashmount.pl
- Let standard_mount() and added_hash() add array-references to
array-references or strings, and hash-references to hash-references
(recursively).
- Formulate zsh-completion help in a more standard manner

*squashmount-15.4.3_p2
Martin Väth <martin at mvath.de>:
- Remove CapabilityBoundingSet: It breaks overlay and possibly others
Expand Down
6 changes: 5 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ Note that the hook-file in this directory treats the mount point "gentoo"
specially! See the example configuration in etc/squashmount.pl how to
setup an appropriate mount point "gentoo" for this setting.

In all cases you have to copy etc/squashmount.pl to /etc/squashmount.pl
In all cases you have to copy lib/squashmount.pl to /etc/squashmount.pl
and adapt it to your need! This is an essential point of squashmount,
and it is impossible to use squashmount without setting up the configuration.
You can optionally also copy lib/squashmount.pl to /lib/squashmount.pl or
/usr/lib/squashmount.pl to provide a system-wide example config.
Alternatively, you can also modify that file to use it as a fallback if
/etc/squashmount.pl is not readable.


Some Examples
Expand Down
130 changes: 102 additions & 28 deletions bin/squashmount
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env perl
BEGIN { require 5.022 }
package Squashmount v15.4.3;
package Squashmount v16.0.0;

use strict;
use warnings;
Expand Down Expand Up @@ -58,7 +58,9 @@ so that the data is regularly resquashed.
You can manually force this resquashing by calling B<squashmount remount>.

B<squashmount> reads its mount-points from F</etc/squashmount.pl> which is
documented later (the path can be changed with B<--config>).
documented later (the path can be changed with B<--config>, and there are
system fallbacks F</usr/lib/squashmount.pl> and F</lib/squashmount.pl> which
can be changed with B<--system-config>).
Configured directories are created if necessary; B<squashmount> never removes
directories (not even configured temporary directories).

Expand Down Expand Up @@ -424,6 +426,17 @@ Print version number and exit
Using I<file> instead of B</etc/squashmount.pl> as a config file.
If this option is repeated, all passed B<file>s are parsed in the given order.

=item B<--system-config=>I<file> (accumulative)

If the file B</etc/squashmount.pl> cannot be read successfully
(or if none of the files specified by B<--config> can be read, respectively),
then the first successfully read file from the system config list
B</usr/lib/squashmount.pl> or B</lib/squashmount.pl> is used instead.
When this option is specified, that list is replaced by the filenames
specified by this option.
Note that in contrast to B<--config> only the first readable file is used,
and also this only if all of the regular configuration files fail.

=item B<--umount=>I<opt> or B<-u> I<opt> (accumulative)

Add option I<opt> to the default B<@umount> array (see also B<--umount-ro>).
Expand Down Expand Up @@ -958,7 +971,7 @@ see the remarks at the end of this manpage.)

=item DIR => '/usr/local',

=item FILE => '/usr/local.sfs'
=item FILE => '/usr/local.sfs',

=back

Expand Down Expand Up @@ -990,7 +1003,7 @@ see the remarks at the end of this manpage.)

=item RM_READONLY => 1, # remove temporary READONLY on stop

=item RM_WORKDIR => 1 # remove temporary WORKDIR on stop
=item RM_WORKDIR => 1, # remove temporary WORKDIR on stop

=back

Expand All @@ -1012,7 +1025,7 @@ see the remarks at the end of this manpage.)

=item DIFF => [ qr{^ls-R$},

=item qr{^tex(/generic(/config(/language(\.(dat(\.lua)?|def)))?)?)?$}n ]
=item qr{^tex(/generic(/config(/language(\.(dat(\.lua)?|def)))?)?)?$}n ],

=back

Expand Down Expand Up @@ -1044,6 +1057,12 @@ see the remarks at the end of this manpage.)

=item READONLY => '/usr/portage.mount/readonly',

=item MKSQUASHFS => [ # Do not recompress git-compressed data

=item # See https://github.com/plougher/squashfs-tools/issues/24

=item '-action', 'uncompressed@subpathname(*/.git/objects/pack)' ],

=item THRESHOLD => '40m', # resquash on umount if 40 MB changed, or

=item # if local/* (with * not .git, profiles, metadata) changed:
Expand All @@ -1054,7 +1073,7 @@ see the remarks at the end of this manpage.)

=item # be more explicit about the changes you do not care about, e.g.:

=item # DIFF => qr{^local(/profiles(/use\.local\.desc)?)?$}n
=item # DIFF => qr{^local(/profiles(/use\.local\.desc)?)?$}n,

=back

Expand Down Expand Up @@ -1082,7 +1101,7 @@ see the remarks at the end of this manpage.)

=item SKIPDIR => qr{(^|/)tmp}ni, # tmp* Tmp* TMP*

=item SKIPFUNC => sub { my ($rel, $abs, $ro) = @_; return (-d $abs) }
=item SKIPFUNC => sub { my ($rel, $abs, $ro) = @_; return (-d $abs) },

=back

Expand Down Expand Up @@ -1393,8 +1412,8 @@ The intention is that this function can be used to return e.g. a temporary
dir name by using something like as in the B<fancy_temporary> example above.

Be aware that if this function uses B<File::Temp::newdir>, it should pass
B<CLEANUP =E<gt> ''> to avoid that the directory is magically removed recursively:
Forgetting this can severely damage your data!
B<CLEANUP =E<gt> ''> to avoid that the directory is magically removed
recursively: Forgetting this can severely damage your data!

As an exception, if the function returns the corresponding created object
(and not only a filename as in the B<make_temporary_subdir> example above),
Expand Down Expand Up @@ -1845,8 +1864,12 @@ In addition, the values for the keys B<CHANGES>, B<WORKDIR>, B<READONLY>,
and B<FILE> are generated by just appending B<.mount/changes>,
B<.mount/workdir>, B<.mount/readonly>, B<.mount/>I<dirname>B<.sfs>.
Moreover, if I<...> are references to hashes, they are added to the hash:
Later hashes override earlier ones; setting a value to C<undef> in a sense
cancels a previous definition.
Later hash entries override earlier ones unless the values itself are hashes
or arrays; so, for instance setting a value to C<undef> in a sense cancels
a previous definition. If a hash entry itself is a hash or array reference,
it does not replace the previous value but is added to it (provided that
the previous value was a hash or array reference or a single string,
respectively). Adding hash references to hash references works recursively.

=item B<added_hash(>I<hashref>B<,> ...B<)>

Expand All @@ -1856,9 +1879,9 @@ not fill a hash with certain values first.
The idea is that this function can be used to start with a "default" hash
and override/modify/add some data at your discretion.

For perl specialists: This function is practically the same as that provided
For perl specialists: This function is similar to the one provided
by B<Hash::Merge::Simple>, but it does not require the existence of that
perl module, and it does not work recursively.
perl module and can add arrays to strings.

=back

Expand All @@ -1877,7 +1900,7 @@ B<THRESHOLD> option) in a shorter way:

=over 24

=item THRESHOLD => '40m'
=item THRESHOLD => '40m',

=back

Expand Down Expand Up @@ -1908,13 +1931,23 @@ Here is such an example which also demonstrates the use of B<added_hash()>:

=item my $defaults = added_hash($always, { BACKUP => '.bak' }, $tempdir);

=item # Adding $git will not recompress git-compressed data.

=item # See https://github.com/plougher/squashfs-tools/issues/24

=item my $git = { MKSQUASHFS => [

=item '-action', 'uncompressed@subpathname(*/.git/objects/pack)' ],

=item };

=item push(@mounts,

=over 16

=item standard_mount('portage', '/usr/portage', $defaults),
=item standard_mount('portage', '/usr/portage', $defaults, $git),

=item standard_mount('kernel', '/usr/src', $defaults),
=item standard_mount('kernel', '/usr/src', $defaults, $git),

=item standard_mount('games', '/usr/share/games', $defaults, {

Expand Down Expand Up @@ -2371,6 +2404,7 @@ my $errorbreak = '';
my $fatalreturn = undef;
my $firstmatch = '';
my @configs = ();
my @system_configs = ();
my @argv = ();
my $separator = "\n";
my $rundir = undef;
Expand Down Expand Up @@ -3588,11 +3622,11 @@ sub read_config_file {
my ($file) = @_;
$file = &bad_abs_path($file);
unless(defined($file)) {
&warning('skipping config file ' . $_[0] . ' (not a valid path)') unless($quiet);
&warning('skipping config file ' . $_[0] . ' (not a valid path)') unless($verbose);
return
}
unless(-f $file) {
&warning("skipping config file $file (not a file)") unless($quiet);
if((-d $file) || !(-r $file)) {
&warning("skipping config file $file (not a readable file)") if($verbose);
return
}
&info("reading config file $file") if($verbose > 2);
Expand Down Expand Up @@ -3650,24 +3684,49 @@ sub added_hash(@) {
my $a = {};
for my $i (@_) {
unless(defined($i) && (ref($i) eq 'HASH')) {
&warning('wrong argument in &added_hash() or &standard_mount():',
&warning('wrong argument in added_hash() or standard_mount():',
'hash reference expected');
next
}
for my $j (keys(%$i)) {
$a->{$j} = $i->{$j}
unless(exists($a->{$j})) {
$a->{$j} = $i->{$j};
next
}
my $type = ref($i->{$j});
if($type eq 'HASH') {
if(ref($a->{$j}) eq 'HASH') {
$a->{$j} = &added_hash($a->{$j}, $i->{$j})
} else {
$a->{$j} = $i->{$j}
}
} elsif($type eq 'ARRAY') {
my $source = $i->{$j};
my $aref = ref($a->{$j});
if($aref eq 'ARRAY') {
my $arrayref = $a->{$j};
push(@$arrayref, @$source)
} elsif(($aref eq '') && defined($a->{$j})) {
$a->{$j} = [ $a->{$j}, @$source ]
} else {
$a->{$j} = $source
}
} else {
$a->{$j} = $i->{$j}
}
}
}
$a
}

sub standard_mount($$@) {
my ($tag, $dir, @rest) = @_;
&fatal('first argument of &standard_mount() should be a (nonempty) tag')
my $tag = shift();
my $dir = shift();
&fatal('first argument of standard_mount() should be a (nonempty) tag')
unless(defined($tag) && (ref(\$tag) eq 'SCALAR') && ($tag ne ''));
# Checking for -d $dir might be wrong: the config might use
# this as a flag and not add the result to @mounts later on
&fatal('error: second argument of &standard_mount() should be a directory')
&fatal('error: second argument of standard_mount() should be a directory')
unless(defined($dir) && (ref(\$dir) eq 'SCALAR') && ($dir ne ''));
$dir = File::Spec->canonpath($dir);
&added_hash({
Expand All @@ -3678,7 +3737,7 @@ sub standard_mount($$@) {
WORKDIR => File::Spec->catdir($dir . '.mount', 'workdir'),
FILE => File::Spec->catfile($dir . '.mount',
((File::Spec->splitpath($dir))[2]) . '.sfs')
}, @rest)
}, @_)
}

# Read settings from /run/squashmount:
Expand Down Expand Up @@ -4712,6 +4771,7 @@ Getopt::Long::GetOptions(
'man|?', sub { &pod2usage(-verbose => 2, -exit => 0) },
'version|V', \&version,
'config|c=s', \@configs,
'system-config=s', \@system_configs,
'umount|u=s', \@CFG::umount,
'umount-ro|U=s', \@CFG::umount_ro,
'fumount=s', \@CFG::fumount,
Expand Down Expand Up @@ -4771,9 +4831,12 @@ if($opt_user) {
unless(@configs);
$rundir //= File::Spec->catdir($root, 'run', 'squashmount')
}
@system_configs = (File::Spec->catfile($root, 'usr', 'lib', 'squashmount.pl'),
File::Spec->catfile($root, 'lib', 'squashmount.pl'))
unless(@system_configs);

&fatal("$rundir is not an absolute path") unless(&is_abspath($rundir));
for my $i (@configs) {
for my $i (@configs, @system_configs) {
&fatal("config-file $i is not an absolute path")
unless(&is_abspath($i))
}
Expand Down Expand Up @@ -4925,10 +4988,21 @@ $|=1;

{
local @ARGV = @argv;
my $have_read_config = '';
for my $file (@configs) {
&read_config_file($file)
$have_read_config = 1 if(&read_config_file($file))
}
unless($have_read_config) {
for my $file (@system_configs) {
if(&read_config_file($file)) {
$have_read_config = 1;
last
}
}
}
$run_ro = !$CFG::storing
$run_ro = !$CFG::storing;
fatal('None of the config files could be read:',
@configs, @system_configs) unless($have_read_config)
}

# Modify options according to config:
Expand Down
Loading

0 comments on commit 28defeb

Please sign in to comment.