Fix for isParentWritable() processing

This commit is contained in:
Deon George 2024-10-04 11:08:18 +10:00
parent 40b9910d8d
commit 28fdd0fcab
4 changed files with 25 additions and 11 deletions

View File

@ -63,10 +63,10 @@ class CatalogDelete implements ShouldQueue
$this->o->people()->detach();
// Make sure our parent is writable
if (! $this->o->isParentWritable(dirname($this->o->file_name(FALSE)))) {
if (! $this->o->isParentWritable(dirname($this->o->file_name_rel(TRUE)))) {
Log::warning(sprintf('%s: NOT Deleting [%s] parent directory not writable',__METHOD__,$this->o->file_name(FALSE)));
exit;
$this->fail();
}
// Perform delete

View File

@ -47,7 +47,7 @@ abstract class Catalog extends Model
}
/**
* Return the prefix for the file path - dependant on the object
* Return the prefix for the file path - dependent on the object
*
* @return string
*/
@ -267,8 +267,11 @@ abstract class Catalog extends Model
/**
* Return the filename.
* If short is TRUE, it is the filename that it should be called (and can be compared to $this->filename)
* If short is FALSE, it is the true path of the actual file
*
* If $short is TRUE, it is the RELATIVE filename that it should be called (and can be compared to $this->filename,
* to see if it is in the wrong place). This path (like filename) is without the DIR prefix, and DIR location.
* If $short is FALSE, it is the FULL path of the actual file (where $this->filename is the RELATIVE path,
* without the DIR prefix, and DIR location)
*
* @param bool $short
* @return string
@ -293,6 +296,15 @@ abstract class Catalog extends Model
->path($this->file_name_rel());
}
/**
* Return the path relative to our HTML root
*
* When $source is TRUE, this is the current filename with the DIR prefix added, without the DIR location,
* When $source is FALSE, this is the NEW filename, with the DIR prefix added, without the DIR location.
*
* @param bool $source
* @return string
*/
public function file_name_rel(bool $source=TRUE): string
{
return config(static::config.'.dir').DIRECTORY_SEPARATOR.($source ? $this->filename : $this->file_name());
@ -396,13 +408,13 @@ abstract class Catalog extends Model
// Test if the dir is writable (so we can remove the file)
$this->move_reason = 'Source parent dir not writable';
if (! $this->isParentWritable(dirname($this->file_name(FALSE))))
if (! $this->isParentWritable(dirname($this->file_name_rel(TRUE))))
return FALSE;
// Test if the target dir is writable
// @todo The target dir may not exist yet, so we should check that a parent exists and is writable.
$this->move_reason = 'Target parent dir doesnt is not writable';
if (! $this->isParentWritable(dirname($this->file_name(TRUE))))
if (! $this->isParentWritable(dirname($this->file_name_rel(FALSE))))
return FALSE;
// Otherwise we can move it
@ -416,7 +428,9 @@ abstract class Catalog extends Model
}
/**
* Determine if the parent dir is writable
* Determine if the parent dir is writable.
*
* $dir should be a relative path, with our DIR prefix (from dirname($this->file_name_rel()))
*
* @param string $dir
* @return bool
@ -428,7 +442,7 @@ abstract class Catalog extends Model
if (Storage::disk(self::fs)->exists($dir) && is_dir($path) && is_writable($path))
return TRUE;
elseif ($path === dirname($path))
elseif ($dir === '.')
return FALSE;
else

View File

@ -1,7 +1,7 @@
<?php
return [
'dir'=>'Photos',
'dir'=>'Photos', // Directory PREFIX
'import'=>[
'accepted'=>['jpg','jpeg','heic'],
],

View File

@ -1,7 +1,7 @@
<?php
return [
'dir'=>'HomeMovies',
'dir'=>'HomeMovies', // Directory PREFIX
'import'=>[
'accepted'=>['m4v','mov','mp4','avi'],
],