MDL-41839 Files: Zip packer progress minor bugs

The progress variable wasn't always passed to recursive calls. This
caused a lack of progress() calls between files in subfolders. I
added a unit test for this situation.
This commit is contained in:
sam marshall
2013-09-17 14:19:07 +01:00
parent 83f26f6407
commit 771e3f7cab
2 changed files with 19 additions and 3 deletions
+16
View File
@@ -446,6 +446,22 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
array(file_progress::INDETERMINATE, file_progress::INDETERMINATE),
$this->progress[0]);
// Archive to pathname using entire folder and subfolder instead of file list.
unlink($archive);
$folder = make_temp_directory('zip_packer_progress');
file_put_contents($folder . '/test1.txt', 'hello');
$subfolder = $folder . '/sub';
check_dir_exists($subfolder);
file_put_contents($subfolder . '/test2.txt', 'world');
file_put_contents($subfolder . '/test3.txt', 'and');
file_put_contents($subfolder . '/test4.txt', 'other');
file_put_contents($subfolder . '/test5.txt', 'worlds');
$this->progress = array();
$result = $packer->archive_to_pathname(array('' => $folder), $archive, true, $this);
$this->assertTrue($result);
// Should send progress at least once per file.
$this->assertTrue(count($this->progress) >= 5);
// Archive to storage.
$this->progress = array();
$archivefile = $packer->archive_to_storage($this->files, $context->id,
+3 -3
View File
@@ -122,7 +122,7 @@ class zip_packer extends file_packer {
}
} else if (is_string($file)) {
if (!$this->archive_pathname($ziparch, $archivepath, $file)) {
if (!$this->archive_pathname($ziparch, $archivepath, $file, $progress)) {
debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
@@ -141,7 +141,7 @@ class zip_packer extends file_packer {
}
} else {
if (!$this->archive_stored($ziparch, $archivepath, $file)) {
if (!$this->archive_stored($ziparch, $archivepath, $file, $progress)) {
debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
@@ -242,7 +242,7 @@ class zip_packer extends file_packer {
continue;
}
$newpath = $archivepath.'/'.$file->getFilename();
$this->archive_pathname($ziparch, $newpath, $file->getPathname());
$this->archive_pathname($ziparch, $newpath, $file->getPathname(), $progress);
}
unset($files); // Release file handles.
return true;