commit 975d4c0213a9302f63630b7c879264d03e83dc23
parent ed78dbffef70a09bd1455a00b476e97b30c72d08
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Fri, 20 Dec 2024 09:31:30 +0100
fix: ensure path exists if note is moved to new category
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/lib/edit.php b/lib/edit.php
@@ -14,6 +14,18 @@ function edit_note(
/* if old and new filepaths differ, the file was likely renamed.
* delete the old one and return immediately */
if ($filepath_t1 != $filepath_t0 && !empty($filepath_t1)) {
+
+ /* Ensure the new path exists */
+ $dirpath = $GLOBALS["data_dir"] . "/" . $user . "/" . $category;
+ if (opendir($dirpath) === false) {
+ mkdir(
+ $dirpath, /* directory */
+ 0770, /* Permissions: rwxrwx--- */
+ true /* recursive */
+ );
+ }
+
+ /* Rename / move file */
$renamed = rename(
$GLOBALS["data_dir"] . "/" . $user . "/" . $filepath_t1,
$GLOBALS["data_dir"] . "/" . $user . "/" . $filepath_t0
@@ -22,6 +34,7 @@ function edit_note(
if ($renamed === false) {
return false;
}
+
/* cleanup directories and removed empty categories */
remove_empty_categories($user, basename(dirname($filepath_t1, 1)));
}