line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Rsnapshot::CheckGNUcp; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25072
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT_OK); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
99
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.0'; |
11
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
@EXPORT_OK = qw(isgnucp); |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
304360
|
use File::Temp qw(tempdir); |
|
1
|
|
|
|
|
32902
|
|
|
1
|
|
|
|
|
226
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
App::Rsnapshot::CheckGNUcp - check that a binary is GNU cp |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $isgnucp = App::Rsnapshot::CheckGNUcp::isgnucp($binary); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Provides a function to attempt to figure out whether a given binary is GNU |
27
|
|
|
|
|
|
|
cp or not. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 FUNCTIONS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 isgnucp |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This function will be exported if you ask for it thus: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use App::Rsnapshot::CheckGNUcp qw(isgnucp); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Takes a filename (with path) and returns true if it is GNU cp, false |
38
|
|
|
|
|
|
|
otherwise. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub isgnucp { |
43
|
1
|
|
|
1
|
1
|
329
|
my $binary = shift; |
44
|
1
|
|
|
|
|
10
|
my $dir = tempdir(); |
45
|
1
|
50
|
|
|
|
168265
|
open(TEMPFILE, '>', "$dir/foo") || |
46
|
|
|
|
|
|
|
die("Can't create $dir/foo to test whether $binary supports -al\n"); |
47
|
1
|
|
|
|
|
22
|
print TEMPFILE "Testing"; |
48
|
1
|
|
|
|
|
52
|
close(TEMPFILE); |
49
|
|
|
|
|
|
|
# open(my $REALSTDERR, ">&STDERR") || die("Can't dup STDERR\n"); |
50
|
|
|
|
|
|
|
# close(STDERR); |
51
|
|
|
|
|
|
|
# system($binary, '-al', "$dir/foo", "$dir/bar"); |
52
|
1
|
|
|
|
|
43004
|
system(qq{$binary -al "$dir/foo" "$dir/bar" 2>/dev/null}); |
53
|
|
|
|
|
|
|
# open(STDERR, '>&', $REALSTDERR) || die("Can't dup saved STDERR\n"); |
54
|
1
|
|
|
|
|
28
|
my $rval = 0; |
55
|
1
|
50
|
33
|
|
|
158
|
if(-e "$dir/bar" && ((stat("$dir/foo"))[1] == (stat("$dir/bar"))[1])) { # same inode |
56
|
1
|
|
|
|
|
6
|
$rval = 1; |
57
|
|
|
|
|
|
|
} |
58
|
1
|
|
|
|
|
202
|
unlink "$dir/foo", "$dir/bar"; |
59
|
1
|
|
|
|
|
157
|
rmdir $dir; |
60
|
1
|
|
|
|
|
34
|
return $rval; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 BUGS/WARNINGS/LIMITATIONS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This is a heuristic. That means that it can be wrong. Bug reports are |
66
|
|
|
|
|
|
|
most welcome, and should include the output from 'cp --version' as well |
67
|
|
|
|
|
|
|
as, of course, telling me what the bug is. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The check is actually whether 'cp -al blah/foo blah/bar' results in two |
70
|
|
|
|
|
|
|
files with the same inode number. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SOURCE CODE REPOSITORY |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR, COPYRIGHT and LICENCE |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Copyright 2009 David Cantrell |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This software is free-as-in-speech software, and may be used, |
81
|
|
|
|
|
|
|
distributed, and modified under the terms of either the GNU |
82
|
|
|
|
|
|
|
General Public Licence version 2 or the Artistic Licence. It's |
83
|
|
|
|
|
|
|
up to you which one you use. The full text of the licences can |
84
|
|
|
|
|
|
|
be found in the files GPL2.txt and ARTISTIC.txt, respectively. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 CONSPIRACY |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This module is also free-as-in-mason software. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |