private function archive_stored($ziparch, $archivepath, $file, file_progress $progress = null) {
        $result = $file->archive_file($ziparch, $archivepath);
        if (!$result) {
            return false;
        }

        if (!$file->is_directory()) {
            return true;
        }

        $baselength = strlen($file->get_filepath());
        $fs = get_file_storage();
        $files = $fs->get_directory_files($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(),
                                          $file->get_filepath(), true, true);
        foreach ($files as $file) {
            // Record progress for each file.
            if ($progress) {
                $progress->progress();
            }

            $path = $file->get_filepath();
            $path = substr($path, $baselength);
            $path = $archivepath.'/'.$path;
            if (!$file->is_directory()) {
                $path = $path.$file->get_filename();
            }
            // Ignore result here, partial zipping is ok for now.
            $file->archive_file($ziparch, $path);
        }

        return true;
    }