**概要 [#k9d478e7] attachプラグインでの添付ファイルリネーム処理は、バックアップファイル(.1, .2, ...)とログファイル(.log)のファイルをリネームしません((バグっぽい挙動ですが))。これをリネームするように変更します。 **内容 [#y408020f] [[BugTrack2/345]] diff --git a/attach.inc.php b/attach.inc.php --- a/attach.inc.php +++ b/attach.inc.php @@ -672,10 +672,40 @@ if (file_exists($newbase)) { return array('msg'=>$_attach_messages['err_exists']); } - if (! PLUGIN_ATTACH_RENAME_ENABLE || ! rename($this->basename, $newbase)) { + if (! PLUGIN_ATTACH_RENAME_ENABLE) { return array('msg'=>$_attach_messages['err_rename']); + } else { + if (! rename($this->basename, $newbase)) { + return array('msg'=>$_attach_messages['err_rename']); + } + // リネーム成功 + // バックアップファイル・ログファイルもリネームする + // エラー処理は省略 + $rename_targets = array(); + if ($dir = opendir(UPLOAD_DIR)) { + $matches_leaf = array(); + if (preg_match('/(((?:[0-9A-F]{2})+)_((?:[0-9A-F]{2})+))$/', $this->basename, $matches_leaf)) { + $attachfile_leafname = $matches_leaf[1]; + $attachfile_leafname_pattern = preg_quote($attachfile_leafname, '/'); + $pattern = "/^({$attachfile_leafname_pattern})(\.((\d+)|(log)))$/"; + + $matches = array(); + while ($file = readdir($dir)) { + if (! preg_match($pattern, $file, $matches)) + continue; + $basename2 = $matches[0]; + $newbase2 = $newbase . $matches[2]; + $rename_targets[$basename2] = $newbase2; + } + } + closedir($dir); + } + foreach ($rename_targets as $basename2=>$newbase2) { + $basename2path = UPLOAD_DIR . $basename2; + echo "rename '$basename2path' to '$newbase2'<br>\n"; + rename($basename2path, $newbase2); + } } - return array('msg'=>$_attach_messages['msg_renamed']); } ** 例 [#kab22c4c] バックアップファイルを持つ a.txt を b.txt にリネームしたとき: rename 'attach/41_612E747874.1' to 'attach/41_622E747874.1' rename 'attach/41_612E747874.log' to 'attach/41_622E747874.log' **コメント [#d2ebf6f5] - 添付ファイルをリネームしたときにバックアップファイルがリネームされず、どこからもリンクされないゴミが残ってしまう対策 -- [[umorigu]] &new{2011-05-07 (土) 17:42:16}; - 改善したほうがいいと思うなら、BugTrackに報告したほうがいい話の気がする。関連: [[BugTrack2/170]] -- &new{2011-05-07 (土) 23:31:20}; - たしかに、BugTrackが適切ですね -- [[umorigu]] &new{2011-05-08 (日) 10:19:23}; - 報告しました [[BugTrack2/345]] -- [[umorigu]] &new{2011-05-08 (日) 13:12:03}; - コンテンツを一本化しますね。 -- [[henoheno]] &new{2011-05-08 (日) 22:09:35}; - こんにちは。コンテンツを一本化しますね。 -- [[henoheno]] &new{2011-05-08 (日) 22:09:35}; #comment