init.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: init.cc,v 1.10 1998/11/05 07:21:42 jgg Exp $
  4. /* ######################################################################
  5. Init - Initialize the package library
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include files /*{{{*/
  9. #include <apt-pkg/init.h>
  10. #include <config.h>
  11. #include <sys/stat.h>
  12. #include <unistd.h>
  13. /*}}}*/
  14. // pkgInitialize - Initialize the configuration class /*{{{*/
  15. // ---------------------------------------------------------------------
  16. /* Directories are specified in such a way that the FindDir function will
  17. understand them. That is, if they don't start with a / then their parent
  18. is prepended, this allows a fair degree of flexability. */
  19. bool pkgInitialize(Configuration &Cnf)
  20. {
  21. // General APT things
  22. Cnf.Set("APT::Architecture",ARCHITECTURE);
  23. // State
  24. Cnf.Set("Dir::State","/var/state/apt/");
  25. Cnf.Set("Dir::State::lists","lists/");
  26. /* These really should be jammed into a generic 'Local Database' engine
  27. which is yet to be determined. The functions in pkgcachegen should
  28. be the only users of these */
  29. Cnf.Set("Dir::State::xstatus","xstatus");
  30. Cnf.Set("Dir::State::userstatus","status.user");
  31. Cnf.Set("Dir::State::status","/var/lib/dpkg/status");
  32. // Cache
  33. Cnf.Set("Dir::Cache","/var/cache/apt/");
  34. Cnf.Set("Dir::Cache::archives","archives/");
  35. Cnf.Set("Dir::Cache::srcpkgcache","srcpkgcache.bin");
  36. Cnf.Set("Dir::Cache::pkgcache","pkgcache.bin");
  37. // Configuration
  38. Cnf.Set("Dir::Etc","/etc/apt/");
  39. Cnf.Set("Dir::Etc::sourcelist","sources.list");
  40. Cnf.Set("Dir::Etc::main","apt.conf");
  41. Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods");
  42. // Read the main config file
  43. string FName = Cnf.FindFile("Dir::Etc::main");
  44. struct stat Buf;
  45. if (stat(FName.c_str(),&Buf) != 0)
  46. return true;
  47. // Read an alternate config file
  48. const char *Cfg = getenv("APT_CONFIG");
  49. // Read both config files, either existing will be OK
  50. if ((ReadConfigFile(Cnf,FName) != true) |
  51. (ReadConfigFile(Cnf,Cfg) != true))
  52. return false;
  53. if (Cnf.FindB("Debug::pkgInitialize",false) == true)
  54. Cnf.Dump();
  55. return true;
  56. }
  57. /*}}}*/