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.
This commit is contained in:
Shamim Rezaie 2018-05-10 18:16:09 +10:00
parent 02c7769422
commit f181a24a0b

View File

@ -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');
}
}