From f181a24a0bc3c991a1f31699885d69e8564bd084 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Thu, 10 May 2018 18:16:09 +1000 Subject: [PATCH] MDL-62251 backup: Fix replace_tempdir() bug under Windows rename() fails under Windows if the destination file/directory exists. I modified the code to only call $this->get_workdir_path() once as that function creates the directory if doesn't exist. And we don't want that considering the behaviour of rename on Windows. --- backup/converter/convertlib.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backup/converter/convertlib.php b/backup/converter/convertlib.php index 1fdcf1dcd7c..9a3f87a11c4 100644 --- a/backup/converter/convertlib.php +++ b/backup/converter/convertlib.php @@ -239,15 +239,17 @@ abstract class base_converter implements loggable { protected function replace_tempdir() { global $CFG; + $tempdir = $this->get_tempdir_path(); + if (empty($CFG->keeptempdirectoriesonbackup)) { - fulldelete($this->get_tempdir_path()); + fulldelete($tempdir); } else { - if (!rename($this->get_tempdir_path(), $this->get_tempdir_path() . '_' . $this->get_name() . '_' . $this->id . '_source')) { + if (!rename($tempdir, $tempdir . '_' . $this->get_name() . '_' . $this->id . '_source')) { throw new convert_exception('failed_rename_source_tempdir'); } } - if (!rename($this->get_workdir_path(), $this->get_tempdir_path())) { + if (!rename($this->get_workdir_path(), $tempdir)) { throw new convert_exception('failed_move_converted_into_place'); } }