File Coverage

File:blib/lib/App/FileSync/Constants.pm
Coverage:100.0%

linestmtbrancondsubtimecode
1package App::FileSync::Constants;
2
3# Every fixed number and reserved name the distribution shares.  Tunables that
4# tests adjust with "local" (chunk sizes, the run-log limit, the delta
5# thresholds) stay as package variables in their own modules instead.
6
7
327
327
327
771
322
4445
use strict;
8
327
327
327
491
230
6583
use warnings;
9
10
327
327
327
552
218
3398
use Exporter qw(import);
11
327
327
327
526
243
6693
use Readonly;
12
13
327
327
327
740
315
1069
use version; our $VERSION = version->declare('0.001.1');
14
15# Exit codes: the contract with cron, the Task Scheduler and "--exit N".
16Readonly our $EXIT_OK       => 0;
17Readonly our $EXIT_FATAL    => 1;
18Readonly our $EXIT_LOCKED   => 2;
19Readonly our $EXIT_WARNINGS => 3;
20Readonly our $EXIT_DRIFT    => 4;
21
22# Highest exit status a process can report; "--exit N" is checked against it.
23Readonly our $EXIT_MAX => 255;
24
25# Wire protocol version spoken by this release; client and server must agree.
26Readonly our $PROTOCOL_VERSION => 2;
27
28# Where the server tree lives when neither --root nor FILESYNC_ROOT says.
29Readonly our $DEFAULT_SERVER_ROOT => '/srv/filesync';
30
31# The program sshd runs as the forced command.
32Readonly our $SERVER_PROGRAM => 'filesync-server';
33
34# Session roles.  A replica only ever pulls.
35Readonly our $ROLE_CLIENT  => 'client';
36Readonly our $ROLE_REPLICA => 'replica';
37Readonly our @ROLES        => ($ROLE_CLIENT, $ROLE_REPLICA);
38
39# Manifest entry types.
40Readonly our $TYPE_FILE => 'f';
41Readonly our $TYPE_DIR  => 'd';
42
43# Permission bits worth carrying between machines, and the mode a file gets
44# when the peer did not send one.
45Readonly our $MODE_MASK         => oct('7777');
46Readonly our $DEFAULT_FILE_MODE => oct('644');
47
48# Reserved names inside a sync root or the master.
49Readonly our $ROOT_MARKER  => '.filesync-root';
50Readonly our $TEMP_PREFIX  => '.filesync-tmp-';
51Readonly our $SNAPSHOT_DIR => '.filesync-snapshots';
52
53# Temporaries older than this are from a run that died; younger ones may
54# belong to a run in progress.
55Readonly our $STALE_TEMP_SECONDS => 3600;
56
57# Largest single data frame either side accepts for an upload chunk.
58Readonly our $MAX_CHUNK_BYTES => 8 * 1024 * 1024;
59
60# Repo policy defaults, also used when a stored config omits a key.
61Readonly our $TRASH_DAYS         => 30;
62Readonly our $MAX_DELETES        => 200;
63Readonly our $MAX_DELETE_PERCENT => 10;
64
65# Replica snapshots kept by "filesync snapshot" when nothing says otherwise.
66Readonly our $SNAPSHOT_KEEP => 14;
67
68# Calendar arithmetic.
69Readonly our $SECONDS_PER_DAY => 86_400;
70
71# Repo and client ids become directory names, so they are short.
72Readonly our $MAX_ID_LENGTH => 64;
73
74# A SHA-256 digest as it appears on the wire and in the index.
75Readonly our $SHA256_HEX => qr/\A[0-9a-f]{64}\z/;
76
77# Two clocks are treated as agreeing within this many seconds (FAT stores
78# mtimes in 2-second units).
79Readonly our $MTIME_TOLERANCE => 2;
80
81our @EXPORT_OK = qw(
82        $EXIT_OK $EXIT_FATAL $EXIT_LOCKED $EXIT_WARNINGS $EXIT_DRIFT $EXIT_MAX
83        $PROTOCOL_VERSION $DEFAULT_SERVER_ROOT $SERVER_PROGRAM
84        $ROLE_CLIENT $ROLE_REPLICA @ROLES
85        $TYPE_FILE $TYPE_DIR
86        $MODE_MASK $DEFAULT_FILE_MODE
87        $ROOT_MARKER $TEMP_PREFIX $SNAPSHOT_DIR $STALE_TEMP_SECONDS
88        $MAX_CHUNK_BYTES
89        $TRASH_DAYS $MAX_DELETES $MAX_DELETE_PERCENT $SNAPSHOT_KEEP
90        $SECONDS_PER_DAY $MAX_ID_LENGTH $SHA256_HEX $MTIME_TOLERANCE
91);
92
93our %EXPORT_TAGS = (all => \@EXPORT_OK);
94
951;
96