line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Filename::Backup; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-10-19'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
436
|
use 5.010001; |
|
1
|
|
|
|
|
2
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
15
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
343
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(check_backup_filename); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %SPEC; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our %SUFFIXES = ( |
17
|
|
|
|
|
|
|
'~' => 1, |
18
|
|
|
|
|
|
|
'.bak' => 1, |
19
|
|
|
|
|
|
|
'.old' => 1, |
20
|
|
|
|
|
|
|
'.orig' => 1, # patch |
21
|
|
|
|
|
|
|
'.rej' => 1, # patch |
22
|
|
|
|
|
|
|
'.swp' => 1, |
23
|
|
|
|
|
|
|
# XXX % (from /etc/mime.types) |
24
|
|
|
|
|
|
|
# XXX sik? (from /etc/mime.types) |
25
|
|
|
|
|
|
|
# XXX .dpkg* |
26
|
|
|
|
|
|
|
# XXX .rpm* |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$SPEC{check_backup_filename} = { |
30
|
|
|
|
|
|
|
v => 1.1, |
31
|
|
|
|
|
|
|
summary => 'Check whether filename indicates being a backup file', |
32
|
|
|
|
|
|
|
description => <<'_', |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
_ |
36
|
|
|
|
|
|
|
args => { |
37
|
|
|
|
|
|
|
filename => { |
38
|
|
|
|
|
|
|
schema => 'str*', |
39
|
|
|
|
|
|
|
req => 1, |
40
|
|
|
|
|
|
|
pos => 0, |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
# XXX recurse? |
43
|
|
|
|
|
|
|
ci => { |
44
|
|
|
|
|
|
|
summary => 'Whether to match case-insensitively', |
45
|
|
|
|
|
|
|
schema => 'bool', |
46
|
|
|
|
|
|
|
default => 1, |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
result_naked => 1, |
50
|
|
|
|
|
|
|
result => { |
51
|
|
|
|
|
|
|
schema => ['any*', of=>['bool*', 'hash*']], |
52
|
|
|
|
|
|
|
description => <<'_', |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Return false if not detected as backup name. Otherwise return a hash, which may |
55
|
|
|
|
|
|
|
contain these keys: `original_filename`. In the future there will be extra |
56
|
|
|
|
|
|
|
information returned, e.g. editor name (if filename indicates backup from |
57
|
|
|
|
|
|
|
certain backup program), date (if filename contains date information), and so |
58
|
|
|
|
|
|
|
on. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
_ |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
sub check_backup_filename { |
64
|
10
|
|
|
10
|
1
|
29
|
my %args = @_; |
65
|
|
|
|
|
|
|
|
66
|
10
|
|
|
|
|
11
|
my $filename = $args{filename}; |
67
|
10
|
|
|
|
|
7
|
my $orig_filename; |
68
|
|
|
|
|
|
|
|
69
|
10
|
100
|
|
|
|
27
|
if ($filename =~ /\A#(.+)#\z/) { |
70
|
1
|
|
|
|
|
3
|
$orig_filename = $1; |
71
|
1
|
|
|
|
|
4
|
goto RETURN; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
9
|
50
|
|
|
|
47
|
$filename =~ /(~|\.\w+)\z/ or return 0; |
75
|
9
|
|
100
|
|
|
32
|
my $ci = $args{ci} // 1; |
76
|
|
|
|
|
|
|
|
77
|
9
|
|
|
|
|
12
|
my $suffix = $1; |
78
|
|
|
|
|
|
|
|
79
|
9
|
|
|
|
|
8
|
my $spec; |
80
|
9
|
100
|
|
|
|
11
|
if ($ci) { |
81
|
8
|
|
|
|
|
9
|
my $suffix_lc = lc($suffix); |
82
|
8
|
|
|
|
|
20
|
for (keys %SUFFIXES) { |
83
|
31
|
100
|
|
|
|
43
|
if (lc($_) eq $suffix_lc) { |
84
|
7
|
|
|
|
|
8
|
$spec = $SUFFIXES{$_}; |
85
|
7
|
|
|
|
|
7
|
last; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} else { |
89
|
1
|
|
|
|
|
2
|
$spec = $SUFFIXES{$suffix}; |
90
|
|
|
|
|
|
|
} |
91
|
9
|
100
|
|
|
|
22
|
return 0 unless $spec; |
92
|
|
|
|
|
|
|
|
93
|
7
|
|
|
|
|
81
|
($orig_filename = $filename) =~ s/\Q$suffix\E\z//; |
94
|
|
|
|
|
|
|
|
95
|
8
|
|
|
|
|
46
|
RETURN: |
96
|
|
|
|
|
|
|
return { |
97
|
|
|
|
|
|
|
original_filename => $orig_filename, |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
# ABSTRACT: Check whether filename indicates being a backup file |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |