From 28fdd0fcab1ed424d0bb3749b79c6fa6ae6b49ef Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 4 Oct 2024 11:08:18 +1000 Subject: [PATCH] Fix for isParentWritable() processing --- app/Jobs/CatalogDelete.php | 4 ++-- app/Models/Abstracted/Catalog.php | 28 +++++++++++++++++++++------- config/photo.php | 2 +- config/video.php | 2 +- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/Jobs/CatalogDelete.php b/app/Jobs/CatalogDelete.php index 542b1f9..152e2d2 100644 --- a/app/Jobs/CatalogDelete.php +++ b/app/Jobs/CatalogDelete.php @@ -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 diff --git a/app/Models/Abstracted/Catalog.php b/app/Models/Abstracted/Catalog.php index a0f3290..a4fc008 100644 --- a/app/Models/Abstracted/Catalog.php +++ b/app/Models/Abstracted/Catalog.php @@ -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 diff --git a/config/photo.php b/config/photo.php index 41779af..6ce5cfd 100644 --- a/config/photo.php +++ b/config/photo.php @@ -1,7 +1,7 @@ 'Photos', + 'dir'=>'Photos', // Directory PREFIX 'import'=>[ 'accepted'=>['jpg','jpeg','heic'], ], diff --git a/config/video.php b/config/video.php index 0cd3c9a..1eb8451 100644 --- a/config/video.php +++ b/config/video.php @@ -1,7 +1,7 @@ 'HomeMovies', + 'dir'=>'HomeMovies', // Directory PREFIX 'import'=>[ 'accepted'=>['m4v','mov','mp4','avi'], ],