From 1191dfb193ea36f18ba84ad1b546ed0517286c95 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 18 Aug 2024 01:06:45 +0200 Subject: [PATCH] pages.php: add copy fallback in case of already existing file when moving thread. --- inc/mod/pages.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index ac5cf35f..a713d8fe 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -10,6 +10,14 @@ use Vichan\Functions\Net; defined('TINYBOARD') or exit; +function _link_or_copy(string $target, string $link): bool { + if (!link($target, $link)) { + error_log("Failed to link() $target to $link. Falling back to copy()"); + return copy($target, $link); + } + return true; +} + function mod_page($title, $template, $args, $subtitle = false) { global $config, $mod; @@ -1348,7 +1356,7 @@ function mod_move(Context $ctx, $originBoard, $postID) { error(_('Target and source board are the same.')); // link() if leaving a shadow thread behind; else, rename(). - $clone = $shadow ? 'link' : 'rename'; + $clone = $shadow ? '_link_or_copy' : 'rename'; // indicate that the post is a thread $post['op'] = true;