From bc977b3ecc0703083930b63f3cf8780ef4f4efe3 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Mon, 23 Oct 2017 19:29:13 +0000 Subject: [PATCH] Bug 19512: Make pass koha qa test tools Can't seem to get the pod coverage correct for one file. This fixes the others. Signed-off-by: Mark Tompsett --- Koha/Exceptions/File.pm | 52 +++++++++++++++++++++++++++++++++++++++++++----- Koha/File.pm | 11 +++++++++- t/Koha/Exceptions/File.t | 2 +- t/Koha/File.t | 2 +- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/Koha/Exceptions/File.pm b/Koha/Exceptions/File.pm index 8353e04..5f3a6a6 100644 --- a/Koha/Exceptions/File.pm +++ b/Koha/Exceptions/File.pm @@ -1,3 +1,20 @@ +# This file is part of Koha. +# +# Copyright (C) YEAR YOURNAME-OR-YOUREMPLOYER +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + package Koha::Exceptions::File; use Modern::Perl; @@ -11,17 +28,41 @@ use Koha::Exceptions; use Exception::Class ( 'Koha::Exceptions::File' => { - isa => 'Koha::Exceptions::Exception', - description => 'Problem with a file', - fields => ['path', 'stat'], + 'isa' => 'Koha::Exceptions::Exception', + 'description' => 'Problem with a file', + 'fields' => ['path', 'stat'], }, ); -=head2 throw -@OVERLOADS +=head1 NAME + +Koha::Exceptions::File + +=head1 SYNOPSIS Adds diagnostic information regarding the file with issues +=head1 AUTHOR + +Olli-Antti Kivilahti + +=head1 LICENSE + +GPL v3 + +=head1 DESCRIPTION + +This file defines exceptions for Koha based on system files. +It does this by overloading the throw method with diagnostic +information. + +=head1 SUBROUTINES/METHODS + +=head2 throw + +my $file_exception = Koha::Exceptions::File->new(); +$file_exception->throw(%args); + =cut sub throw { @@ -46,6 +87,7 @@ sub throw { $args{error} .= '. '.$stat; $self->SUPER::throw(%args); + return; } 1; diff --git a/Koha/File.pm b/Koha/File.pm index 87e0cb8..a26d481 100644 --- a/Koha/File.pm +++ b/Koha/File.pm @@ -20,6 +20,8 @@ $filetypes[Fcntl::S_IFIFO] = "p"; $filetypes[Fcntl::S_IFLNK] = "l"; $filetypes[Fcntl::S_IFSOCK] = "s"; +=head1 EXPORTED FUNCTIONS + =head2 getDiagnostics @PARAM1 String, path to a file @@ -33,7 +35,7 @@ $filetypes[Fcntl::S_IFSOCK] = "s"; sub getDiagnostics { my ($path) = @_; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat($path); - return undef unless $dev; #No such file + return unless $dev; #No such file my %rv; $rv{user} = getpwuid($uid); @@ -45,6 +47,13 @@ sub getDiagnostics { } our $diagnosticsStringFormat = '%s %s %s:%s'; + +=head2 getDiagnosticsString + +@PARAM1 String, path to a file + +=cut + sub getDiagnosticsString { my $stat = getDiagnostics(@_); return sprintf($diagnosticsStringFormat, $stat->{filetype}, $stat->{permissions}, $stat->{user}, $stat->{group}); diff --git a/t/Koha/Exceptions/File.t b/t/Koha/Exceptions/File.t index 79e99b5..c23ec54 100644 --- a/t/Koha/Exceptions/File.t +++ b/t/Koha/Exceptions/File.t @@ -6,7 +6,7 @@ use File::Basename; use Koha::Exceptions::File; -#file diagnostics are more throughly tested in t/Koha/File.t +#file diagnostics are more thoroughly tested in t/Koha/File.t subtest "Catch File-exception and inspect diagnostics", \&getDiagnostics; sub getDiagnostics { my $koha_path= $ENV{KOHA_PATH} // q{.}; diff --git a/t/Koha/File.t b/t/Koha/File.t index 76e03a2..abe8f3d 100644 --- a/t/Koha/File.t +++ b/t/Koha/File.t @@ -18,7 +18,7 @@ sub _testDiagnostics { my ($filepath, $expectedFiletype) = @_; my @expected = ( $expectedFiletype, - sprintf("%04o", ((lstat($filepath))[2] & 07777)), #$expectedPermissions, + sprintf("%04o", ((lstat($filepath))[2] & 0xFFF)), #$expectedPermissions, scalar(getpwuid((lstat($filepath))[4])), #$expectedUser, scalar(getgrgid((lstat($filepath))[5])), #$expectedGroup, ); -- 2.1.4