private function archive_pathname($ziparch, $archivepath, $file,
            file_progress $progress = null) {
        // Record progress each time this function is called.
        if ($progress) {
            $progress->progress();
        }

        if (!file_exists($file)) {
            return false;
        }

        if (is_file($file)) {
            if (!is_readable($file)) {
                return false;
            }
            return $ziparch->add_file_from_pathname($archivepath, $file);
        }
        if (is_dir($file)) {
            if ($archivepath !== '') {
                $ziparch->add_directory($archivepath);
            }
            $files = new DirectoryIterator($file);
            foreach ($files as $file) {
                if ($file->isDot()) {
                    continue;
                }
                $newpath = $archivepath.'/'.$file->getFilename();
                $this->archive_pathname($ziparch, $newpath, $file->getPathname(), $progress);
            }
            unset($files); // Release file handles.
            return true;
        }
    }