public function scan()
    {
        $this->init();
        $list = $this->packageInfo->getFilelist();

        if ($this->includes === null) {
            // No includes supplied, so set it to 'matches all'
            $this->includes = ["**"];
        }
        if ($this->excludes === null) {
            $this->excludes = [];
        }

        $this->filesIncluded = [];
        $this->filesNotIncluded = [];
        $this->filesExcluded = [];
        $this->filesDeselected = [];

        $this->dirsIncluded = [];
        $this->dirsNotIncluded = [];
        $this->dirsExcluded = [];
        $this->dirsDeselected = [];
        $origFirstFile = null;

        foreach ($list as $file => $att) {
            if ($att['role'] != $this->role && $this->role != '') {
                continue;
            }
            $origFile = $file;
            if (isset($att['install-as'])) {
                $file = $att['install-as'];
            } else {
                if (isset($att['baseinstalldir'])) {
                    $file = ltrim($att['baseinstalldir'] . '/' . $file, '/');
                }
            }
            $file = str_replace('/', DIRECTORY_SEPARATOR, $file);

            if ($this->isIncluded($file)) {
                if ($this->isExcluded($file)) {
                    $this->everythingIncluded = false;
                    if (@is_dir($file)) {
                        $this->dirsExcluded[] = $file;
                    } else {
                        $this->filesExcluded[] = $file;
                    }
                } else {
                    if (@is_dir($file)) {
                        $this->dirsIncluded[] = $file;
                    } else {
                        $this->filesIncluded[] = $file;
                        if ($origFirstFile === null) {
                            $origFirstFile = $origFile;
                        }
                    }
                }
            } else {
                $this->everythingIncluded = false;
                if (@is_dir($file)) {
                    $this->dirsNotIncluded[] = $file;
                } else {
                    $this->filesNotIncluded[] = $file;
                }
            }
        }

        if (count($this->filesIncluded) > 0) {
            if (empty($this->packageFile)) {
                $att = $list[$origFirstFile];
                $base_dir = substr(
                    $att['installed_as'],
                    0,
                    -strlen($this->filesIncluded[0])
                );
            } else {
                $base_dir = dirname($this->packageFile);
            }
            $this->setBasedir($base_dir);
        }

        return true;
    }