cmdline/apt-get.cc从http://packages.ubuntu.com/source/maverick/apt的源压缩文件中查看文件,我可以看到这--auto-remove是一个启用APT::Get::AutomaticRemove设置的参数。
命令autoremove和remove都调用函数DoInstall。
命令“ autoremove”也设置APT::Get::AutomaticRemove了,因此它与做同样的事情--auto-remove。
从DoAutomaticRemove功能中可以明显看出,启用APT::Get::AutomaticRemove设置(--auto-remove并autoremove执行此操作)会导致Apt循环遍历所有已安装的软件包,并将未使用的软件包标记为要删除。
来自main():
CommandLine::Args Args[] = {
// ... stripped to save space
{0,"auto-remove","APT::Get::AutomaticRemove",0},
// ...
}
CommandLine::Dispatch Cmds[] = { // ...
{"remove",&DoInstall},
{"purge",&DoInstall},
{"autoremove",&DoInstall},
// ...
}
// ...
// Parse the command line and initialize the package library
CommandLine CmdL(Args,_config);
来自DoInstall():
unsigned short fallback = MOD_INSTALL;
if (strcasecmp(CmdL.FileList[0],"remove") == 0)
fallback = MOD_REMOVE;
else if (strcasecmp(CmdL.FileList[0], "purge") == 0)
{
_config->Set("APT::Get::Purge", true);
fallback = MOD_REMOVE;
}
else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0)
{
_config->Set("APT::Get::AutomaticRemove", "true");
fallback = MOD_REMOVE;
}
从功能DoAutomaticRemove:
bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false);
// ...
// look over the cache to see what can be removed
for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg) {
if (doAutoRemove) {
if(Pkg.CurrentVer() != 0 &&
Pkg->CurrentState != pkgCache::State::ConfigFiles)
Cache->MarkDelete(Pkg, purgePkgs);
else
Cache->MarkKeep(Pkg, false, false);
}
}
我不能说这是不是故意的,您可以在launchpad.net上填写错误 /提出问题。
目前,无法从中删除包apt-get autoremove。如果要保留软件包,请运行apt-get -s autoremove,从列表中复制软件包,然后从要保留的列表中删除软件包。最后,删除那些软件包:(sudo apt-get purge [packages-to-be-removed]清除也会删除配置文件,如果有的话)