View | Details | Raw Unified | Return to bug 19512
Collapse All | Expand All

(-)a/Koha/Exceptions/File.pm (-5 / +47 lines)
Lines 1-3 Link Here
1
# This file is part of Koha.
2
#
3
# Copyright (C) YEAR  YOURNAME-OR-YOUREMPLOYER
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
1
package Koha::Exceptions::File;
18
package Koha::Exceptions::File;
2
19
3
use Modern::Perl;
20
use Modern::Perl;
Lines 11-27 use Koha::Exceptions; Link Here
11
use Exception::Class (
28
use Exception::Class (
12
29
13
    'Koha::Exceptions::File' => {
30
    'Koha::Exceptions::File' => {
14
        isa => 'Koha::Exceptions::Exception',
31
        'isa' => 'Koha::Exceptions::Exception',
15
        description => 'Problem with a file',
32
        'description' => 'Problem with a file',
16
        fields => ['path', 'stat'],
33
        'fields' => ['path', 'stat'],
17
    },
34
    },
18
);
35
);
19
36
20
=head2 throw
37
=head1 NAME
21
@OVERLOADS
38
39
Koha::Exceptions::File
40
41
=head1 SYNOPSIS
22
42
23
Adds diagnostic information regarding the file with issues
43
Adds diagnostic information regarding the file with issues
24
44
45
=head1 AUTHOR
46
47
Olli-Antti Kivilahti
48
49
=head1 LICENSE
50
51
GPL v3
52
53
=head1 DESCRIPTION
54
55
This file defines exceptions for Koha based on system files.
56
It does this by overloading the throw method with diagnostic
57
information.
58
59
=head1 SUBROUTINES/METHODS
60
61
=head2 throw
62
63
my $file_exception = Koha::Exceptions::File->new();
64
$file_exception->throw(%args);
65
25
=cut
66
=cut
26
67
27
sub throw {
68
sub throw {
Lines 46-51 sub throw { Link Here
46
87
47
    $args{error} .= '. '.$stat;
88
    $args{error} .= '. '.$stat;
48
    $self->SUPER::throw(%args);
89
    $self->SUPER::throw(%args);
90
    return;
49
}
91
}
50
92
51
1;
93
1;
(-)a/Koha/File.pm (-1 / +10 lines)
Lines 20-25 $filetypes[Fcntl::S_IFIFO] = "p"; Link Here
20
$filetypes[Fcntl::S_IFLNK] = "l";
20
$filetypes[Fcntl::S_IFLNK] = "l";
21
$filetypes[Fcntl::S_IFSOCK] = "s";
21
$filetypes[Fcntl::S_IFSOCK] = "s";
22
22
23
=head1 EXPORTED FUNCTIONS
24
23
=head2 getDiagnostics
25
=head2 getDiagnostics
24
26
25
@PARAM1 String, path to a file
27
@PARAM1 String, path to a file
Lines 33-39 $filetypes[Fcntl::S_IFSOCK] = "s"; Link Here
33
sub getDiagnostics {
35
sub getDiagnostics {
34
    my ($path) = @_;
36
    my ($path) = @_;
35
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat($path);
37
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat($path);
36
    return undef unless $dev; #No such file
38
    return unless $dev; #No such file
37
39
38
    my %rv;
40
    my %rv;
39
    $rv{user} =        getpwuid($uid);
41
    $rv{user} =        getpwuid($uid);
Lines 45-50 sub getDiagnostics { Link Here
45
}
47
}
46
48
47
our $diagnosticsStringFormat = '%s %s %s:%s';
49
our $diagnosticsStringFormat = '%s %s %s:%s';
50
51
=head2 getDiagnosticsString
52
53
@PARAM1 String, path to a file
54
55
=cut
56
48
sub getDiagnosticsString {
57
sub getDiagnosticsString {
49
    my $stat = getDiagnostics(@_);
58
    my $stat = getDiagnostics(@_);
50
    return sprintf($diagnosticsStringFormat, $stat->{filetype}, $stat->{permissions}, $stat->{user}, $stat->{group});
59
    return sprintf($diagnosticsStringFormat, $stat->{filetype}, $stat->{permissions}, $stat->{user}, $stat->{group});
(-)a/t/Koha/Exceptions/File.t (-1 / +1 lines)
Lines 6-12 use File::Basename; Link Here
6
6
7
use Koha::Exceptions::File;
7
use Koha::Exceptions::File;
8
8
9
#file diagnostics are more throughly tested in t/Koha/File.t
9
#file diagnostics are more thoroughly tested in t/Koha/File.t
10
subtest "Catch File-exception and inspect diagnostics", \&getDiagnostics;
10
subtest "Catch File-exception and inspect diagnostics", \&getDiagnostics;
11
sub getDiagnostics {
11
sub getDiagnostics {
12
    my $koha_path= $ENV{KOHA_PATH} // q{.};
12
    my $koha_path= $ENV{KOHA_PATH} // q{.};
(-)a/t/Koha/File.t (-2 / +1 lines)
Lines 18-24 sub _testDiagnostics { Link Here
18
    my ($filepath, $expectedFiletype) = @_;
18
    my ($filepath, $expectedFiletype) = @_;
19
    my @expected = (
19
    my @expected = (
20
        $expectedFiletype,
20
        $expectedFiletype,
21
        sprintf("%04o", ((lstat($filepath))[2] & 07777)), #$expectedPermissions,
21
        sprintf("%04o", ((lstat($filepath))[2] & 0xFFF)), #$expectedPermissions,
22
        scalar(getpwuid((lstat($filepath))[4])),          #$expectedUser,
22
        scalar(getpwuid((lstat($filepath))[4])),          #$expectedUser,
23
        scalar(getgrgid((lstat($filepath))[5])),          #$expectedGroup,
23
        scalar(getgrgid((lstat($filepath))[5])),          #$expectedGroup,
24
    );
24
    );
25
- 

Return to bug 19512