| 1 | package App::FileSync::Admin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Server-side administration: the operations behind filesync-admin. Every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # method works directly on the server root; none of them talks to a client. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 327 | ▶ | use App::FileSync::Platform; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 327 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 327 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 327 | ▶ | use autodie qw(:all); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 327 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 327 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 327 | ▶ | use List::Util qw(any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 327 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 327 | ▶ | use Sub::Private { mode => 'enforce' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 327 | ▶ | use parent 'App::FileSync::Base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 327 | ▶ | use App::FileSync qw(json_decode validate_relpath validate_repo_name validate_client_id parse_since parse_until); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 327 | ▶ | use App::FileSync::Args qw(named positional); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 327 | ▶ | use App::FileSync::Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 327 | ▶ | use App::FileSync::Constants qw($DEFAULT_SERVER_ROOT $ROLE_CLIENT @ROLES); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 327 | ▶ | use App::FileSync::I18N qw(os_error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 327 | ▶ | use App::FileSync::Ignore; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 327 | ▶ | use App::FileSync::IO qw(ensure_dir list_dir open_file sha256_file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 327 | ▶ | use App::FileSync::Settings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 327 | ▶ | use App::FileSync::Store; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 327 | ▶ | use App::FileSync::Trash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 327 | ▶ | use App::FileSync::Verify; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 327 | ▶ | use version; our $VERSION = version->declare('0.002.1'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # The per-repo metadata directories a new repo starts with. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 327 | Readonly my @META_DIRS => qw(clients trash journal locks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Journal files are one per month, named YYYY-MM.jsonl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 327 | Readonly my $JOURNAL_FILE => qr/\.jsonl\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # A trash date argument. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 327 | Readonly my $DATE => qr/\A\d{4}-\d{2}-\d{2}\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Arguments most methods take. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 327 | my %REPO = (repo => { type => 'string', min => 1 }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | App::FileSync::Admin - server-side repo, client and recovery administration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | my $admin = App::FileSync::Admin->new(root => '/srv/filesync'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $admin->repo_create(name => 'docs'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | $admin->client_allow(repo => 'docs', client => 'laptop'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | my $report = $admin->verify(repo => 'docs', deep => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | The library behind C<filesync-admin>. Methods return hashrefs or arrayrefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | for the command line to print (or encode as JSON) and raise catalogued | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | errors (see L<App::FileSync::I18N>) on failure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | Purpose: an administrator for one server root. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | Args: optional C<root> (default C<FILESYNC_ROOT>, then F</srv/filesync>), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | C<logger> (default from L<App::FileSync::Settings>), C<language>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | Returns: the object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | Side Effects: builds a logger from the settings when none is given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | my $admin = App::FileSync::Admin->new(root => $root); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | my $admin = App::FileSync::Admin->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | print $admin->root, "\n"; # /srv/filesync unless FILESYNC_ROOT says otherwise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | root => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | logger => { type => 'object', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | language => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | { type => 'object', isa => 'App::FileSync::Admin' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | args.invalid an argument is malformed fix the call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | root' = first non-empty ⟨root, FILESYNC_ROOT, "/srv/filesync"⟩ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 136 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 136 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 136 | my $args = named(\@_, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | root => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | logger => { type => 'object', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | language => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | }, 'Admin->new'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 136 | ▶ | my ($root) = grep { defined && length } $args->{root}, $ENV{FILESYNC_ROOT}, $DEFAULT_SERVER_ROOT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && length $_
MC/DC50%1/2
defined $_ && length $_
defined $_
length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | root => $root, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | language => $args->{language}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 136 | ▶ | logger => $args->{logger} || App::FileSync::Settings::logger(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'logger'} || App::FileSync::Settings::logger()
MC/DC0%0/2
$args->{'logger'} || App::FileSync::Settings::logger()
$args->{'logger'}
App::FileSync::Settings::logger()
Truth table33%1/3
A || B
A= $args->{'logger'}B= App::FileSync::Settings::logger()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | =head2 root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | Purpose: the server root this object administers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | Args: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | Returns: the path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | Side Effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | my $root = $admin->root; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | print $admin->root, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | [ { name => 'self', type => 'object' } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | { type => 'string', min => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | None. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | root = self.root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 30 | ▶ | sub root { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 30 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 30 | return $self->{root}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | =head2 repo_create | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | Purpose: create a repo: its master tree, metadata directories, policy and an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | empty index. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | Args: C<name> (a repo id), optional C<trash_days>, C<max_deletes>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | C<max_delete_percent> (non-negative integers) and C<ignore> (patterns; the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | default ignore list when absent or empty). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | Returns: C<{ name, master, config }> (the master and config paths). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | Side Effects: creates F<ROOT/master/NAME> and F<ROOT/.filesync/repos/NAME>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | $admin->repo_create(name => 'docs', trash_days => 60); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | my $made = $admin->repo_create(name => 'photos', ignore => [ '*.tmp', '/cache/' ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | print "master at $made->{master}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | name => { type => 'string', min => 1, max => 64 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | trash_days => { type => 'integer', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | max_deletes => { type => 'integer', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | max_delete_percent => { type => 'integer', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ignore => { type => 'arrayref', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | type => 'hashref', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | name => { type => 'string' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | master => { type => 'string' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | config => { type => 'string' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | admin.bad_repo the name is not a valid id letters, digits, . _ - ; at most 64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | admin.repo_exists the repo already exists choose another name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | admin.root_unwritable the root cannot be written chown it, or use --root elsewhere | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | io.mkdir / io.write the files cannot be written check permissions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ΔFS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | pre name ∈ Id ∧ repo_config_path(root, name) ∉ dom FS ∧ writable(root) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | post repo_config_path(root, name) ∈ dom FS' ∧ index(name) = ∅ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | =head3 PSEUDOCODE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | validate the name; refuse if the repo exists or the root cannot be written | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | start from the default policy; apply the given limits and ignore list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | create the master and metadata directories | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | save the policy and an empty index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 82 | ▶ | sub repo_create { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repo_create: called CC=10 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 82 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 82 | my $args = named(\@_, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | name => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | trash_days => { type => 'integer', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | max_deletes => { type => 'integer', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | max_delete_percent => { type => 'integer', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | ignore => { type => 'arrayref', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | }, 'Admin::repo_create'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 82 | my $name = $self->_valid_repo($args->{name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 82 | my $config_path = App::FileSync::Config::repo_config_path($self->{root}, $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 82 | ▶ | $self->_throw('admin.repo_exists', { repo => $name, path => $config_path }) if -e $config_path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 82 | my $master = File::Spec->catdir($self->{root}, 'master', $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 82 | my $meta = App::FileSync::Config::repo_meta_dir($self->{root}, $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 82 | my $config = App::FileSync::Config::default_repo_config($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 82 | for my $limit (qw(trash_days max_deletes max_delete_percent)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 246 | ▶ | $config->{$limit} = $args->{$limit} + 0 if defined $args->{$limit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # A copy: the caller's list must not become the stored policy's storage. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | $config->{ignore} = [ @{ $args->{ignore} } ] if $args->{ignore} && @{ $args->{ignore} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{"ignore"} and @{$args->{"ignore"};}
MC/DC0%0/2
$args->{"ignore"} and @{$args->{"ignore"};}
$args->{"ignore"}
@{$args->{"ignore"};}
Truth table33%1/3
A and B
A= $args->{"ignore"}B= @{$args->{"ignore"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 82 | my $made = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 82 | ensure_dir($_) for $master, map { File::Spec->catdir($meta, $_) } @META_DIRS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 80 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 82 | ▶ | unless ($made) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # A root another account owns is a setup mistake. Name the directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # to fix rather than the deepest one make_path could not create, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # is several levels below the one the administrator passed. Only when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # that directory really is unwritable: a full disk or a bad path keeps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # its own error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | ▶ | my $blocked = _unwritable_base($master) // _unwritable_base($meta); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
_unwritable_base($master) // _unwritable_base($meta)
MC/DC0%0/2
_unwritable_base($master) // _unwritable_base($meta)
_unwritable_base($master)
_unwritable_base($meta)
Truth table33%1/3
A // B
A= _unwritable_base($master)B= _unwritable_base($meta)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | ▶ | $self->_throw('admin.root_unwritable', { root => $self->{root}, blocked => $blocked }) if defined $blocked; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | die $error; ## no critic (ErrorHandling::RequireCarping) -- rethrow unchanged | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 80 | App::FileSync::Config::save_repo($self->{root}, $name, $config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 80 | $self->_store($name, $config)->save_index({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 80 | return { name => $name, master => $master, config => $config_path }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | =head2 repo_list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | Purpose: the repos under this root. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | Args: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | Returns: an arrayref of names, sorted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | Side Effects: reads the metadata directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | print "$_\n" for @{ $admin->repo_list }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | my $repos = $admin->repo_list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | print @{$repos} ? "@{$repos}\n" : "none\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | [ { name => 'self', type => 'object' } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | { type => 'arrayref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | None; a root with no repos gives an empty list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | repo_list = sort { n | n ∈ children(root/.filesync/repos) ∧ isdir(n) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | ▶ | sub repo_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repo_list: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | my $root = File::Spec->catdir($self->{root}, '.filesync', 'repos'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | ▶ | return [ grep { -d File::Spec->catdir($root, $_) } @{ list_dir($root) || [] } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
list_dir($root) || []
MC/DC0%0/1
list_dir($root) || []
list_dir($root)
Truth table50%1/2
A
A= list_dir($root)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | =head2 repo_show | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | Purpose: a repo's policy and where it lives. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | Args: C<$name>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | Returns: C<{ config, master, meta, clients }>; C<clients> is a sorted arrayref. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | Side Effects: reads the repo config. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | my $info = $admin->repo_show('docs'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | my $info = $admin->repo_show('docs'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | print "trash kept $info->{config}{trash_days} days\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | [ { name => 'name', type => 'string', min => 1 } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | { type => 'hashref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | admin.bad_repo the name is not an id check the spelling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | config.no_repo the repo does not exist filesync-admin repo list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | repo_show(n) = ⟨config ↦ load_repo(n), master ↦ master_dir(n), meta ↦ meta_dir(n), clients ↦ sort dom config.clients⟩ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | sub repo_show { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repo_show: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $store = $self->_store($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | config => $store->config, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | master => $store->master_dir(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | meta => $store->meta_dir(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | clients => [ sort keys %{ $store->config->{clients} } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | =head2 client_allow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | Purpose: let a client (or replica) sync a repo. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | Args: C<repo>, C<client> (a client id), optional C<role> (C<client>, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | default, or C<replica>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | Returns: C<{ client, role }>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | Side Effects: rewrites the repo config. Allowing an existing client again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | changes its role. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | $admin->client_allow(repo => 'docs', client => 'backup', role => 'replica'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | $admin->client_allow(repo => 'docs', client => 'laptop'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | repo => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | client => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | role => { type => 'string', optional => 1, memberof => [ 'client', 'replica' ] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | { type => 'hashref', schema => { client => { type => 'string' }, role => { type => 'string' } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | admin.bad_client the client id is not valid letters, digits, . _ - ; at most 64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | admin.bad_role the role is not client/replica choose one of those | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | admin.bad_repo the repo name is not an id check the spelling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | config.no_repo the repo does not exist create it first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | ΔRepoConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | pre client ∈ Id ∧ role ∈ {client, replica} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | clients' = clients ⊕ {client ↦ role} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 80 | ▶ | sub client_allow { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
client_allow: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 80 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 80 | my $args = named(\@_, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | %REPO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | client => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | role => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | }, 'Admin::client_allow'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 80 | my $client = $self->_valid_client($args->{client}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 79 | ▶ | my $role = $args->{role} || $ROLE_CLIENT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{'role'} || $App::FileSync::Admin::ROLE_CLIENT
MC/DC0%0/2
$args->{'role'} || $App::FileSync::Admin::ROLE_CLIENT
$args->{'role'}
$App::FileSync::Admin::ROLE_CLIENT
Truth table66%2/3
A || B
A= $args->{'role'}B= $App::FileSync::Admin::ROLE_CLIENT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | $self->_throw('admin.bad_role', { role => $role, roles => join(', ', @ROLES) }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 79 | ▶ | unless any { $_ eq $role } @ROLES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 79 | my $repo = $self->_valid_repo($args->{repo}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 79 | my $config = App::FileSync::Config::load_repo($self->{root}, $repo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 78 | $config->{clients}{$client} = { role => $role }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 78 | App::FileSync::Config::save_repo($self->{root}, $repo, $config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 78 | return { client => $client, role => $role }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | =head2 client_list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | Purpose: the clients allowed on a repo. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | Args: C<$repo>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | Returns: an arrayref, sorted by id, of C<{ client, role, base }>; C<base> is 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | when the server holds that client's base (it has synced at least once). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | Side Effects: reads the repo config. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | for my $c (@{ $admin->client_list('docs') }) { ... } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | printf "%-12s %s\n", $_->{client}, $_->{role} for @{ $admin->client_list('docs') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | [ { name => 'repo', type => 'string', min => 1 } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | { type => 'arrayref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | config.no_repo the repo does not exist check the name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | client_list(r) = sort ⟨ (c, role(c), base(c) ∈ dom FS) | c ∈ dom clients(r) ⟩ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | sub client_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
client_list: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my ($self, $repo) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | my $store = $self->_store($repo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | my $clients = $store->config->{clients}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # A hand-edited config may hold an id that is not one; list it without a base. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | my $entry = $clients->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | my $base = eval { $store->base_path($_) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | client => $_, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | role => (ref($entry) eq 'HASH' && $entry->{role}) || $ROLE_CLIENT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
ref $entry eq 'HASH' && $entry->{'role'} || $App::FileSync::Admin::ROLE_CLIENT
ref $entry eq "HASH" and $entry->{"role"}
defined $base and -e $base
MC/DC0%0/3
ref $entry eq 'HASH' && $entry->{'role'} || $App::FileSync::Admin::ROLE_CLIENT
ref $entry eq "HASH"
$entry->{"role"}
$App::FileSync::Admin::ROLE_CLIENT
MC/DC0%0/2
defined $base and -e $base
defined $base
-e $base
Truth table0%0/5
A and B || C
A= ref $entry eq "HASH"B= $entry->{"role"}C= $App::FileSync::Admin::ROLE_CLIENT
Truth table0%0/3
A and B
A= defined $baseB= -e $base
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | base => (defined $base && -e $base) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | } sort keys %{$clients} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | =head2 client_forget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | Purpose: drop the server's base for a client, so its next sync starts afresh. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | Args: C<repo>, C<client>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | Returns: C<{ removed =E<gt> 0|1, path }>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | Side Effects: removes the client's base file. The client stays allowed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | $admin->client_forget(repo => 'docs', client => 'laptop'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | my $done = $admin->client_forget(repo => 'docs', client => 'old-laptop'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | print $done->{removed} ? "forgot\n" : "nothing to forget\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | repo => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | client => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | { type => 'hashref', schema => { removed => { type => 'integer' }, path => { type => 'string' } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | store.bad_client the client id is not valid check the spelling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | io.remove the base cannot be removed check permissions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | ΔFS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | FS' = {base_path(r, c)} ⩤ FS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | removed = 1 ⇔ base_path(r, c) ∈ dom FS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 4 | ▶ | sub client_forget { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
client_forget: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 4 | my $args = named(\@_, { %REPO, client => { type => 'string', min => 1 } }, 'Admin::client_forget'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # base_path validates the id, so "../x" cannot reach outside the repo. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 4 | my $path = $self->_store($args->{repo})->base_path($args->{client}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 3 | ▶ | return { removed => 0, path => $path } unless -e $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 3 | ▶ | eval { unlink $path; 1 } or $self->_throw('io.remove', { path => $path, error => os_error($@) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 3 | return { removed => 1, path => $path }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | =head2 journal_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | Purpose: where a repo's journal lives. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | Args: C<$repo>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | Returns: F<ROOT/.filesync/repos/REPO/journal>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | Side Effects: reads the repo config. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | my $dir = $admin->journal_dir('docs'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | print $admin->journal_dir('docs'), "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | [ { name => 'repo', type => 'string', min => 1 } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | { type => 'string', min => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | config.no_repo the repo does not exist check the name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | journal_dir(r) = meta_dir(r) / "journal" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 88 | ▶ | sub journal_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
journal_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 88 | my ($self, $repo) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 88 | return File::Spec->catdir($self->_store($repo)->meta_dir(), 'journal'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | =head2 journal_read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | Purpose: the journal's events, filtered. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | Args: C<repo>; optional filters C<client> (id), C<since> and C<until> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | (C<YYYY-MM-DD> or epoch, inclusive), C<exits> (arrayref of exit codes; selects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | session outcomes), C<warnings> (sessions that kept conflict copies) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | C<limit> (the newest N). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | Returns: an arrayref of event hashrefs, oldest first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | Side Effects: reads every monthly journal file. A torn final line from a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | killed run is skipped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | my $events = $admin->journal_read(repo => 'docs', since => '2026-10-01', limit => 50); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | for my $event (@{ $admin->journal_read(repo => 'docs', exits => [ 1, 2 ]) }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | print "$event->{ts} $event->{client} exit $event->{exit}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | repo => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | client => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | since => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | until => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | exits => { type => 'arrayref', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | warnings => { type => 'boolean', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | limit => { type => 'integer', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | { type => 'arrayref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | when.bad since/until is not a date use YYYY-MM-DD or an epoch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | io.read a journal file cannot be read check permissions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | let E = ⟨ e | f ∈ sort(journal files), line ∈ f, e = json(line) ∈ HASH ⟩ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | journal_read = last limit (sort_by ts (filter(E))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | =head3 PSEUDOCODE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | read every journal file in name (month) order, skipping torn lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | keep events for the client, inside since..until | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | keep session outcomes with a wanted exit code, if asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | keep sessions that kept conflict copies, if asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | sort by time; keep the newest limit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 60 | ▶ | sub journal_read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
journal_read: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 60 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 60 | my $args = named(\@_, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | %REPO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | client => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | since => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | until => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | exits => { type => 'arrayref', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | warnings => { type => 'scalar', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | limit => { type => 'integer', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | }, 'Admin::journal_read'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # list_dir, not glob: glob splits a root containing spaces into words. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 60 | my $dir = $self->journal_dir($args->{repo}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 60 | ▶ | my @files = map { File::Spec->catfile($dir, $_) } grep { $_ =~ $JOURNAL_FILE } @{ list_dir($dir) || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
list_dir($dir) || []
MC/DC0%0/1
list_dir($dir) || []
list_dir($dir)
Truth table50%1/2
A
A= list_dir($dir)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 60 | my $keep = $self->_event_filter($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 59 | ▶ | my @events = sort { ($a->{ts} || 0) <=> ($b->{ts} || 0) } grep { $keep->($_) } map { @{ _read_events($_) } } @files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$App::FileSync::Admin::a->{'ts'} || 0
$App::FileSync::Admin::b->{'ts'} || 0
MC/DC0%0/1
$App::FileSync::Admin::a->{'ts'} || 0
$App::FileSync::Admin::a->{'ts'}
MC/DC0%0/1
$App::FileSync::Admin::b->{'ts'} || 0
$App::FileSync::Admin::b->{'ts'}
Truth table50%1/2
A
A= $App::FileSync::Admin::a->{'ts'}
Truth table50%1/2
A
A= $App::FileSync::Admin::b->{'ts'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 59 | my $limit = $args->{limit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 59 | ▶ | splice(@events, 0, @events - $limit) if defined $limit && $limit > 0 && @events > $limit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $limit and $limit > 0 and @events > $limit
defined $limit and $limit > 0
MC/DC66%2/3
defined $limit and $limit > 0 and @events > $limit
defined $limit
$limit > 0
@events > $limit
Truth table75%3/4
A and B and C
A= defined $limitB= $limit > 0C= @events > $limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 59 | return \@events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | =head2 verify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | Purpose: rehash the master against its index and report what no longer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | agrees. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | Args: C<repo>, optional C<deep> (hash every file) and C<sample> (hash N | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | random files). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | Returns: the L<App::FileSync::Verify> report, plus C<repo> and C<master>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | Side Effects: reads the master tree; logs a debug summary. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | my $report = $admin->verify(repo => 'docs', deep => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | my $report = $admin->verify(repo => 'docs', sample => 20); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | print $report->{ok} ? "clean\n" : "drift\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | repo => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | deep => { type => 'boolean', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | sample => { type => 'integer', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | { type => 'hashref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | config.no_repo the repo does not exist check the name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | verify.* see App::FileSync::Verify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | verify(r) = Verify(master_dir(r), index(r), ignore(r)) ⊕ ⟨repo ↦ r, master ↦ master_dir(r)⟩ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 15 | ▶ | sub verify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 15 | my $args = named(\@_, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | %REPO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | deep => { type => 'scalar', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | sample => { type => 'integer', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | }, 'Admin::verify'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 15 | my $repo = $args->{repo}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 15 | my $store = $self->_store($repo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | my $report = App::FileSync::Verify::verify( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | root => $store->master_dir(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | entries => $store->load_index(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | ignore => App::FileSync::Ignore->new(patterns => $store->config->{ignore}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | deep => $args->{deep}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | sample => $args->{sample}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 15 | @{$report}{qw(repo master)} = ($repo, $store->master_dir()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | $self->{logger}->debug('verify finished', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | repo => $repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | files => $report->{files}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 45 | ▶ | (map { $_ => scalar @{ $report->{$_} } } qw(modified missing extra)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 15 | ok => $report->{ok} ? 1 : 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 15 | return $report; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | =head2 reindex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | Purpose: rebuild F<master.json> from the tree, hashing every file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | Used after a manual repair (a rollback from a backup, say) so the index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | describes the restored master without waiting for the next client session. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | The old index is deliberately not reused: a restored file can keep its size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | and mtime while its content differs, which is exactly the case reindex exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | Args: C<repo>, optional C<dry_run>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | Returns: C<{ repo, master, index, files, dirs, bytes, skipped, dry_run, written }>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | Side Effects: holds the repo lock (the same one the server takes), so it never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | races a session; writes the index and a journal event unless C<dry_run>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | my $result = $admin->reindex(repo => 'docs'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | my $plan = $admin->reindex(repo => 'docs', dry_run => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | print "would index $plan->{files} files\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | repo => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | dry_run => { type => 'boolean', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | { type => 'hashref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | admin.locked a sync session holds the repo lock retry when it has finished | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | config.no_repo the repo does not exist check the name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | ΔFS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | pre lock(r) is free | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | ¬dry_run ⇒ index'(r) = scan(master_dir(r)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | =head3 PSEUDOCODE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | open the repo and take its lock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | walk the master, hashing everything | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | unless dry run: save the index and journal the reindex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | log and report the counts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 7 | ▶ | sub reindex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reindex: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 7 | my $args = named(\@_, { %REPO, dry_run => { type => 'scalar', optional => 1 } }, 'Admin::reindex'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 7 | my $repo = $args->{repo}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 7 | my $store = $self->_store($repo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 7 | ▶ | my $dry_run = $args->{dry_run} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # Held until $lock goes out of scope at the end of this method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 7 | ▶ | my $lock = $store->acquire_lock() or $self->_throw('admin.locked', { repo => $repo }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 6 | my ($manifest, $stats, $skipped) = @{ $store->walk_master({}) }{qw(manifest stats skipped)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 6 | my %counts = (map { $_ => $stats->{$_} } qw(files dirs bytes)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 6 | ▶ | unless ($dry_run) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 4 | $store->save_index($manifest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 4 | $store->journal({ action => 'reindex', %counts, skipped => scalar(keys %{$skipped}), result => 'ok' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | $self->{logger}->info('reindexed master', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 6 | repo => $repo, %counts, skipped => scalar(keys %{$skipped}), dry_run => $dry_run, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 6 | ▶ | repo => $repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | master => $store->master_dir(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | index => $store->index_path(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | %counts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | skipped => $skipped, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | dry_run => $dry_run, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | written => $dry_run ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | =head2 restore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | Purpose: put a path back from the server trash: into the master by default, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | or into C<to> as an export. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | Args: C<repo>, C<path> (the relative path as synced), optional C<to> (a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | directory), C<date> (C<YYYY-MM-DD>; the newest version from that day), C<list> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | (only list the versions). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | Returns: with C<list>, C<{ repo, path, versions }> (rows from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | L<App::FileSync::Trash/version_info>); otherwise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | C<{ repo, path, from, to, date, sha256, into_master }>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | Side Effects: copies the version out (the trash entry is kept, so this is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | repeatable); when restoring into the master, rebuilds the index so verify and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | the next sync agree; journals the restore. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | $admin->restore(repo => 'docs', path => 'notes/a.txt'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | my $done = $admin->restore(repo => 'docs', path => 'a.txt', to => '/tmp/out', date => '2026-10-20'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | print "restored to $done->{to}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | repo => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | path => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | to => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | date => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | list => { type => 'boolean', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | { type => 'hashref' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | Key Meaning Resolution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | admin.unsafe_path the path fails validate_relpath fix the path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | admin.no_versions nothing of that path is in the trash check "restore --list" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | admin.bad_date the date is not YYYY-MM-DD fix it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | admin.no_version_on no version from that day pick a listed date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | admin.not_dir the export target is not a directory choose another | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | admin.exists the destination exists move it aside first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | ΔFS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | pre path ∈ SafePath ∧ versions(path) ≠ ⟨⟩ ∧ dest ∉ dom FS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | post tree'(dest) = tree(chosen) ∧ (into_master ⇒ index' = scan(master)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | =head3 PSEUDOCODE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | validate the path and list its trashed versions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | if listing, return them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | choose the newest version, or the newest from the given day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | destination: the master, or the export directory (created if needed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | refuse to overwrite; copy the version out | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | if into the master, rebuild the index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | journal, log and report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 12 | ▶ | sub restore { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restore: called CC=13 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 12 | my $args = named(\@_, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | %REPO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | path => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | to => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | date => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | list => { type => 'scalar', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | }, 'Admin::restore'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 12 | my ($repo, $path) = @{$args}{qw(repo path)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 12 | my ($safe, $reason) = validate_relpath($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 12 | ▶ | $self->_throw('admin.unsafe_path', { path => $path // '', reason => $reason }) unless $safe; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$path // ""
MC/DC0%0/1
$path // ""
$path
Truth table0%0/2
A
A= $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 12 | my $store = $self->_store($repo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 12 | my $versions = App::FileSync::Trash::versions(root => $store->trash_dir(), rel => $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 12 | ▶ | if ($args->{list}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 3 | return { repo => $repo, path => $path, versions => [ map { App::FileSync::Trash::version_info($_) } @{$versions} ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 9 | my $chosen = $self->_choose_version($versions, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 5 | ▶ | my $into_master = !(defined $args->{to} && length $args->{to}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $args->{'to'} && length $args->{'to'}
MC/DC50%1/2
defined $args->{'to'} && length $args->{'to'}
defined $args->{'to'}
length $args->{'to'}
Truth table66%2/3
A && B
A= defined $args->{'to'}B= length $args->{'to'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 5 | ▶ | my $base = $into_master ? $store->master_dir() : $args->{to}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 5 | ▶ | unless ($into_master) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 3 | ensure_dir($base); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 3 | ▶ | $self->_throw('admin.not_dir', { path => $base }) unless -d $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 5 | my $destination = File::Spec->catfile($base, split m{/}, $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 5 | ▶ | $self->_throw('admin.exists', { path => $destination }) if -e $destination || -l $destination; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e $destination or -l $destination
MC/DC50%1/2
-e $destination or -l $destination
-e $destination
-l $destination
Truth table66%2/3
A or B
A= -e $destinationB= -l $destination
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 4 | App::FileSync::Trash::restore(src => $chosen, to => $destination); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 4 | my $sha = sha256_file($destination); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | # The index is a cache; rebuild it so verify and the next sync agree that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | # the restored tree is what the master now holds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 4 | ▶ | $store->save_index($store->walk_master($store->load_index())->{manifest}) if $into_master; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 4 | ▶ | my %moved = (path => $path, to => $destination, (defined $sha ? (sha256 => $sha) : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 4 | $store->journal({ action => 'restore', %moved, trash => $chosen, result => 'ok' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 4 | $self->{logger}->info('restored path', { repo => $repo, path => $path, from => $chosen, to => $destination }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 4 | ▶ | repo => $repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | %moved, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | from => $chosen, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | date => App::FileSync::Trash::date_of($chosen), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | into_master => $into_master ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | # _unwritable_base | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | # Purpose: find the nearest existing directory above a path that this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | # account cannot write. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | # Entry: $path is the file or directory about to be created. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | # Exit: returns that directory, or undef when every existing one is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | # writable (so creation should succeed). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | # Side effects: none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 2 | ▶ | sub _unwritable_base :Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unwritable_base: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 2 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 2 | my $base = $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 2 | ▶ | $base = dirname($base) while !-d $base && dirname($base) ne $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not -d $base and dirname($base) ne $base
MC/DC50%1/2
not -d $base and dirname($base) ne $base
not -d $base
dirname($base) ne $base
Truth table66%2/3
not(A) and B
A= not -d $baseB= dirname($base) ne $base
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 2 | ▶ | return (-d $base && !-w $base) ? $base : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $base and not -w $base
MC/DC0%0/2
-d $base and not -w $base
-d $base
not -w $base
Truth table33%1/3
A and not(B)
A= -d $baseB= not -w $base
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 327 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | # _store | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | # Purpose: open a repo after checking its name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | # Entry: $repo is the caller's name; $config optional (saves a read). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | # Exit: returns an App::FileSync::Store. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # Side effects: reads the repo config unless given; raises admin.bad_repo or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | # config.no_repo. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 206 | ▶ | sub _store :Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_store: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 206 | my ($self, $repo, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | return App::FileSync::Store->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | root => $self->{root}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | repo => $self->_valid_repo($repo), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | language => $self->{language}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 206 | ▶ | ($config ? (config => $config) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 327 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | # _valid_repo / _valid_client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | # Purpose: check an id with the shared validators (which also cap the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | # length), so admin, server and transport agree on what an id is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | # Entry: the candidate, possibly undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | # Exit: returns the id. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | # Side effects: raises admin.bad_repo / admin.bad_client. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 367 | ▶ | sub _valid_repo :Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_repo: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 367 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 367 | my ($ok, $reason) = validate_repo_name($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 367 | ▶ | $self->_throw('admin.bad_repo', { reason => $reason }) unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 367 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 327 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 80 | ▶ | sub _valid_client :Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_client: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 80 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 80 | my ($ok, $reason) = validate_client_id($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 80 | ▶ | $self->_throw('admin.bad_client', { reason => $reason }) unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 79 | return $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 327 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | # _event_filter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | # Purpose: turn journal_read's options into one predicate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | # Entry: $args validated by journal_read. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | # Exit: returns a coderef taking an event, true to keep it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | # Side effects: raises when.bad for a malformed since/until (before any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | # file is read, since the bounds are parsed here). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 60 | ▶ | sub _event_filter :Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_event_filter: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 60 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 60 | ▶ | my $client = (defined $args->{client} && length $args->{client}) ? $args->{client} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $args->{"client"} and length $args->{"client"}
MC/DC50%1/2
defined $args->{"client"} and length $args->{"client"}
defined $args->{"client"}
length $args->{"client"}
Truth table66%2/3
A and B
A= defined $args->{"client"}B= length $args->{"client"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 60 | ▶ | my $since = defined $args->{since} ? parse_since($args->{since}) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 59 | ▶ | my $until = defined $args->{until} ? parse_until($args->{until}) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | # Only session outcomes record an exit code, so this selects those. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 59 | ▶ | my %exits = map { ($_ + 0) => 1 } @{ $args->{exits} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'exits'} || []
MC/DC100%1/1
$args->{'exits'} || []
$args->{'exits'}
Truth table100%2/2
A
A= $args->{'exits'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | # The server journals planned conflicts on the plan event too, but only a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | # session outcome shows a run that kept the conflict copies, which is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | # client's --warnings case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 59 | my $warnings = $args->{warnings}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 727 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 727 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 727 | ▶ | my $ts = $event->{ts} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$event->{'ts'} || 0
MC/DC0%0/1
$event->{'ts'} || 0
$event->{'ts'}
Truth table50%1/2
A
A= $event->{'ts'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 727 | ▶ | return 0 if defined $client && !(defined $event->{client} && $event->{client} eq $client); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $client and not defined $event->{"client"} && $event->{"client"} eq $client
defined $event->{'client'} && $event->{'client'} eq $client
MC/DC66%2/3
defined $client and not defined $event->{"client"} && $event->{"client"} eq $client
defined $client
defined $event->{'client'}
$event->{'client'} eq $client
Truth table75%3/4
A and not(B && C)
A= defined $clientB= defined $event->{'client'}C= $event->{'client'} eq $client
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 685 | ▶ | return 0 if (defined $since && $ts < $since) || (defined $until && $ts > $until); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
defined $since and $ts < $since or defined $until and $ts > $until
defined $since and $ts < $since
defined $until and $ts > $until
MC/DC100%4/4
defined $since and $ts < $since or defined $until and $ts > $until
defined $since
$ts < $since
defined $until
$ts > $until
Truth table71%5/7
A and B or C and D
A= defined $sinceB= $ts < $sinceC= defined $untilD= $ts > $until
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 629 | ▶ | return 0 if %exits && !(defined $event->{exit} && $exits{ $event->{exit} + 0 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
%exits and not defined $event->{"exit"} && $exits{$event->{"exit"} + 0}
defined $event->{'exit'} && $exits{$event->{'exit'} + 0}
MC/DC100%3/3
%exits and not defined $event->{"exit"} && $exits{$event->{"exit"} + 0}
%exits
defined $event->{'exit'}
$exits{$event->{'exit'} + 0}
Truth table100%4/4
A and not(B && C)
A= %exitsB= defined $event->{'exit'}C= $exits{$event->{'exit'} + 0}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 436 | ▶ | return 0 if $warnings && !(($event->{action} || '') eq 'session' && ($event->{conflicts} || 0) > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition90%9/10
$warnings and not +($event->{"action"} || "") eq "session" && ($event->{"conflicts"} || 0) > 0
($event->{'action'} || '') eq 'session' && ($event->{'conflicts'} || 0) > 0
$event->{'action'} || ''
$event->{'conflicts'} || 0
MC/DC66%2/3
$warnings and not +($event->{"action"} || "") eq "session" && ($event->{"conflicts"} || 0) > 0
$warnings
$event->{'action'}
$event->{'conflicts'}
Truth table75%3/4
A and not(B && C)
A= $warningsB= $event->{'action'}C= $event->{'conflicts'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 360 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 59 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 327 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | # _read_events | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | # Purpose: parse one journal file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | # Entry: $file exists. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | # Exit: returns an arrayref of event hashrefs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | # Side effects: reads the file; raises io.read if it cannot be opened. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | # Lines that are not JSON objects (a torn final line from a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | # killed run) are skipped, not fatal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 58 | ▶ | sub _read_events :Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_events: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 58 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 58 | my $fh = open_file($file, '<'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 58 | ▶ | my @events = grep { ref($_) eq 'HASH' } map { chomp; length ? eval { json_decode($_) } : () } <$fh>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 58 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 58 | return \@events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 327 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | # _choose_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | # Purpose: pick the trashed version restore should use. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | # Entry: $versions newest first; $args has path, repo and maybe date. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | # Exit: returns a version path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | # Side effects: raises admin.no_versions, admin.bad_date or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | # admin.no_version_on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 9 | ▶ | sub _choose_version :Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_choose_version: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 9 | my ($self, $versions, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 9 | my ($repo, $path, $date) = @{$args}{qw(repo path date)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 9 | ▶ | $self->_throw('admin.no_versions', { path => $path, repo => $repo }) unless @{$versions}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 8 | ▶ | return $versions->[0] unless defined $date && length $date; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $date and length $date
MC/DC50%1/2
defined $date and length $date
defined $date
length $date
Truth table66%2/3
A and B
A= defined $dateB= length $date
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 4 | ▶ | $self->_throw('admin.bad_date', { date => $date }) unless $date =~ $DATE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | # date_of is undef for a path outside the dated layout; such a version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | # never matches a date. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 3 | ▶ | my ($match) = grep { (App::FileSync::Trash::date_of($_) // '') eq $date } @{$versions}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
App::FileSync::Trash::date_of($_) // ""
MC/DC0%0/1
App::FileSync::Trash::date_of($_) // ""
App::FileSync::Trash::date_of($_)
Truth table50%1/2
A
A= App::FileSync::Trash::date_of($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 3 | ▶ | $self->_throw('admin.no_version_on', { path => $path, date => $date }) unless defined $match; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 1 | return $match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 327 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 327 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||