6b9207451b3d2a7e7fe19823bdcaf7e1989927d5
[ntk/apt.git] / apt-pkg / edsp / edspsystem.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4
5 This system provides the abstraction to use the scenario file as the
6 only source of package information to be able to feed the created file
7 back to APT for its own consumption (eat your own dogfood).
8
9 ##################################################################### */
10 /*}}}*/
11 // Include Files /*{{{*/
12 #include <config.h>
13
14 #include <apt-pkg/edspsystem.h>
15 #include <apt-pkg/debversion.h>
16 #include <apt-pkg/edspindexfile.h>
17 #include <apt-pkg/configuration.h>
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/fileutl.h>
20 #include <sys/types.h>
21 #include <unistd.h>
22 #include <dirent.h>
23 #include <errno.h>
24
25 #include <apti18n.h>
26 /*}}}*/
27
28 edspSystem edspSys;
29
30 // System::debSystem - Constructor /*{{{*/
31 edspSystem::edspSystem()
32 {
33 StatusFile = 0;
34
35 Label = "Debian APT solver interface";
36 VS = &debVS;
37 }
38 /*}}}*/
39 // System::~debSystem - Destructor /*{{{*/
40 edspSystem::~edspSystem()
41 {
42 delete StatusFile;
43 }
44 /*}}}*/
45 // System::Lock - Get the lock /*{{{*/
46 bool edspSystem::Lock()
47 {
48 return true;
49 }
50 /*}}}*/
51 // System::UnLock - Drop a lock /*{{{*/
52 bool edspSystem::UnLock(bool NoErrors)
53 {
54 return true;
55 }
56 /*}}}*/
57 // System::CreatePM - Create the underlying package manager /*{{{*/
58 // ---------------------------------------------------------------------
59 /* we can't use edsp input as input for real installations - just a
60 simulation can work, but everything else will fail bigtime */
61 pkgPackageManager *edspSystem::CreatePM(pkgDepCache *Cache) const
62 {
63 return NULL;
64 }
65 /*}}}*/
66 // System::Initialize - Setup the configuration space.. /*{{{*/
67 bool edspSystem::Initialize(Configuration &Cnf)
68 {
69 Cnf.Set("Dir::State::extended_states", "/dev/null");
70 Cnf.Set("Dir::State::status","/dev/null");
71 Cnf.Set("Dir::State::lists","/dev/null");
72
73 Cnf.Set("Debug::NoLocking", "true");
74 Cnf.Set("APT::Get::Simulate", "true");
75
76 if (StatusFile) {
77 delete StatusFile;
78 StatusFile = 0;
79 }
80 return true;
81 }
82 /*}}}*/
83 // System::ArchiveSupported - Is a file format supported /*{{{*/
84 bool edspSystem::ArchiveSupported(const char *Type)
85 {
86 return false;
87 }
88 /*}}}*/
89 // System::Score - Determine if we should use the edsp system /*{{{*/
90 signed edspSystem::Score(Configuration const &Cnf)
91 {
92 if (Cnf.Find("edsp::scenario", "") == "stdin")
93 return 1000;
94 if (FileExists(Cnf.FindFile("edsp::scenario","")) == true)
95 return 1000;
96 return -1000;
97 }
98 /*}}}*/
99 // System::AddStatusFiles - Register the status files /*{{{*/
100 bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List)
101 {
102 if (StatusFile == 0)
103 {
104 if (_config->Find("edsp::scenario", "") == "stdin")
105 StatusFile = new edspIndex("stdin");
106 else
107 StatusFile = new edspIndex(_config->FindFile("edsp::scenario"));
108 }
109 List.push_back(StatusFile);
110 return true;
111 }
112 /*}}}*/
113 // System::FindIndex - Get an index file for status files /*{{{*/
114 bool edspSystem::FindIndex(pkgCache::PkgFileIterator File,
115 pkgIndexFile *&Found) const
116 {
117 if (StatusFile == 0)
118 return false;
119 if (StatusFile->FindInCache(*File.Cache()) == File)
120 {
121 Found = StatusFile;
122 return true;
123 }
124
125 return false;
126 }
127 /*}}}*/