mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-54916 filestorage: Only write empty zip on change.
In some cases we may inspect an empty zip file. If we do open an empty zip file, check that it changed before we attempt to write it to disk. It may be the case that we were reading the file from a location that we don't have write access to.
This commit is contained in:
parent
919b9dfabd
commit
261bfabc6f
1 changed files with 6 additions and 0 deletions
|
@ -207,6 +207,12 @@ class zip_archive extends file_archive {
|
||||||
$this->mode = null;
|
$this->mode = null;
|
||||||
$this->namelookup = null;
|
$this->namelookup = null;
|
||||||
$this->modified = false;
|
$this->modified = false;
|
||||||
|
// If the existing archive is already empty, we didn't change it. Don't bother completing a save.
|
||||||
|
// This is important when we are inspecting archives that we might not have write permission to.
|
||||||
|
if (@filesize($this->archivepathname) == 22 &&
|
||||||
|
@file_get_contents($this->archivepathname) === base64_decode(self::$emptyzipcontent)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@unlink($this->archivepathname);
|
@unlink($this->archivepathname);
|
||||||
$data = base64_decode(self::$emptyzipcontent);
|
$data = base64_decode(self::$emptyzipcontent);
|
||||||
if (!file_put_contents($this->archivepathname, $data)) {
|
if (!file_put_contents($this->archivepathname, $data)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue