Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #205 ubuntu scan fails #209

Closed
wants to merge 3 commits into from

Conversation

william20111
Copy link

Fix for #205

Just runs another regex that matches the older apt versions output. It works, but its not pretty might want to put something more elegant in.

Cheers
Will

@kotakanbe
Copy link
Member

@kotakanbe
Copy link
Member

The copy & paste code is not so good ;)
I think it's better to change Regex pattern like below.

func (o *debian) parseAptGetUpgrade(stdout string) (upgradableNames []string, err error) {
    startRe := regexp.MustCompile(`The following packages will be upgraded:`)
*   stopRe := regexp.MustCompile(`^(\d+) (to )?upgrade(d)?,.*`)
    startLineFound, stopLineFound := false, false

    lines := strings.Split(stdout, "\n")
    for _, line := range lines {
        if !startLineFound {
            if matche := startRe.MatchString(line); matche {
                startLineFound = true
            }
            continue
        }
        result := stopRe.FindStringSubmatch(line)
*       if 2 < len(result) {
            numUpgradablePacks, err := strconv.Atoi(result[1])
            if err != nil {
                return nil, fmt.Errorf(
                    "Failed to scan upgradable packages number. line: %s", line)
            }
            if numUpgradablePacks != len(upgradableNames) {
                return nil, fmt.Errorf(
                    "Failed to scan upgradable packages, expected: %s, detected: %d",
                    result[1], len(upgradableNames))
            }
            stopLineFound = true
            o.log.Debugf("Found the stop line. line: %s", line)
            break
        }
        upgradableNames = append(upgradableNames, strings.Fields(line)...)
    }
    if !startLineFound {
        // no upgrades
        return
    }
    if !stopLineFound {
        // There are upgrades, but not found the stop line.
        return nil, fmt.Errorf("Failed to scan upgradable packages")
    }
    return
}

@william20111
Copy link
Author

Yes looks much better! Will change the PR and test

Cheers
Will

@kotakanbe kotakanbe added the bug label Oct 25, 2016
@kotakanbe
Copy link
Member

If you are still using the old version of apt please reopen.

@kotakanbe kotakanbe closed this Mar 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants