]>
git.saurik.com Git - apt.git/blob - cmdline/debfile.cc
2 #include <apt-pkg/tagfile.h>
3 #include <apt-pkg/extracttar.h>
4 #include <apt-pkg/arfile.h>
5 #include <apt-pkg/pkgcache.h>
9 pkgCache
*DebFile::Cache
= 0;
11 DebFile::DebFile(const char *debfile
)
12 : File(debfile
, FileFd::ReadOnly
), Control(0), Package(0), Version(0), DepVer(0), PreDepVer(0), DepOp(0), PreDepOp(0), Config(0), Template(0), Which(None
)
23 char *DebFile::GetInstalledVer(const char *package
)
27 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(package
);
28 if (Pkg
.end() == false)
30 pkgCache::VerIterator V
= Pkg
.CurrentVer();
33 ver
= strdup(V
.VerStr());
43 const ARArchive::Member
*Member
= AR
.FindMember("control.tar.gz");
46 fprintf(stderr
, "This is not a valid DEB archive.\n");
50 if (File
.Seek(Member
->Start
) == false)
55 ExtractTar
Tar(File
, Member
->Size
);
59 bool DebFile::DoItem(Item
&I
, int &Fd
)
61 if (strcmp(I
.Name
, "control") == 0)
64 Control
= new char[I
.Size
+1];
68 // make it call the Process method below. this is so evil
71 else if (strcmp(I
.Name
, "config") == 0)
74 Config
= new char[I
.Size
+1];
79 else if (strcmp(I
.Name
, "templates") == 0)
82 Template
= new char[I
.Size
+1];
94 bool DebFile::Process(Item
&I
, const unsigned char *data
,
95 unsigned long size
, unsigned long pos
)
100 memcpy(Control
+ pos
, data
, size
);
103 memcpy(Config
+ pos
, data
, size
);
106 memcpy(Template
+ pos
, data
, size
);
108 default: /* throw it away */ ;
113 bool DebFile::ParseInfo()
115 if (Control
== NULL
) return false;
116 pkgTagSection Section
;
117 Section
.Scan(Control
, ControlLen
);
119 const char *pkgtmp
= Section
.FindS("Package").c_str();
120 Package
= CopyString(pkgtmp
, strlen(pkgtmp
));
121 Version
= GetInstalledVer(Package
);
123 const char *Start
, *Stop
;
124 if (Section
.Find("Depends", Start
, Stop
) == true)
130 Start
= ParseDepends(Start
, Stop
, P
, V
, Op
);
131 if (Start
== 0) return false;
132 if (strcmp(P
, "debconf") == 0)
144 if (Start
== Stop
) break;
148 if (Section
.Find("Pre-Depends", Start
, Stop
) == true)
154 Start
= ParseDepends(Start
, Stop
, P
, V
, Op
);
155 if (Start
== 0) return false;
156 if (strcmp(P
, "debconf") == 0)
168 if (Start
== Stop
) break;
175 char *DebFile::CopyString(const char *start
, unsigned int len
)
177 char *s
= new char[len
+ 1];
179 memcpy(s
, start
, len
);
183 const char *DebFile::ParseDepends(const char *Start
,const char *Stop
,
184 char *&Package
, char *&Ver
,
187 // Strip off leading space
188 for (;Start
!= Stop
&& isspace(*Start
) != 0; Start
++);
190 // Parse off the package name
191 const char *I
= Start
;
192 for (;I
!= Stop
&& isspace(*I
) == 0 && *I
!= '(' && *I
!= ')' &&
193 *I
!= ',' && *I
!= '|'; I
++);
196 if (I
!= Stop
&& *I
== ')')
202 // Stash the package name
203 Package
= CopyString(Start
, I
- Start
);
205 // Skip white space to the '('
206 for (;I
!= Stop
&& isspace(*I
) != 0 ; I
++);
209 if (I
!= Stop
&& *I
== '(')
212 for (I
++; I
!= Stop
&& isspace(*I
) != 0 ; I
++);
216 // Determine the operator
224 Op
= pkgCache::Dep::LessEq
;
231 Op
= pkgCache::Dep::Less
;
235 // < is the same as <= and << is really Cs < for some reason
236 Op
= pkgCache::Dep::LessEq
;
244 Op
= pkgCache::Dep::GreaterEq
;
251 Op
= pkgCache::Dep::Greater
;
255 // > is the same as >= and >> is really Cs > for some reason
256 Op
= pkgCache::Dep::GreaterEq
;
260 Op
= pkgCache::Dep::Equals
;
264 // HACK around bad package definitions
266 Op
= pkgCache::Dep::Equals
;
271 for (;I
!= Stop
&& isspace(*I
) != 0; I
++);
273 for (;I
!= Stop
&& *I
!= ')'; I
++);
274 if (I
== Stop
|| Start
== I
)
277 // Skip trailing whitespace
279 for (; End
> Start
&& isspace(End
[-1]); End
--);
281 Ver
= CopyString(Start
, End
- Start
);
286 Ver
= CopyString("", 0);
287 Op
= pkgCache::Dep::NoOp
;
291 for (;I
!= Stop
&& isspace(*I
) != 0; I
++);
293 if (I
!= Stop
&& *I
== '|')
294 Op
|= pkgCache::Dep::Or
;
296 if (I
== Stop
|| *I
== ',' || *I
== '|')
299 for (I
++; I
!= Stop
&& isspace(*I
) != 0; I
++);