]> git.saurik.com Git - apt.git/blob - apt-pkg/indexcopy.cc
Merge branch 'debian/sid' into debian/experimental
[apt.git] / apt-pkg / indexcopy.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: indexcopy.cc,v 1.10 2002/03/26 07:38:58 jgg Exp $
4 /* ######################################################################
5
6 Index Copying - Aid for copying and verifying the index files
7
8 This class helps apt-cache reconstruct a damaged index files.
9
10 ##################################################################### */
11 /*}}}*/
12 // Include Files /*{{{*/
13 #include<config.h>
14
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/progress.h>
17 #include <apt-pkg/strutl.h>
18 #include <apt-pkg/fileutl.h>
19 #include <apt-pkg/aptconfiguration.h>
20 #include <apt-pkg/configuration.h>
21 #include <apt-pkg/tagfile.h>
22 #include <apt-pkg/indexrecords.h>
23 #include <apt-pkg/cdrom.h>
24 #include <apt-pkg/gpgv.h>
25 #include <apt-pkg/hashes.h>
26
27 #include <iostream>
28 #include <sstream>
29 #include <unistd.h>
30 #include <sys/stat.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "indexcopy.h"
36 #include <apti18n.h>
37 /*}}}*/
38
39 using namespace std;
40
41 // IndexCopy::CopyPackages - Copy the package files from the CD /*{{{*/
42 // ---------------------------------------------------------------------
43 /* */
44 bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
45 pkgCdromStatus *log)
46 {
47 OpProgress *Progress = NULL;
48 if (List.empty() == true)
49 return true;
50
51 if(log)
52 Progress = log->GetOpProgress();
53
54 bool NoStat = _config->FindB("APT::CDROM::Fast",false);
55 bool Debug = _config->FindB("Debug::aptcdrom",false);
56
57 // Prepare the progress indicator
58 off_t TotalSize = 0;
59 std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
60 for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
61 {
62 struct stat Buf;
63 bool found = false;
64 std::string file = std::string(*I).append(GetFileName());
65 for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
66 c != compressor.end(); ++c)
67 {
68 if (stat((file + c->Extension).c_str(), &Buf) != 0)
69 continue;
70 found = true;
71 break;
72 }
73
74 if (found == false)
75 return _error->Errno("stat", "Stat failed for %s", file.c_str());
76 TotalSize += Buf.st_size;
77 }
78
79 off_t CurrentSize = 0;
80 unsigned int NotFound = 0;
81 unsigned int WrongSize = 0;
82 unsigned int Packages = 0;
83 for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
84 {
85 string OrigPath = string(*I,CDROM.length());
86
87 // Open the package file
88 FileFd Pkg(*I + GetFileName(), FileFd::ReadOnly, FileFd::Auto);
89 off_t const FileSize = Pkg.Size();
90
91 pkgTagFile Parser(&Pkg);
92 if (_error->PendingError() == true)
93 return false;
94
95 // Open the output file
96 char S[400];
97 snprintf(S,sizeof(S),"cdrom:[%s]/%s%s",Name.c_str(),
98 (*I).c_str() + CDROM.length(),GetFileName());
99 string TargetF = _config->FindDir("Dir::State::lists") + "partial/";
100 TargetF += URItoFileName(S);
101 FileFd Target;
102 if (_config->FindB("APT::CDROM::NoAct",false) == true)
103 {
104 TargetF = "/dev/null";
105 Target.Open(TargetF,FileFd::WriteExists);
106 } else {
107 Target.Open(TargetF,FileFd::WriteAtomic);
108 }
109 if (_error->PendingError() == true)
110 return false;
111
112 // Setup the progress meter
113 if(Progress)
114 Progress->OverallProgress(CurrentSize,TotalSize,FileSize,
115 string("Reading ") + Type() + " Indexes");
116
117 // Parse
118 if(Progress)
119 Progress->SubProgress(Pkg.Size());
120 pkgTagSection Section;
121 this->Section = &Section;
122 string Prefix;
123 unsigned long Hits = 0;
124 unsigned long Chop = 0;
125 while (Parser.Step(Section) == true)
126 {
127 if(Progress)
128 Progress->Progress(Parser.Offset());
129 string File;
130 unsigned long long Size;
131 if (GetFile(File,Size) == false)
132 return false;
133
134 if (Chop != 0)
135 File = OrigPath + ChopDirs(File,Chop);
136
137 // See if the file exists
138 if (NoStat == false || Hits < 10)
139 {
140 // Attempt to fix broken structure
141 if (Hits == 0)
142 {
143 if (ReconstructPrefix(Prefix,OrigPath,CDROM,File) == false &&
144 ReconstructChop(Chop,*I,File) == false)
145 {
146 if (Debug == true)
147 clog << "Missed: " << File << endl;
148 NotFound++;
149 continue;
150 }
151 if (Chop != 0)
152 File = OrigPath + ChopDirs(File,Chop);
153 }
154
155 // Get the size
156 struct stat Buf;
157 if (stat((CDROM + Prefix + File).c_str(),&Buf) != 0 ||
158 Buf.st_size == 0)
159 {
160 bool Mangled = false;
161 // Attempt to fix busted symlink support for one instance
162 string OrigFile = File;
163 string::size_type Start = File.find("binary-");
164 string::size_type End = File.find("/",Start+3);
165 if (Start != string::npos && End != string::npos)
166 {
167 File.replace(Start,End-Start,"binary-all");
168 Mangled = true;
169 }
170
171 if (Mangled == false ||
172 stat((CDROM + Prefix + File).c_str(),&Buf) != 0)
173 {
174 if (Debug == true)
175 clog << "Missed(2): " << OrigFile << endl;
176 NotFound++;
177 continue;
178 }
179 }
180
181 // Size match
182 if ((unsigned long long)Buf.st_size != Size)
183 {
184 if (Debug == true)
185 clog << "Wrong Size: " << File << endl;
186 WrongSize++;
187 continue;
188 }
189 }
190
191 Packages++;
192 Hits++;
193
194 if (RewriteEntry(Target, File) == false)
195 return false;
196 }
197
198 if (Debug == true)
199 cout << " Processed by using Prefix '" << Prefix << "' and chop " << Chop << endl;
200
201 if (_config->FindB("APT::CDROM::NoAct",false) == false)
202 {
203 // Move out of the partial directory
204 Target.Close();
205 string FinalF = _config->FindDir("Dir::State::lists");
206 FinalF += URItoFileName(S);
207 if (rename(TargetF.c_str(),FinalF.c_str()) != 0)
208 return _error->Errno("rename","Failed to rename");
209 ChangeOwnerAndPermissionOfFile("CopyPackages", FinalF.c_str(), "root", "root", 0644);
210 }
211
212 /* Mangle the source to be in the proper notation with
213 prefix dist [component] */
214 *I = string(*I,Prefix.length());
215 ConvertToSourceList(CDROM,*I);
216 *I = Prefix + ' ' + *I;
217
218 CurrentSize += FileSize;
219 }
220 if(Progress)
221 Progress->Done();
222
223 // Some stats
224 if(log) {
225 stringstream msg;
226 if(NotFound == 0 && WrongSize == 0)
227 ioprintf(msg, _("Wrote %i records.\n"), Packages);
228 else if (NotFound != 0 && WrongSize == 0)
229 ioprintf(msg, _("Wrote %i records with %i missing files.\n"),
230 Packages, NotFound);
231 else if (NotFound == 0 && WrongSize != 0)
232 ioprintf(msg, _("Wrote %i records with %i mismatched files\n"),
233 Packages, WrongSize);
234 if (NotFound != 0 && WrongSize != 0)
235 ioprintf(msg, _("Wrote %i records with %i missing files and %i mismatched files\n"), Packages, NotFound, WrongSize);
236 }
237
238 if (Packages == 0)
239 _error->Warning("No valid records were found.");
240
241 if (NotFound + WrongSize > 10)
242 _error->Warning("A lot of entries were discarded, something may be wrong.\n");
243
244 return true;
245 }
246 /*}}}*/
247 // IndexCopy::ChopDirs - Chop off the leading directory components /*{{{*/
248 // ---------------------------------------------------------------------
249 /* */
250 string IndexCopy::ChopDirs(string Path,unsigned int Depth)
251 {
252 string::size_type I = 0;
253 do
254 {
255 I = Path.find('/',I+1);
256 Depth--;
257 }
258 while (I != string::npos && Depth != 0);
259
260 if (I == string::npos)
261 return string();
262
263 return string(Path,I+1);
264 }
265 /*}}}*/
266 // IndexCopy::ReconstructPrefix - Fix strange prefixing /*{{{*/
267 // ---------------------------------------------------------------------
268 /* This prepends dir components from the path to the package files to
269 the path to the deb until it is found */
270 bool IndexCopy::ReconstructPrefix(string &Prefix,string OrigPath,string CD,
271 string File)
272 {
273 bool Debug = _config->FindB("Debug::aptcdrom",false);
274 unsigned int Depth = 1;
275 string MyPrefix = Prefix;
276 while (1)
277 {
278 struct stat Buf;
279 if (stat((CD + MyPrefix + File).c_str(),&Buf) != 0)
280 {
281 if (Debug == true)
282 cout << "Failed, " << CD + MyPrefix + File << endl;
283 if (GrabFirst(OrigPath,MyPrefix,Depth++) == true)
284 continue;
285
286 return false;
287 }
288 else
289 {
290 Prefix = MyPrefix;
291 return true;
292 }
293 }
294 return false;
295 }
296 /*}}}*/
297 // IndexCopy::ReconstructChop - Fixes bad source paths /*{{{*/
298 // ---------------------------------------------------------------------
299 /* This removes path components from the filename and prepends the location
300 of the package files until a file is found */
301 bool IndexCopy::ReconstructChop(unsigned long &Chop,string Dir,string File)
302 {
303 // Attempt to reconstruct the filename
304 unsigned long Depth = 0;
305 while (1)
306 {
307 struct stat Buf;
308 if (stat((Dir + File).c_str(),&Buf) != 0)
309 {
310 File = ChopDirs(File,1);
311 Depth++;
312 if (File.empty() == false)
313 continue;
314 return false;
315 }
316 else
317 {
318 Chop = Depth;
319 return true;
320 }
321 }
322 return false;
323 }
324 /*}}}*/
325 // IndexCopy::ConvertToSourceList - Convert a Path to a sourcelist /*{{{*/
326 // ---------------------------------------------------------------------
327 /* We look for things in dists/ notation and convert them to
328 <dist> <component> form otherwise it is left alone. This also strips
329 the CD path.
330
331 This implements a regex sort of like:
332 (.*)/dists/([^/]*)/(.*)/binary-*
333 ^ ^ ^- Component
334 | |-------- Distribution
335 |------------------- Path
336
337 It was deciced to use only a single word for dist (rather than say
338 unstable/non-us) to increase the chance that each CD gets a single
339 line in sources.list.
340 */
341 void IndexCopy::ConvertToSourceList(string CD,string &Path)
342 {
343 // Strip the cdrom base path
344 Path = string(Path,CD.length());
345 if (Path.empty() == true)
346 Path = "/";
347
348 // Too short to be a dists/ type
349 if (Path.length() < strlen("dists/"))
350 return;
351
352 // Not a dists type.
353 if (stringcmp(Path.c_str(),Path.c_str()+strlen("dists/"),"dists/") != 0)
354 return;
355
356 // Isolate the dist
357 string::size_type Slash = strlen("dists/");
358 string::size_type Slash2 = Path.find('/',Slash + 1);
359 if (Slash2 == string::npos || Slash2 + 2 >= Path.length())
360 return;
361 string Dist = string(Path,Slash,Slash2 - Slash);
362
363 // Isolate the component
364 Slash = Slash2;
365 for (unsigned I = 0; I != 10; I++)
366 {
367 Slash = Path.find('/',Slash+1);
368 if (Slash == string::npos || Slash + 2 >= Path.length())
369 return;
370 string Comp = string(Path,Slash2+1,Slash - Slash2-1);
371
372 // Verify the trailing binary- bit
373 string::size_type BinSlash = Path.find('/',Slash + 1);
374 if (Slash == string::npos)
375 return;
376 string Binary = string(Path,Slash+1,BinSlash - Slash-1);
377
378 if (strncmp(Binary.c_str(), "binary-", strlen("binary-")) == 0)
379 {
380 Binary.erase(0, strlen("binary-"));
381 if (APT::Configuration::checkArchitecture(Binary) == false)
382 continue;
383 }
384 else if (Binary != "source")
385 continue;
386
387 Path = Dist + ' ' + Comp;
388 return;
389 }
390 }
391 /*}}}*/
392 // IndexCopy::GrabFirst - Return the first Depth path components /*{{{*/
393 // ---------------------------------------------------------------------
394 /* */
395 bool IndexCopy::GrabFirst(string Path,string &To,unsigned int Depth)
396 {
397 string::size_type I = 0;
398 do
399 {
400 I = Path.find('/',I+1);
401 Depth--;
402 }
403 while (I != string::npos && Depth != 0);
404
405 if (I == string::npos)
406 return false;
407
408 To = string(Path,0,I+1);
409 return true;
410 }
411 /*}}}*/
412 // PackageCopy::GetFile - Get the file information from the section /*{{{*/
413 // ---------------------------------------------------------------------
414 /* */
415 bool PackageCopy::GetFile(string &File,unsigned long long &Size)
416 {
417 File = Section->FindS("Filename");
418 Size = Section->FindI("Size");
419 if (File.empty() || Size == 0)
420 return _error->Error("Cannot find filename or size tag");
421 return true;
422 }
423 /*}}}*/
424 // PackageCopy::RewriteEntry - Rewrite the entry with a new filename /*{{{*/
425 bool PackageCopy::RewriteEntry(FileFd &Target,string const &File)
426 {
427 string const Dir(File,0,File.rfind('/'));
428 std::vector<pkgTagSection::Tag> Changes;
429 Changes.push_back(pkgTagSection::Tag::Rewrite("Filename", File));
430
431 if (Section->Write(Target, TFRewritePackageOrder, Changes) == false)
432 return false;
433 return Target.Write("\n", 1);
434 }
435 /*}}}*/
436 // SourceCopy::GetFile - Get the file information from the section /*{{{*/
437 // ---------------------------------------------------------------------
438 /* */
439 bool SourceCopy::GetFile(string &File,unsigned long long &Size)
440 {
441 string Files = Section->FindS("Files");
442 if (Files.empty() == true)
443 return false;
444
445 // Stash the / terminated directory prefix
446 string Base = Section->FindS("Directory");
447 if (Base.empty() == false && Base[Base.length()-1] != '/')
448 Base += '/';
449
450 // Read the first file triplet
451 const char *C = Files.c_str();
452 string sSize;
453 string MD5Hash;
454
455 // Parse each of the elements
456 if (ParseQuoteWord(C,MD5Hash) == false ||
457 ParseQuoteWord(C,sSize) == false ||
458 ParseQuoteWord(C,File) == false)
459 return _error->Error("Error parsing file record");
460
461 // Parse the size and append the directory
462 Size = strtoull(sSize.c_str(), NULL, 10);
463 File = Base + File;
464 return true;
465 }
466 /*}}}*/
467 // SourceCopy::RewriteEntry - Rewrite the entry with a new filename /*{{{*/
468 bool SourceCopy::RewriteEntry(FileFd &Target, std::string const &File)
469 {
470 string const Dir(File,0,File.rfind('/'));
471 std::vector<pkgTagSection::Tag> Changes;
472 Changes.push_back(pkgTagSection::Tag::Rewrite("Directory", Dir));
473
474 if (Section->Write(Target, TFRewriteSourceOrder, Changes) == false)
475 return false;
476 return Target.Write("\n", 1);
477 }
478 /*}}}*/
479 // SigVerify::Verify - Verify a files md5sum against its metaindex /*{{{*/
480 bool SigVerify::Verify(string prefix, string file, indexRecords *MetaIndex)
481 {
482 const indexRecords::checkSum *Record = MetaIndex->Lookup(file);
483 bool const Debug = _config->FindB("Debug::aptcdrom",false);
484
485 // we skip non-existing files in the verifcation of the Release file
486 // as non-existing files do not harm, but a warning scares people and
487 // makes it hard to strip unneeded files from an ISO like uncompressed
488 // indexes as it is done on the mirrors (see also LP: #255545 )
489 if(!RealFileExists(prefix+file))
490 {
491 if (Debug == true)
492 cout << "Skipping nonexistent in " << prefix << " file " << file << std::endl;
493 return true;
494 }
495
496 if (!Record)
497 {
498 _error->Warning(_("Can't find authentication record for: %s"), file.c_str());
499 return false;
500 }
501
502 if (!Record->Hashes.VerifyFile(prefix+file))
503 {
504 _error->Warning(_("Hash mismatch for: %s"),file.c_str());
505 return false;
506 }
507
508 if(Debug == true)
509 {
510 cout << "File: " << prefix+file << endl
511 << "Expected Hash " << endl;
512 for (HashStringList::const_iterator hs = Record->Hashes.begin(); hs != Record->Hashes.end(); ++hs)
513 std::cout << "\t- " << hs->toStr() << std::endl;
514 }
515
516 return true;
517 }
518 /*}}}*/
519 bool SigVerify::CopyMetaIndex(string CDROM, string CDName, /*{{{*/
520 string prefix, string file)
521 {
522 char S[400];
523 snprintf(S,sizeof(S),"cdrom:[%s]/%s%s",CDName.c_str(),
524 (prefix).c_str() + CDROM.length(),file.c_str());
525 string TargetF = _config->FindDir("Dir::State::lists");
526 TargetF += URItoFileName(S);
527
528 FileFd Target;
529 FileFd Rel;
530 Target.Open(TargetF,FileFd::WriteAtomic);
531 Rel.Open(prefix + file,FileFd::ReadOnly);
532 if (CopyFile(Rel,Target) == false || Target.Close() == false)
533 return _error->Error("Copying of '%s' for '%s' from '%s' failed", file.c_str(), CDName.c_str(), prefix.c_str());
534 ChangeOwnerAndPermissionOfFile("CopyPackages", TargetF.c_str(), "root", "root", 0644);
535
536 return true;
537 }
538 /*}}}*/
539 bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList, /*{{{*/
540 vector<string> /*PkgList*/,vector<string> /*SrcList*/)
541 {
542 if (SigList.empty() == true)
543 return true;
544
545 bool Debug = _config->FindB("Debug::aptcdrom",false);
546
547 // Read all Release files
548 for (vector<string>::iterator I = SigList.begin(); I != SigList.end(); ++I)
549 {
550 if(Debug)
551 cout << "Signature verify for: " << *I << endl;
552
553 indexRecords *MetaIndex = new indexRecords;
554 string prefix = *I;
555
556 string const releasegpg = *I+"Release.gpg";
557 string const release = *I+"Release";
558 string const inrelease = *I+"InRelease";
559 bool useInRelease = true;
560
561 // a Release.gpg without a Release should never happen
562 if (RealFileExists(inrelease) == true)
563 ;
564 else if(RealFileExists(release) == false || RealFileExists(releasegpg) == false)
565 {
566 delete MetaIndex;
567 continue;
568 }
569 else
570 useInRelease = false;
571
572 pid_t pid = ExecFork();
573 if(pid < 0) {
574 _error->Error("Fork failed");
575 return false;
576 }
577 if(pid == 0)
578 {
579 if (useInRelease == true)
580 ExecGPGV(inrelease, inrelease);
581 else
582 ExecGPGV(release, releasegpg);
583 }
584
585 if(!ExecWait(pid, "gpgv")) {
586 _error->Warning("Signature verification failed for: %s",
587 (useInRelease ? inrelease.c_str() : releasegpg.c_str()));
588 // something went wrong, don't copy the Release.gpg
589 // FIXME: delete any existing gpg file?
590 delete MetaIndex;
591 continue;
592 }
593
594 // Open the Release file and add it to the MetaIndex
595 if(!MetaIndex->Load(release))
596 {
597 _error->Error("%s",MetaIndex->ErrorText.c_str());
598 return false;
599 }
600
601 // go over the Indexfiles and see if they verify
602 // if so, remove them from our copy of the lists
603 vector<string> keys = MetaIndex->MetaKeys();
604 for (vector<string>::iterator I = keys.begin(); I != keys.end(); ++I)
605 {
606 if(!Verify(prefix,*I, MetaIndex)) {
607 // something went wrong, don't copy the Release.gpg
608 // FIXME: delete any existing gpg file?
609 _error->Discard();
610 continue;
611 }
612 }
613
614 // we need a fresh one for the Release.gpg
615 delete MetaIndex;
616
617 // everything was fine, copy the Release and Release.gpg file
618 if (useInRelease == true)
619 CopyMetaIndex(CDROM, Name, prefix, "InRelease");
620 else
621 {
622 CopyMetaIndex(CDROM, Name, prefix, "Release");
623 CopyMetaIndex(CDROM, Name, prefix, "Release.gpg");
624 }
625 }
626
627 return true;
628 }
629 /*}}}*/
630 // SigVerify::RunGPGV - deprecated wrapper calling ExecGPGV /*{{{*/
631 APT_NORETURN bool SigVerify::RunGPGV(std::string const &File, std::string const &FileOut,
632 int const &statusfd, int fd[2]) {
633 ExecGPGV(File, FileOut, statusfd, fd);
634 }
635 APT_NORETURN bool SigVerify::RunGPGV(std::string const &File, std::string const &FileOut,
636 int const &statusfd) {
637 ExecGPGV(File, FileOut, statusfd);
638 }
639 /*}}}*/
640 bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/
641 vector<string> &List, pkgCdromStatus *log)
642 {
643 OpProgress *Progress = NULL;
644 if (List.empty() == true)
645 return true;
646
647 if(log)
648 Progress = log->GetOpProgress();
649
650 bool Debug = _config->FindB("Debug::aptcdrom",false);
651
652 // Prepare the progress indicator
653 off_t TotalSize = 0;
654 std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
655 for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
656 {
657 struct stat Buf;
658 bool found = false;
659 std::string file = *I;
660 for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
661 c != compressor.end(); ++c)
662 {
663 if (stat((file + c->Extension).c_str(), &Buf) != 0)
664 continue;
665 found = true;
666 break;
667 }
668
669 if (found == false)
670 return _error->Errno("stat", "Stat failed for %s", file.c_str());
671 TotalSize += Buf.st_size;
672 }
673
674 off_t CurrentSize = 0;
675 unsigned int NotFound = 0;
676 unsigned int WrongSize = 0;
677 unsigned int Packages = 0;
678 for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
679 {
680 // Open the package file
681 FileFd Pkg(*I, FileFd::ReadOnly, FileFd::Auto);
682 off_t const FileSize = Pkg.Size();
683
684 pkgTagFile Parser(&Pkg);
685 if (_error->PendingError() == true)
686 return false;
687
688 // Open the output file
689 char S[400];
690 snprintf(S,sizeof(S),"cdrom:[%s]/%s",Name.c_str(),
691 (*I).c_str() + CDROM.length());
692 string TargetF = _config->FindDir("Dir::State::lists") + "partial/";
693 TargetF += URItoFileName(S);
694 FileFd Target;
695 if (_config->FindB("APT::CDROM::NoAct",false) == true)
696 {
697 TargetF = "/dev/null";
698 Target.Open(TargetF,FileFd::WriteExists);
699 } else {
700 Target.Open(TargetF,FileFd::WriteAtomic);
701 }
702 if (_error->PendingError() == true)
703 return false;
704
705 // Setup the progress meter
706 if(Progress)
707 Progress->OverallProgress(CurrentSize,TotalSize,FileSize,
708 string("Reading Translation Indexes"));
709
710 // Parse
711 if(Progress)
712 Progress->SubProgress(Pkg.Size());
713 pkgTagSection Section;
714 this->Section = &Section;
715 string Prefix;
716 unsigned long Hits = 0;
717 while (Parser.Step(Section) == true)
718 {
719 if(Progress)
720 Progress->Progress(Parser.Offset());
721
722 if (Section.Write(Target) == false || Target.Write("\n", 1) == false)
723 return false;
724
725 Packages++;
726 Hits++;
727 }
728
729 if (Debug == true)
730 cout << " Processed by using Prefix '" << Prefix << "' and chop " << endl;
731
732 if (_config->FindB("APT::CDROM::NoAct",false) == false)
733 {
734 // Move out of the partial directory
735 Target.Close();
736 string FinalF = _config->FindDir("Dir::State::lists");
737 FinalF += URItoFileName(S);
738 if (rename(TargetF.c_str(),FinalF.c_str()) != 0)
739 return _error->Errno("rename","Failed to rename");
740 ChangeOwnerAndPermissionOfFile("CopyTranslations", FinalF.c_str(), "root", "root", 0644);
741 }
742
743 CurrentSize += FileSize;
744 }
745 if(Progress)
746 Progress->Done();
747
748 // Some stats
749 if(log) {
750 stringstream msg;
751 if(NotFound == 0 && WrongSize == 0)
752 ioprintf(msg, _("Wrote %i records.\n"), Packages);
753 else if (NotFound != 0 && WrongSize == 0)
754 ioprintf(msg, _("Wrote %i records with %i missing files.\n"),
755 Packages, NotFound);
756 else if (NotFound == 0 && WrongSize != 0)
757 ioprintf(msg, _("Wrote %i records with %i mismatched files\n"),
758 Packages, WrongSize);
759 if (NotFound != 0 && WrongSize != 0)
760 ioprintf(msg, _("Wrote %i records with %i missing files and %i mismatched files\n"), Packages, NotFound, WrongSize);
761 }
762
763 if (Packages == 0)
764 _error->Warning("No valid records were found.");
765
766 if (NotFound + WrongSize > 10)
767 _error->Warning("A lot of entries were discarded, something may be wrong.\n");
768
769 return true;
770 }
771 /*}}}*/
772
773 APT_CONST IndexCopy::~IndexCopy() {}