Skip to content

Commit

Permalink
Issue #1295: a more consistent set up of $Path
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed Oct 8, 2021
1 parent e27bd21 commit 8b8595a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
40 changes: 21 additions & 19 deletions Kernel/System/Ticket/Article/Backend/MIMEBase/ArticleStorageFS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ sub ArticleDeletePlain {
my $ContentPath = $Self->_ArticleContentPathGet(
ArticleID => $Param{ArticleID},
);
my $File = "$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}/plain.txt";
my $Path = join '/', $Self->{ArticleDataDir}, $ContentPath, $Param{ArticleID};
my $File = join '/', $Path, 'plain.txt';
if ( -f $File ) {
if ( !unlink $File ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Expand Down Expand Up @@ -206,7 +207,7 @@ sub ArticleDeleteAttachment {
my $ContentPath = $Self->_ArticleContentPathGet(
ArticleID => $Param{ArticleID},
);
my $Path = "$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}";
my $Path = join '/', $Self->{ArticleDataDir}, $ContentPath, $Param{ArticleID};

if ( -e $Path ) {

Expand Down Expand Up @@ -268,7 +269,7 @@ sub ArticleWritePlain {
my $ContentPath = $Self->_ArticleContentPathGet(
ArticleID => $Param{ArticleID},
);
my $Path = $Self->{ArticleDataDir} . '/' . $ContentPath . '/' . $Param{ArticleID};
my $Path = join '/', $Self->{ArticleDataDir}, $ContentPath, $Param{ArticleID};

# debug
if ( defined $Self->{Debug} && $Self->{Debug} > 1 ) {
Expand Down Expand Up @@ -325,9 +326,7 @@ sub ArticleWriteAttachment {
my $ContentPath = $Self->_ArticleContentPathGet(
ArticleID => $Param{ArticleID},
);

# define path
$Param{Path} = $Self->{ArticleDataDir} . '/' . $ContentPath . '/' . $Param{ArticleID};
my $Path = join '/', $Self->{ArticleDataDir}, $ContentPath, $Param{ArticleID};

# get main object
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
Expand Down Expand Up @@ -365,19 +364,19 @@ sub ArticleWriteAttachment {
$Param{Filename} = $NewFileName;

# write attachment to backend
if ( !-d $Param{Path} ) {
if ( !mkpath( [ $Param{Path} ], 0, 0770 ) ) { ## no critic qw(ValuesAndExpressions::ProhibitLeadingZeros)
if ( !-d $Path ) {
if ( !mkpath( [$Path], 0, 0770 ) ) { ## no critic qw(ValuesAndExpressions::ProhibitLeadingZeros)
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Can't create $Param{Path}: $!",
Message => "Can't create $Path: $!",
);
return;
}
}

# write attachment content type to fs
my $SuccessContentType = $MainObject->FileWrite(
Directory => $Param{Path},
Directory => $Path,
Filename => "$Param{Filename}.content_type",
Mode => 'binmode',
Content => \$Param{ContentType},
Expand All @@ -394,7 +393,7 @@ sub ArticleWriteAttachment {
# write attachment content id to fs
if ( $Param{ContentID} ) {
$MainObject->FileWrite(
Directory => $Param{Path},
Directory => $Path,
Filename => "$Param{Filename}.content_id",
Mode => 'binmode',
Content => \$Param{ContentID},
Expand All @@ -406,7 +405,7 @@ sub ArticleWriteAttachment {
# write attachment content alternative to fs
if ( $Param{ContentAlternative} ) {
$MainObject->FileWrite(
Directory => $Param{Path},
Directory => $Path,
Filename => "$Param{Filename}.content_alternative",
Mode => 'binmode',
Content => \$Param{ContentAlternative},
Expand All @@ -421,7 +420,7 @@ sub ArticleWriteAttachment {
my ( $Disposition, $FileName ) = split ';', $Param{Disposition};

$MainObject->FileWrite(
Directory => $Param{Path},
Directory => $Path,
Filename => "$Param{Filename}.disposition",
Mode => 'binmode',
Content => \$Disposition || '',
Expand All @@ -432,7 +431,7 @@ sub ArticleWriteAttachment {

# write attachment content to fs
my $SuccessContent = $MainObject->FileWrite(
Directory => $Param{Path},
Directory => $Path,
Filename => $Param{Filename},
Mode => 'binmode',
Content => \$Param{Content},
Expand Down Expand Up @@ -486,13 +485,14 @@ sub ArticlePlain {
my $ContentPath = $Self->_ArticleContentPathGet(
ArticleID => $Param{ArticleID},
);
my $Path = join '/', $Self->{ArticleDataDir}, $ContentPath, $Param{ArticleID};

# open plain article
if ( -f "$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}/plain.txt" ) {
if ( -f "$Path/plain.txt" ) {

# read whole article
my $Data = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
Directory => "$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}/",
Directory => $Path,
Filename => 'plain.txt',
Mode => 'binmode',
);
Expand Down Expand Up @@ -571,6 +571,7 @@ sub ArticleAttachmentIndexRaw {
my $ContentPath = $Self->_ArticleContentPathGet(
ArticleID => $Param{ArticleID},
);
my $Path = join '/', $Self->{ArticleDataDir}, $ContentPath, $Param{ArticleID};
my %Index;
my $Counter = 0;

Expand All @@ -579,7 +580,7 @@ sub ArticleAttachmentIndexRaw {

# try fs
my @List = $MainObject->DirectoryRead(
Directory => "$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}",
Directory => $Path,
Filter => "*",
Silent => 1,
);
Expand Down Expand Up @@ -763,15 +764,16 @@ sub ArticleAttachment {
my $ContentPath = $Self->_ArticleContentPathGet(
ArticleID => $Param{ArticleID},
);
my $Path = join '/', $Self->{ArticleDataDir}, $ContentPath, $Param{ArticleID};
my %Data = %{ $Index{ $Param{FileID} } // {} };
my $Counter = 0;

# get main object
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');

my @List = $MainObject->DirectoryRead(
Directory => "$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}",
Filter => "*",
Directory => $Path,
Filter => '*',
Silent => 1,
);

Expand Down
4 changes: 2 additions & 2 deletions Kernel/System/Ticket/Article/Backend/MIMEBase/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Generate a base article content path for article storage in the file system.
my $ArticleContentPath = $BackendObject->BuildArticleContentPath();
This is useful in file system based storage backends because there shouldn't be too many entries in a directory.
This is useful in file system based storage backends because there should not be too many entries in a directory.
A different content path, in the form YYYY/MM/DD is generated for every day.
=cut
Expand Down Expand Up @@ -283,7 +283,7 @@ sub _ArticleDeleteDirectory {
my $ContentPath = $Self->_ArticleContentPathGet(
ArticleID => $Param{ArticleID},
);
my $Path = "$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}";
my $Path = join '/', $Self->{ArticleDataDir}, $ContentPath, $Param{ArticleID};
if ( -d $Path ) {
if ( !rmdir $Path ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Expand Down

0 comments on commit 8b8595a

Please sign in to comment.