| Línea 98... | Línea 98... | 
          
            | 98 |      * @throws file_exception If file operations fail
 | 98 |      * @throws file_exception If file operations fail
 | 
          
            | 99 |      * @throws coding_exception If any archive paths do not meet the restrictions
 | 99 |      * @throws coding_exception If any archive paths do not meet the restrictions
 | 
          
            | 100 |      */
 | 100 |      */
 | 
          
            | 101 |     public function archive_to_storage(array $files, $contextid,
 | 101 |     public function archive_to_storage(array $files, $contextid,
 | 
          
            | 102 |             $component, $filearea, $itemid, $filepath, $filename,
 | 102 |             $component, $filearea, $itemid, $filepath, $filename,
 | 
          
            | 103 |             $userid = null, $ignoreinvalidfiles = true, file_progress $progress = null) {
 | 103 |             $userid = null, $ignoreinvalidfiles = true, ?file_progress $progress = null) {
 | 
          
            | 104 |         global $CFG;
 | 104 |         global $CFG;
 | 
          
            | Línea 105... | Línea 105... | 
          
            | 105 |  
 | 105 |  
 | 
          
            | 106 |         // Set up a temporary location for the file.
 | 106 |         // Set up a temporary location for the file.
 | 
          
            | 107 |         $tempfolder = $CFG->tempdir . '/core_files';
 | 107 |         $tempfolder = $CFG->tempdir . '/core_files';
 | 
          
            | Línea 165... | Línea 165... | 
          
            | 165 |      * @param file_progress $progress Progress indicator callback or null if not required
 | 165 |      * @param file_progress $progress Progress indicator callback or null if not required
 | 
          
            | 166 |      * @return bool true if file created, false if not
 | 166 |      * @return bool true if file created, false if not
 | 
          
            | 167 |      * @throws coding_exception If any archive paths do not meet the restrictions
 | 167 |      * @throws coding_exception If any archive paths do not meet the restrictions
 | 
          
            | 168 |      */
 | 168 |      */
 | 
          
            | 169 |     public function archive_to_pathname(array $files, $archivefile,
 | 169 |     public function archive_to_pathname(array $files, $archivefile,
 | 
          
            | 170 |             $ignoreinvalidfiles=true, file_progress $progress = null) {
 | 170 |             $ignoreinvalidfiles=true, ?file_progress $progress = null) {
 | 
          
            | 171 |         // Open .gz file.
 | 171 |         // Open .gz file.
 | 
          
            | 172 |         if (!($gz = gzopen($archivefile, 'wb'))) {
 | 172 |         if (!($gz = gzopen($archivefile, 'wb'))) {
 | 
          
            | 173 |             return false;
 | 173 |             return false;
 | 
          
            | 174 |         }
 | 174 |         }
 | 
          
            | 175 |         try {
 | 175 |         try {
 | 
          
            | Línea 325... | Línea 325... | 
          
            | 325 |      * @param int $done Value for progress indicator
 | 325 |      * @param int $done Value for progress indicator
 | 
          
            | 326 |      * @return bool True if OK
 | 326 |      * @return bool True if OK
 | 
          
            | 327 |      * @throws coding_exception If names aren't valid
 | 327 |      * @throws coding_exception If names aren't valid
 | 
          
            | 328 |      */
 | 328 |      */
 | 
          
            | 329 |     protected function write_tar_entry($gz, $archivepath, $file, $size, $mtime, $content = null,
 | 329 |     protected function write_tar_entry($gz, $archivepath, $file, $size, $mtime, $content = null,
 | 
          
            | 330 |             file_progress $progress = null, $done = 0) {
 | 330 |             ?file_progress $progress = null, $done = 0) {
 | 
          
            | 331 |         // Header based on documentation of POSIX ustar format from:
 | 331 |         // Header based on documentation of POSIX ustar format from:
 | 
          
            | 332 |         // http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5&manpath=FreeBSD+8-current .
 | 332 |         // http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5&manpath=FreeBSD+8-current .
 | 
          
            | Línea 333... | Línea 333... | 
          
            | 333 |  
 | 333 |  
 | 
          
            | 334 |         // For directories, ensure name ends in a slash.
 | 334 |         // For directories, ensure name ends in a slash.
 | 
          
            | Línea 639... | Línea 639... | 
          
            | 639 |      * details.
 | 639 |      * details.
 | 
          
            | 640 |      * @return array list of processed files (name=>true)
 | 640 |      * @return array list of processed files (name=>true)
 | 
          
            | 641 |      * @throws moodle_exception If error
 | 641 |      * @throws moodle_exception If error
 | 
          
            | 642 |      */
 | 642 |      */
 | 
          
            | 643 |     public function extract_to_pathname($archivefile, $pathname,
 | 643 |     public function extract_to_pathname($archivefile, $pathname,
 | 
          
            | 644 |             array $onlyfiles = null, file_progress $progress = null, $returnbool = false) {
 | 644 |             ?array $onlyfiles = null, ?file_progress $progress = null, $returnbool = false) {
 | 
          
            | 645 |         $extractor = new tgz_extractor($archivefile);
 | 645 |         $extractor = new tgz_extractor($archivefile);
 | 
          
            | 646 |         try {
 | 646 |         try {
 | 
          
            | 647 |             $result = $extractor->extract(
 | 647 |             $result = $extractor->extract(
 | 
          
            | 648 |                     new tgz_packer_extract_to_pathname($pathname, $onlyfiles), $progress);
 | 648 |                     new tgz_packer_extract_to_pathname($pathname, $onlyfiles), $progress);
 | 
          
            | 649 |             if ($returnbool) {
 | 649 |             if ($returnbool) {
 | 
          
            | Línea 682... | Línea 682... | 
          
            | 682 |      * @return array list of processed files (name=>true)
 | 682 |      * @return array list of processed files (name=>true)
 | 
          
            | 683 |      * @throws moodle_exception If error
 | 683 |      * @throws moodle_exception If error
 | 
          
            | 684 |      */
 | 684 |      */
 | 
          
            | 685 |     public function extract_to_storage($archivefile, $contextid,
 | 685 |     public function extract_to_storage($archivefile, $contextid,
 | 
          
            | 686 |             $component, $filearea, $itemid, $pathbase, $userid = null,
 | 686 |             $component, $filearea, $itemid, $pathbase, $userid = null,
 | 
          
            | 687 |             file_progress $progress = null) {
 | 687 |             ?file_progress $progress = null) {
 | 
          
            | 688 |         $extractor = new tgz_extractor($archivefile);
 | 688 |         $extractor = new tgz_extractor($archivefile);
 | 
          
            | 689 |         return $extractor->extract(
 | 689 |         return $extractor->extract(
 | 
          
            | 690 |                 new tgz_packer_extract_to_storage($contextid, $component,
 | 690 |                 new tgz_packer_extract_to_storage($contextid, $component,
 | 
          
            | 691 |                     $filearea, $itemid, $pathbase, $userid), $progress);
 | 691 |                     $filearea, $itemid, $pathbase, $userid), $progress);
 | 
          
            | 692 |     }
 | 692 |     }
 | 
          
            | Línea 750... | Línea 750... | 
          
            | 750 |      * Constructor.
 | 750 |      * Constructor.
 | 
          
            | 751 |      *
 | 751 |      *
 | 
          
            | 752 |      * @param string $pathname target directory
 | 752 |      * @param string $pathname target directory
 | 
          
            | 753 |      * @param array $onlyfiles only extract files present in the array
 | 753 |      * @param array $onlyfiles only extract files present in the array
 | 
          
            | 754 |      */
 | 754 |      */
 | 
          
            | 755 |     public function __construct($pathname, array $onlyfiles = null) {
 | 755 |     public function __construct($pathname, ?array $onlyfiles = null) {
 | 
          
            | 756 |         $this->pathname = $pathname;
 | 756 |         $this->pathname = $pathname;
 | 
          
            | 757 |         $this->onlyfiles = $onlyfiles;
 | 757 |         $this->onlyfiles = $onlyfiles;
 | 
          
            | 758 |     }
 | 758 |     }
 | 
          
            | Línea 759... | Línea 759... | 
          
            | 759 |  
 | 759 |  
 |