]>
git.saurik.com Git - apt.git/blob - ftparchive/apt-ftparchive.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-ftparchive.cc,v 1.6 2003/02/10 07:34:41 doogie Exp $
4 /* ######################################################################
6 apt-scanpackages - Efficient work-alike for dpkg-scanpackages
8 Let contents be disabled from the conf
10 ##################################################################### */
12 // Include Files /*{{{*/
14 #pragma implementation "apt-ftparchive.h"
17 #include "apt-ftparchive.h"
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/configuration.h>
21 #include <apt-pkg/cmndline.h>
22 #include <apt-pkg/strutl.h>
31 #include "multicompress.h"
39 ofstream
devnull("/dev/null");
42 // struct PackageMap - List of all package files in the config file /*{{{*/
43 // ---------------------------------------------------------------------
49 string InternalPrefix
;
54 // Stuff for the Package File
60 // Stuff for the Source File
63 string SrcExtraOverride
;
75 unsigned int DeLinkLimit
;
83 struct ContentsCompare
: public binary_function
<PackageMap
,PackageMap
,bool>
85 inline bool operator() (const PackageMap
&x
,const PackageMap
&y
)
86 {return x
.ContentsMTime
< y
.ContentsMTime
;};
89 struct DBCompare
: public binary_function
<PackageMap
,PackageMap
,bool>
91 inline bool operator() (const PackageMap
&x
,const PackageMap
&y
)
92 {return x
.BinCacheDB
< y
.BinCacheDB
;};
95 void GetGeneral(Configuration
&Setup
,Configuration
&Block
);
96 bool GenPackages(Configuration
&Setup
,struct CacheDB::Stats
&Stats
);
97 bool GenSources(Configuration
&Setup
,struct CacheDB::Stats
&Stats
);
98 bool GenContents(Configuration
&Setup
,
99 vector
<PackageMap
>::iterator Begin
,
100 vector
<PackageMap
>::iterator End
,
101 unsigned long &Left
);
103 PackageMap() : DeLinkLimit(0), Permissions(1), ContentsDone(false),
104 PkgDone(false), SrcDone(false), ContentsMTime(0) {};
108 // PackageMap::GetGeneral - Common per-section definitions /*{{{*/
109 // ---------------------------------------------------------------------
111 void PackageMap::GetGeneral(Configuration
&Setup
,Configuration
&Block
)
113 PathPrefix
= Block
.Find("PathPrefix");
115 if (Block
.FindB("External-Links",true) == false)
116 DeLinkLimit
= Setup
.FindI("Default::DeLinkLimit",UINT_MAX
);
120 PkgCompress
= Block
.Find("Packages::Compress",
121 Setup
.Find("Default::Packages::Compress",". gzip").c_str());
122 CntCompress
= Block
.Find("Contents::Compress",
123 Setup
.Find("Default::Contents::Compress",". gzip").c_str());
124 SrcCompress
= Block
.Find("Sources::Compress",
125 Setup
.Find("Default::Sources::Compress",". gzip").c_str());
127 SrcExt
= Block
.Find("Sources::Extensions",
128 Setup
.Find("Default::Sources::Extensions",".dsc").c_str());
129 PkgExt
= Block
.Find("Packages::Extensions",
130 Setup
.Find("Default::Packages::Extensions",".deb").c_str());
132 Permissions
= Setup
.FindI("Default::FileMode",0644);
134 if (FLFile
.empty() == false)
135 FLFile
= flCombine(Setup
.Find("Dir::FileListDir"),FLFile
);
141 // PackageMap::GenPackages - Actually generate a Package file /*{{{*/
142 // ---------------------------------------------------------------------
143 /* This generates the Package File described by this object. */
144 bool PackageMap::GenPackages(Configuration
&Setup
,struct CacheDB::Stats
&Stats
)
146 if (PkgFile
.empty() == true)
149 string ArchiveDir
= Setup
.FindDir("Dir::ArchiveDir");
150 string OverrideDir
= Setup
.FindDir("Dir::OverrideDir");
151 string CacheDir
= Setup
.FindDir("Dir::CacheDir");
153 struct timeval StartTime
;
154 gettimeofday(&StartTime
,0);
158 // Create a package writer object.
159 PackagesWriter
Packages(flCombine(CacheDir
,BinCacheDB
),
160 flCombine(OverrideDir
,BinOverride
),
161 flCombine(OverrideDir
,ExtraOverride
));
162 if (PkgExt
.empty() == false && Packages
.SetExts(PkgExt
) == false)
163 return _error
->Error(_("Package extension list is too long"));
164 if (_error
->PendingError() == true)
165 return _error
->Error(_("Error Processing directory %s"),BaseDir
.c_str());
167 Packages
.PathPrefix
= PathPrefix
;
168 Packages
.DirStrip
= ArchiveDir
;
169 Packages
.InternalPrefix
= flCombine(ArchiveDir
,InternalPrefix
);
171 Packages
.Stats
.DeLinkBytes
= Stats
.DeLinkBytes
;
172 Packages
.DeLinkLimit
= DeLinkLimit
;
174 // Create a compressor object
175 MultiCompress
Comp(flCombine(ArchiveDir
,PkgFile
),
176 PkgCompress
,Permissions
);
177 Packages
.Output
= Comp
.Input
;
178 if (_error
->PendingError() == true)
179 return _error
->Error(_("Error Processing directory %s"),BaseDir
.c_str());
181 c0out
<< ' ' << BaseDir
<< ":" << flush
;
183 // Do recursive directory searching
184 if (FLFile
.empty() == true)
186 if (Packages
.RecursiveScan(flCombine(ArchiveDir
,BaseDir
)) == false)
191 if (Packages
.LoadFileList(ArchiveDir
,FLFile
) == false)
195 Packages
.Output
= 0; // Just in case
197 // Finish compressing
199 if (Comp
.Finalize(Size
) == false)
202 return _error
->Error(_("Error Processing directory %s"),BaseDir
.c_str());
207 << SizeToStr(Size
) << "B ";
211 struct timeval NewTime
;
212 gettimeofday(&NewTime
,0);
213 double Delta
= NewTime
.tv_sec
- StartTime
.tv_sec
+
214 (NewTime
.tv_usec
- StartTime
.tv_usec
)/1000000.0;
216 c0out
<< Packages
.Stats
.Packages
<< " files " <<
217 /* SizeToStr(Packages.Stats.MD5Bytes) << "B/" << */
218 SizeToStr(Packages
.Stats
.Bytes
) << "B " <<
219 TimeToStr((long)Delta
) << endl
;
221 Stats
.Add(Packages
.Stats
);
222 Stats
.DeLinkBytes
= Packages
.Stats
.DeLinkBytes
;
224 return !_error
->PendingError();
227 // PackageMap::GenSources - Actually generate a Source file /*{{{*/
228 // ---------------------------------------------------------------------
229 /* This generates the Sources File described by this object. */
230 bool PackageMap::GenSources(Configuration
&Setup
,struct CacheDB::Stats
&Stats
)
232 if (SrcFile
.empty() == true)
235 string ArchiveDir
= Setup
.FindDir("Dir::ArchiveDir");
236 string OverrideDir
= Setup
.FindDir("Dir::OverrideDir");
237 string CacheDir
= Setup
.FindDir("Dir::CacheDir");
239 struct timeval StartTime
;
240 gettimeofday(&StartTime
,0);
244 // Create a package writer object.
245 SourcesWriter
Sources(flCombine(OverrideDir
,BinOverride
),
246 flCombine(OverrideDir
,SrcOverride
),
247 flCombine(OverrideDir
,SrcExtraOverride
));
248 if (SrcExt
.empty() == false && Sources
.SetExts(SrcExt
) == false)
249 return _error
->Error(_("Source extension list is too long"));
250 if (_error
->PendingError() == true)
251 return _error
->Error(_("Error Processing directory %s"),BaseDir
.c_str());
253 Sources
.PathPrefix
= PathPrefix
;
254 Sources
.DirStrip
= ArchiveDir
;
255 Sources
.InternalPrefix
= flCombine(ArchiveDir
,InternalPrefix
);
257 Sources
.DeLinkLimit
= DeLinkLimit
;
258 Sources
.Stats
.DeLinkBytes
= Stats
.DeLinkBytes
;
260 // Create a compressor object
261 MultiCompress
Comp(flCombine(ArchiveDir
,SrcFile
),
262 SrcCompress
,Permissions
);
263 Sources
.Output
= Comp
.Input
;
264 if (_error
->PendingError() == true)
265 return _error
->Error(_("Error Processing directory %s"),BaseDir
.c_str());
267 c0out
<< ' ' << BaseDir
<< ":" << flush
;
269 // Do recursive directory searching
270 if (FLFile
.empty() == true)
272 if (Sources
.RecursiveScan(flCombine(ArchiveDir
,BaseDir
))== false)
277 if (Sources
.LoadFileList(ArchiveDir
,FLFile
) == false)
280 Sources
.Output
= 0; // Just in case
282 // Finish compressing
284 if (Comp
.Finalize(Size
) == false)
287 return _error
->Error(_("Error Processing directory %s"),BaseDir
.c_str());
292 << SizeToStr(Size
) << "B ";
296 struct timeval NewTime
;
297 gettimeofday(&NewTime
,0);
298 double Delta
= NewTime
.tv_sec
- StartTime
.tv_sec
+
299 (NewTime
.tv_usec
- StartTime
.tv_usec
)/1000000.0;
301 c0out
<< Sources
.Stats
.Packages
<< " pkgs in " <<
302 TimeToStr((long)Delta
) << endl
;
304 Stats
.Add(Sources
.Stats
);
305 Stats
.DeLinkBytes
= Sources
.Stats
.DeLinkBytes
;
307 return !_error
->PendingError();
310 // PackageMap::GenContents - Actually generate a Contents file /*{{{*/
311 // ---------------------------------------------------------------------
312 /* This generates the contents file partially described by this object.
313 It searches the given iterator range for other package files that map
314 into this contents file and includes their data as well when building. */
315 bool PackageMap::GenContents(Configuration
&Setup
,
316 vector
<PackageMap
>::iterator Begin
,
317 vector
<PackageMap
>::iterator End
,
320 if (Contents
.empty() == true)
326 string ArchiveDir
= Setup
.FindDir("Dir::ArchiveDir");
327 string CacheDir
= Setup
.FindDir("Dir::CacheDir");
328 string OverrideDir
= Setup
.FindDir("Dir::OverrideDir");
330 struct timeval StartTime
;
331 gettimeofday(&StartTime
,0);
333 // Create a package writer object.
334 ContentsWriter
Contents("");
335 if (PkgExt
.empty() == false && Contents
.SetExts(PkgExt
) == false)
336 return _error
->Error(_("Package extension list is too long"));
337 if (_error
->PendingError() == true)
340 MultiCompress
Comp(flCombine(ArchiveDir
,this->Contents
),
341 CntCompress
,Permissions
);
342 Comp
.UpdateMTime
= Setup
.FindI("Default::ContentsAge",10)*24*60*60;
343 Contents
.Output
= Comp
.Input
;
344 if (_error
->PendingError() == true)
347 // Write the header out.
348 if (ContentsHead
.empty() == false)
350 FileFd
Head(flCombine(OverrideDir
,ContentsHead
),FileFd::ReadOnly
);
351 if (_error
->PendingError() == true)
354 unsigned long Size
= Head
.Size();
355 unsigned char Buf
[4096];
358 unsigned long ToRead
= Size
;
359 if (Size
> sizeof(Buf
))
360 ToRead
= sizeof(Buf
);
362 if (Head
.Read(Buf
,ToRead
) == false)
365 if (fwrite(Buf
,1,ToRead
,Comp
.Input
) != ToRead
)
366 return _error
->Errno("fwrite",_("Error writing header to contents file"));
372 /* Go over all the package file records and parse all the package
373 files associated with this contents file into one great big honking
374 memory structure, then dump the sorted version */
375 c0out
<< ' ' << this->Contents
<< ":" << flush
;
376 for (vector
<PackageMap
>::iterator I
= Begin
; I
!= End
; I
++)
378 if (I
->Contents
!= this->Contents
)
381 Contents
.Prefix
= ArchiveDir
;
382 Contents
.ReadyDB(flCombine(CacheDir
,I
->BinCacheDB
));
383 Contents
.ReadFromPkgs(flCombine(ArchiveDir
,I
->PkgFile
),
386 I
->ContentsDone
= true;
391 // Finish compressing
393 if (Comp
.Finalize(Size
) == false || _error
->PendingError() == true)
396 return _error
->Error(_("Error Processing Contents %s"),
397 this->Contents
.c_str());
402 c0out
<< " New " << SizeToStr(Size
) << "B ";
411 struct timeval NewTime
;
412 gettimeofday(&NewTime
,0);
413 double Delta
= NewTime
.tv_sec
- StartTime
.tv_sec
+
414 (NewTime
.tv_usec
- StartTime
.tv_usec
)/1000000.0;
416 c0out
<< Contents
.Stats
.Packages
<< " files " <<
417 SizeToStr(Contents
.Stats
.Bytes
) << "B " <<
418 TimeToStr((long)Delta
) << endl
;
424 // LoadTree - Load a 'tree' section from the Generate Config /*{{{*/
425 // ---------------------------------------------------------------------
426 /* This populates the PkgList with all the possible permutations of the
427 section/arch lists. */
428 void LoadTree(vector
<PackageMap
> &PkgList
,Configuration
&Setup
)
431 string DDir
= Setup
.Find("TreeDefault::Directory",
432 "$(DIST)/$(SECTION)/binary-$(ARCH)/");
433 string DSDir
= Setup
.Find("TreeDefault::SrcDirectory",
434 "$(DIST)/$(SECTION)/source/");
435 string DPkg
= Setup
.Find("TreeDefault::Packages",
436 "$(DIST)/$(SECTION)/binary-$(ARCH)/Packages");
437 string DIPrfx
= Setup
.Find("TreeDefault::InternalPrefix",
438 "$(DIST)/$(SECTION)/");
439 string DContents
= Setup
.Find("TreeDefault::Contents",
440 "$(DIST)/Contents-$(ARCH)");
441 string DContentsH
= Setup
.Find("TreeDefault::Contents::Header","");
442 string DBCache
= Setup
.Find("TreeDefault::BinCacheDB",
443 "packages-$(ARCH).db");
444 string DSources
= Setup
.Find("TreeDefault::Sources",
445 "$(DIST)/$(SECTION)/source/Sources");
446 string DFLFile
= Setup
.Find("TreeDefault::FileList", "");
447 string DSFLFile
= Setup
.Find("TreeDefault::SourceFileList", "");
449 // Process 'tree' type sections
450 const Configuration::Item
*Top
= Setup
.Tree("tree");
451 for (Top
= (Top
== 0?0:Top
->Child
); Top
!= 0;)
453 Configuration
Block(Top
);
454 string Dist
= Top
->Tag
;
456 // Parse the sections
457 string Tmp
= Block
.Find("Sections");
458 const char *Sections
= Tmp
.c_str();
460 while (ParseQuoteWord(Sections
,Section
) == true)
462 string Tmp2
= Block
.Find("Architectures");
464 const char *Archs
= Tmp2
.c_str();
465 while (ParseQuoteWord(Archs
,Arch
) == true)
467 struct SubstVar Vars
[] = {{"$(DIST)",&Dist
},
468 {"$(SECTION)",&Section
},
473 Itm
.BinOverride
= SubstVar(Block
.Find("BinOverride"),Vars
);
474 Itm
.InternalPrefix
= SubstVar(Block
.Find("InternalPrefix",DIPrfx
.c_str()),Vars
);
476 if (stringcasecmp(Arch
,"source") == 0)
478 Itm
.SrcOverride
= SubstVar(Block
.Find("SrcOverride"),Vars
);
479 Itm
.BaseDir
= SubstVar(Block
.Find("SrcDirectory",DSDir
.c_str()),Vars
);
480 Itm
.SrcFile
= SubstVar(Block
.Find("Sources",DSources
.c_str()),Vars
);
481 Itm
.Tag
= SubstVar("$(DIST)/$(SECTION)/source",Vars
);
482 Itm
.FLFile
= SubstVar(Block
.Find("SourceFileList",DSFLFile
.c_str()),Vars
);
483 Itm
.SrcExtraOverride
= SubstVar(Block
.Find("SrcExtraOverride"),Vars
);
487 Itm
.BinCacheDB
= SubstVar(Block
.Find("BinCacheDB",DBCache
.c_str()),Vars
);
488 Itm
.BaseDir
= SubstVar(Block
.Find("Directory",DDir
.c_str()),Vars
);
489 Itm
.PkgFile
= SubstVar(Block
.Find("Packages",DPkg
.c_str()),Vars
);
490 Itm
.Tag
= SubstVar("$(DIST)/$(SECTION)/$(ARCH)",Vars
);
491 Itm
.Contents
= SubstVar(Block
.Find("Contents",DContents
.c_str()),Vars
);
492 Itm
.ContentsHead
= SubstVar(Block
.Find("Contents::Header",DContentsH
.c_str()),Vars
);
493 Itm
.FLFile
= SubstVar(Block
.Find("FileList",DFLFile
.c_str()),Vars
);
494 Itm
.ExtraOverride
= SubstVar(Block
.Find("ExtraOverride"),Vars
);
497 Itm
.GetGeneral(Setup
,Block
);
498 PkgList
.push_back(Itm
);
506 // LoadBinDir - Load a 'bindirectory' section from the Generate Config /*{{{*/
507 // ---------------------------------------------------------------------
509 void LoadBinDir(vector
<PackageMap
> &PkgList
,Configuration
&Setup
)
511 // Process 'bindirectory' type sections
512 const Configuration::Item
*Top
= Setup
.Tree("bindirectory");
513 for (Top
= (Top
== 0?0:Top
->Child
); Top
!= 0;)
515 Configuration
Block(Top
);
518 Itm
.PkgFile
= Block
.Find("Packages");
519 Itm
.SrcFile
= Block
.Find("Sources");
520 Itm
.BinCacheDB
= Block
.Find("BinCacheDB");
521 Itm
.BinOverride
= Block
.Find("BinOverride");
522 Itm
.ExtraOverride
= Block
.Find("ExtraOverride");
523 Itm
.SrcExtraOverride
= Block
.Find("SrcExtraOverride");
524 Itm
.SrcOverride
= Block
.Find("SrcOverride");
525 Itm
.BaseDir
= Top
->Tag
;
526 Itm
.FLFile
= Block
.Find("FileList");
527 Itm
.InternalPrefix
= Block
.Find("InternalPrefix",Top
->Tag
.c_str());
528 Itm
.Contents
= Block
.Find("Contents");
529 Itm
.ContentsHead
= Block
.Find("Contents::Header");
531 Itm
.GetGeneral(Setup
,Block
);
532 PkgList
.push_back(Itm
);
539 // ShowHelp - Show the help text /*{{{*/
540 // ---------------------------------------------------------------------
542 bool ShowHelp(CommandLine
&CmdL
)
544 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
545 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
546 if (_config
->FindB("version") == true)
550 _("Usage: apt-ftparchive [options] command\n"
551 "Commands: packges binarypath [overridefile [pathprefix]]\n"
552 " sources srcpath [overridefile [pathprefix]]\n"
554 " generate config [groups]\n"
557 "apt-ftparchive generates index files for Debian archives. It supports\n"
558 "many styles of generation from fully automated to functional replacements\n"
559 "for dpkg-scanpackages and dpkg-scansources\n"
561 "apt-ftparchive generates Package files from a tree of .debs. The\n"
562 "Package file contains the contents of all the control fields from\n"
563 "each package as well as the MD5 hash and filesize. An override file\n"
564 "is supported to force the value of Priority and Section.\n"
566 "Similarly apt-ftparchive generates Sources files from a tree of .dscs.\n"
567 "The --source-override option can be used to specify a src override file\n"
569 "The 'packages' and 'sources' command should be run in the root of the\n"
570 "tree. BinaryPath should point to the base of the recursive search and \n"
571 "override file should contian the override flags. Pathprefix is\n"
572 "appended to the filename fields if present. Example usage from the \n"
574 " apt-ftparchive packages dists/potato/main/binary-i386/ > \\\n"
575 " dists/potato/main/binary-i386/Packages\n"
578 " -h This help text\n"
579 " --md5 Control MD5 generation\n"
580 " -s=? Source override file\n"
582 " -d=? Select the optional caching database\n"
583 " --no-delink Enable delinking debug mode\n"
584 " --contents Control contents file generation\n"
585 " -c=? Read this configuration file\n"
586 " -o=? Set an arbitary configuration option") << endl
;
591 // SimpleGenPackages - Generate a Packages file for a directory tree /*{{{*/
592 // ---------------------------------------------------------------------
593 /* This emulates dpkg-scanpackages's command line interface. 'mostly' */
594 bool SimpleGenPackages(CommandLine
&CmdL
)
596 if (CmdL
.FileSize() < 2)
597 return ShowHelp(CmdL
);
600 if (CmdL
.FileSize() >= 3)
601 Override
= CmdL
.FileList
[2];
603 // Create a package writer object.
604 PackagesWriter
Packages(_config
->Find("APT::FTPArchive::DB"),
606 if (_error
->PendingError() == true)
609 if (CmdL
.FileSize() >= 4)
610 Packages
.PathPrefix
= CmdL
.FileList
[3];
612 // Do recursive directory searching
613 if (Packages
.RecursiveScan(CmdL
.FileList
[1]) == false)
619 // SimpleGenContents - Generate a Contents listing /*{{{*/
620 // ---------------------------------------------------------------------
622 bool SimpleGenContents(CommandLine
&CmdL
)
624 if (CmdL
.FileSize() < 2)
625 return ShowHelp(CmdL
);
627 // Create a package writer object.
628 ContentsWriter
Contents(_config
->Find("APT::FTPArchive::DB"));
629 if (_error
->PendingError() == true)
632 // Do recursive directory searching
633 if (Contents
.RecursiveScan(CmdL
.FileList
[1]) == false)
641 // SimpleGenSources - Generate a Sources file for a directory tree /*{{{*/
642 // ---------------------------------------------------------------------
643 /* This emulates dpkg-scanpackages's command line interface. 'mostly' */
644 bool SimpleGenSources(CommandLine
&CmdL
)
646 if (CmdL
.FileSize() < 2)
647 return ShowHelp(CmdL
);
650 if (CmdL
.FileSize() >= 3)
651 Override
= CmdL
.FileList
[2];
654 if (Override
.empty() == false)
655 SOverride
= Override
+ ".src";
657 SOverride
= _config
->Find("APT::FTPArchive::SourceOverride",
660 // Create a package writer object.
661 SourcesWriter
Sources(Override
,SOverride
);
662 if (_error
->PendingError() == true)
665 if (CmdL
.FileSize() >= 4)
666 Sources
.PathPrefix
= CmdL
.FileList
[3];
668 // Do recursive directory searching
669 if (Sources
.RecursiveScan(CmdL
.FileList
[1]) == false)
675 // Generate - Full generate, using a config file /*{{{*/
676 // ---------------------------------------------------------------------
678 bool Generate(CommandLine
&CmdL
)
680 struct CacheDB::Stats SrcStats
;
681 if (CmdL
.FileSize() < 2)
682 return ShowHelp(CmdL
);
684 struct timeval StartTime
;
685 gettimeofday(&StartTime
,0);
686 struct CacheDB::Stats Stats
;
688 // Read the configuration file.
690 if (ReadConfigFile(Setup
,CmdL
.FileList
[1],true) == false)
693 vector
<PackageMap
> PkgList
;
694 LoadTree(PkgList
,Setup
);
695 LoadBinDir(PkgList
,Setup
);
697 // Sort by cache DB to improve IO locality.
698 stable_sort(PkgList
.begin(),PkgList
.end(),PackageMap::DBCompare());
701 if (CmdL
.FileSize() <= 2)
703 for (vector
<PackageMap
>::iterator I
= PkgList
.begin(); I
!= PkgList
.end(); I
++)
704 if (I
->GenPackages(Setup
,Stats
) == false)
705 _error
->DumpErrors();
706 for (vector
<PackageMap
>::iterator I
= PkgList
.begin(); I
!= PkgList
.end(); I
++)
707 if (I
->GenSources(Setup
,SrcStats
) == false)
708 _error
->DumpErrors();
712 // Make a choice list out of the package list..
713 RxChoiceList
*List
= new RxChoiceList
[2*PkgList
.size()+1];
714 RxChoiceList
*End
= List
;
715 for (vector
<PackageMap
>::iterator I
= PkgList
.begin(); I
!= PkgList
.end(); I
++)
717 End
->UserData
= &(*I
);
718 End
->Str
= I
->BaseDir
.c_str();
721 End
->UserData
= &(*I
);
722 End
->Str
= I
->Tag
.c_str();
728 if (RegexChoice(List
,CmdL
.FileList
+ 2,CmdL
.FileList
+ CmdL
.FileSize()) == 0)
731 return _error
->Error(_("No selections matched"));
733 _error
->DumpErrors();
735 // Do the generation for Packages
736 for (End
= List
; End
->Str
!= 0; End
++)
738 if (End
->Hit
== false)
741 PackageMap
*I
= (PackageMap
*)End
->UserData
;
742 if (I
->PkgDone
== true)
744 if (I
->GenPackages(Setup
,Stats
) == false)
745 _error
->DumpErrors();
748 // Do the generation for Sources
749 for (End
= List
; End
->Str
!= 0; End
++)
751 if (End
->Hit
== false)
754 PackageMap
*I
= (PackageMap
*)End
->UserData
;
755 if (I
->SrcDone
== true)
757 if (I
->GenSources(Setup
,SrcStats
) == false)
758 _error
->DumpErrors();
764 if (_config
->FindB("APT::FTPArchive::Contents",true) == false)
767 c1out
<< "Done Packages, Starting contents." << endl
;
769 // Sort the contents file list by date
770 string ArchiveDir
= Setup
.FindDir("Dir::ArchiveDir");
771 for (vector
<PackageMap
>::iterator I
= PkgList
.begin(); I
!= PkgList
.end(); I
++)
774 if (MultiCompress::GetStat(flCombine(ArchiveDir
,I
->Contents
),
775 I
->CntCompress
,A
) == false)
776 time(&I
->ContentsMTime
);
778 I
->ContentsMTime
= A
.st_mtime
;
780 stable_sort(PkgList
.begin(),PkgList
.end(),PackageMap::ContentsCompare());
782 /* Now for Contents.. The process here is to do a make-like dependency
783 check. Each contents file is verified to be newer than the package files
784 that describe the debs it indexes. Since the package files contain
785 hashes of the .debs this means they have not changed either so the
786 contents must be up to date. */
787 unsigned long MaxContentsChange
= Setup
.FindI("Default::MaxContentsChange",UINT_MAX
)*1024;
788 for (vector
<PackageMap
>::iterator I
= PkgList
.begin(); I
!= PkgList
.end(); I
++)
790 // This record is not relevent
791 if (I
->ContentsDone
== true ||
792 I
->Contents
.empty() == true)
795 // Do not do everything if the user specified sections.
796 if (CmdL
.FileSize() > 2 && I
->PkgDone
== false)
800 if (MultiCompress::GetStat(flCombine(ArchiveDir
,I
->Contents
),I
->CntCompress
,A
) == true)
802 if (MultiCompress::GetStat(flCombine(ArchiveDir
,I
->PkgFile
),I
->PkgCompress
,B
) == false)
804 _error
->Warning(_("Some files are missing in the package file group `%s'"),I
->PkgFile
.c_str());
808 if (A
.st_mtime
> B
.st_mtime
)
812 if (I
->GenContents(Setup
,PkgList
.begin(),PkgList
.end(),
813 MaxContentsChange
) == false)
814 _error
->DumpErrors();
817 if (MaxContentsChange
== 0)
819 c1out
<< "Hit contents update byte limit" << endl
;
824 struct timeval NewTime
;
825 gettimeofday(&NewTime
,0);
826 double Delta
= NewTime
.tv_sec
- StartTime
.tv_sec
+
827 (NewTime
.tv_usec
- StartTime
.tv_usec
)/1000000.0;
828 c1out
<< "Done. " << SizeToStr(Stats
.Bytes
) << "B in " << Stats
.Packages
829 << " archives. Took " << TimeToStr((long)Delta
) << endl
;
834 // Clean - Clean out the databases /*{{{*/
835 // ---------------------------------------------------------------------
837 bool Clean(CommandLine
&CmdL
)
839 if (CmdL
.FileSize() != 2)
840 return ShowHelp(CmdL
);
842 // Read the configuration file.
844 if (ReadConfigFile(Setup
,CmdL
.FileList
[1],true) == false)
847 vector
<PackageMap
> PkgList
;
848 LoadTree(PkgList
,Setup
);
849 LoadBinDir(PkgList
,Setup
);
851 // Sort by cache DB to improve IO locality.
852 stable_sort(PkgList
.begin(),PkgList
.end(),PackageMap::DBCompare());
854 string CacheDir
= Setup
.FindDir("Dir::CacheDir");
856 for (vector
<PackageMap
>::iterator I
= PkgList
.begin(); I
!= PkgList
.end(); )
858 c0out
<< I
->BinCacheDB
<< endl
;
859 CacheDB
DB(flCombine(CacheDir
,I
->BinCacheDB
));
860 if (DB
.Clean() == false)
861 _error
->DumpErrors();
863 string CacheDB
= I
->BinCacheDB
;
864 for (; I
!= PkgList
.end() && I
->BinCacheDB
== CacheDB
; I
++);
871 int main(int argc
, const char *argv
[])
873 CommandLine::Args Args
[] = {
874 {'h',"help","help",0},
875 {0,"md5","APT::FTPArchive::MD5",0},
876 {'v',"version","version",0},
877 {'d',"db","APT::FTPArchive::DB",CommandLine::HasArg
},
878 {'s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg
},
879 {'q',"quiet","quiet",CommandLine::IntLevel
},
880 {'q',"silent","quiet",CommandLine::IntLevel
},
881 {0,"delink","APT::FTPArchive::DeLinkAct",0},
882 {0,"readonly","APT::FTPArchive::ReadOnlyDB",0},
883 {0,"contents","APT::FTPArchive::Contents",0},
884 {'c',"config-file",0,CommandLine::ConfigFile
},
885 {'o',"option",0,CommandLine::ArbItem
},
887 CommandLine::Dispatch Cmds
[] = {{"packages",&SimpleGenPackages
},
888 {"contents",&SimpleGenContents
},
889 {"sources",&SimpleGenSources
},
890 {"generate",&Generate
},
895 // Parse the command line and initialize the package library
896 CommandLine
CmdL(Args
,_config
);
897 if (CmdL
.Parse(argc
,argv
) == false)
899 _error
->DumpErrors();
903 // See if the help should be shown
904 if (_config
->FindB("help") == true ||
905 _config
->FindB("version") == true ||
906 CmdL
.FileSize() == 0)
912 // Setup the output streams
913 c0out
.rdbuf(clog
.rdbuf());
914 c1out
.rdbuf(clog
.rdbuf());
915 c2out
.rdbuf(clog
.rdbuf());
916 Quiet
= _config
->FindI("quiet",0);
918 c0out
.rdbuf(devnull
.rdbuf());
920 c1out
.rdbuf(devnull
.rdbuf());
922 // Match the operation
923 CmdL
.DispatchArg(Cmds
);
925 if (_error
->empty() == false)
927 bool Errors
= _error
->PendingError();
928 _error
->DumpErrors();
929 return Errors
== true?100:0;