From e98483d7485e44916986d23f7f685896eade5657 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Mon, 8 Aug 2016 15:26:42 +0100 Subject: [PATCH 1/2] MDL-55513 core_filestorage: Pass full path of temp dir to remove_dir() --- lib/filestorage/file_storage.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index 18e357003b7..0480bf794ba 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -365,7 +365,7 @@ class file_storage { throw new file_exception('storedfileproblem', 'Could not copy file contents to temp file.'); } } catch (file_exception $fe) { - remove_dir($uniqdir); + remove_dir($tmp); throw $fe; } @@ -387,7 +387,7 @@ class file_storage { $result = exec($cmd, $output); chdir($currentdir); if (!file_exists($newtmpfile)) { - remove_dir($uniqdir); + remove_dir($tmp); // Cleanup. return false; } @@ -404,7 +404,7 @@ class file_storage { $convertedfile = $this->create_file_from_pathname($record, $newtmpfile); // Cleanup. - remove_dir($uniqdir); + remove_dir($tmp); return $convertedfile; } From 2ee668ec56cc5b830bc03b59656613cb943e8027 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Mon, 8 Aug 2016 15:29:14 +0100 Subject: [PATCH 2/2] MDL-55513 core_filestorage: Touch and test size instead of file_exists() file_exists() can return false when file exists (in certain scenarios) --- lib/filestorage/file_storage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index 0480bf794ba..38a20a11026 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -386,7 +386,8 @@ class file_storage { chdir($tmp); $result = exec($cmd, $output); chdir($currentdir); - if (!file_exists($newtmpfile)) { + touch($newtmpfile); + if (filesize($newtmpfile) === 0) { remove_dir($tmp); // Cleanup. return false;