added: Uploads locations and files are set to the same uid/gid that owns the uploads root
This commit is contained in:
parent
4a326b2b40
commit
da5877eb3d
2 changed files with 32 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
|||
- fixed: Thingy i18n has an empty message
|
||||
- fixed: Thingy has no icon
|
||||
- fixed: Wiki page history shows username instead of alias
|
||||
- added: Uploads locations and files are set to the same uid/gid that owns the uploads root
|
||||
|
||||
7.5.6
|
||||
- fixed: events get start/end time even when none specified (also can offset start/end day)
|
||||
|
|
|
|||
|
|
@ -116,7 +116,10 @@ sub _makePath {
|
|||
foreach my $folder ($self->{_part1}, $self->{_part2}, $self->getFileId) {
|
||||
$node .= '/'.$folder;
|
||||
unless (-e $node) { # check to see if it already exists
|
||||
unless (mkdir($node)) { # check to see if there was an error during creation
|
||||
if (mkdir($node)) { # check to see if there was an error during creation
|
||||
$self->_changeOwner($node);
|
||||
}
|
||||
else {
|
||||
$self->_addError("Couldn't create storage location: $node : $!");
|
||||
}
|
||||
}
|
||||
|
|
@ -125,6 +128,26 @@ sub _makePath {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _changeOwner ( )
|
||||
|
||||
Changes the owner to be the same as that of the uploads directory
|
||||
|
||||
NOTE: This is a private method and should never be called except internally to this package.
|
||||
|
||||
=cut
|
||||
|
||||
sub _changeOwner {
|
||||
my $self = shift;
|
||||
# Don't change owner if we're on windows or not the superuser
|
||||
return
|
||||
if ($^O eq 'MSWin32' || $> != 0);
|
||||
my $uploads = $self->session->config->get("uploadsPath");
|
||||
my ($uid, $gid) = (stat($uploads))[4,5];
|
||||
chown $uid, $gid, @_;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addFileFromFilesystem( pathToFile )
|
||||
|
||||
Grabs a file from the server's file system and saves it to a storage location and returns a URL compliant filename. If there are errors encountered during the add, then it will return undef instead.
|
||||
|
|
@ -161,6 +184,7 @@ sub addFileFromFilesystem {
|
|||
binmode($dest);
|
||||
cp($source,$dest) or $self->_addError("Couldn't copy $pathToFile to ".$self->getPath($filename).": $!");
|
||||
$dest->close;
|
||||
$self->_changeOwner($self->getPath($filename));
|
||||
} else {
|
||||
$self->_addError("Couldn't open file ".$self->getPath($filename)." for writing due to error: ".$!);
|
||||
$filename = undef;
|
||||
|
|
@ -228,6 +252,7 @@ sub addFileFromFormPost {
|
|||
print $file $buffer;
|
||||
}
|
||||
close($file);
|
||||
$self->_changeOwner($self->getPath($filename));
|
||||
$self->session->errorHandler->info("Got ".$upload->filename);
|
||||
} else {
|
||||
$self->_addError("Couldn't open file ".$self->getPath($filename)." for writing due to error: ".$!);
|
||||
|
|
@ -259,7 +284,8 @@ sub addFileFromHashref {
|
|||
my $self = shift;
|
||||
my $filename = $self->session->url->makeCompliant(shift);
|
||||
my $hashref = shift;
|
||||
nstore $hashref, $self->getPath($filename) or $self->_addError("Couldn't create file ".$self->getPath($filename)." because ".$!);
|
||||
nstore $hashref, $self->getPath($filename) or $self->_addError("Couldn't create file ".$self->getPath($filename)." because ".$!);
|
||||
$self->_changeOwner($self->getPath($filename));
|
||||
return $filename;
|
||||
}
|
||||
|
||||
|
|
@ -286,6 +312,7 @@ sub addFileFromScalar {
|
|||
if (open(my $FILE,">",$self->getPath($filename))) {
|
||||
print $FILE $content;
|
||||
close($FILE);
|
||||
$self->_changeOwner($self->getPath($filename));
|
||||
} else {
|
||||
$self->_addError("Couldn't create file ".$self->getPath($filename)." because ".$!);
|
||||
}
|
||||
|
|
@ -338,6 +365,7 @@ sub copy {
|
|||
binmode($dest);
|
||||
cp($source,$dest) or $self->_addError("Couldn't copy file ".$self->getPath($file)." to ".$newStorage->getPath($file)." because ".$!);
|
||||
$dest->close;
|
||||
$newStorage->_changeOwner($newStorage->getPath($file));
|
||||
}
|
||||
$source->close;
|
||||
}
|
||||
|
|
@ -366,6 +394,7 @@ sub copyFile {
|
|||
|
||||
cp( $self->getPath($filename), $self->getPath($newFilename) )
|
||||
|| croak "Couldn't copy '$filename' to '$newFilename': $!";
|
||||
$self->_changeOwner($self->getPath($filename));
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue