sebastien/cuisine

Why `apt_get` function executes a command twice?

Tolsi opened this issue · 0 comments

In the case of "purge" operations, a second call is the removal of a package fails:

def apt_get(cmd):
    cmd    = CMD_APT_GET + cmd
    result = sudo(cmd) # !!!
    # If the installation process was interrupted, we might get the following message
    # E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.
    if "sudo dpkg --configure -a" in result:
        sudo("DEBIAN_FRONTEND=noninteractive dpkg --configure -a")
    return sudo(cmd) # !!!

I use it like that:

apt_get('--force-yes -q purge ' + package_name)

In logs I see:

DEBIAN_FRONTEND=noninteractive apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes -q purge my-package
...
removal logs
...
DEBIAN_FRONTEND=noninteractive apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes -q purge my-package
out: E: Unable to locate package my-package

Fatal error: sudo() received nonzero return code 100 while executing!