diff options
Diffstat (limited to 'cmdline/indexcopy.cc')
-rw-r--r-- | cmdline/indexcopy.cc | 90 |
1 files changed, 31 insertions, 59 deletions
diff --git a/cmdline/indexcopy.cc b/cmdline/indexcopy.cc index a8243c085..389d3c547 100644 --- a/cmdline/indexcopy.cc +++ b/cmdline/indexcopy.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: indexcopy.cc,v 1.5 2000/05/10 06:02:26 jgg Exp $ +// $Id: indexcopy.cc,v 1.6 2001/02/20 07:03:17 jgg Exp $ /* ###################################################################### Index Copying - Aid for copying and verifying the index files @@ -107,7 +107,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List) Pkg.Seek(0); } - pkgTagFile Parser(Pkg); + pkgTagFile Parser(&Pkg); if (_error->PendingError() == true) return false; @@ -119,9 +119,12 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List) TargetF += URItoFileName(S); if (_config->FindB("APT::CDROM::NoAct",false) == true) TargetF = "/dev/null"; - FileFd Target(TargetF,FileFd::WriteEmpty); + FileFd Target(TargetF,FileFd::WriteEmpty); + FILE *TargetFl = fdopen(dup(Target.Fd()),"w"); if (_error->PendingError() == true) return false; + if (TargetFl == 0) + return _error->Errno("fdopen","Failed to reopen fd"); // Setup the progress meter Progress.OverallProgress(CurrentSize,TotalSize,FileSize, @@ -140,7 +143,10 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List) string File; unsigned long Size; if (GetFile(File,Size) == false) + { + fclose(TargetFl); return false; + } if (Chop != 0) File = OrigPath + ChopDirs(File,Chop); @@ -202,21 +208,13 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List) Packages++; Hits++; - // Copy it to the target package file - if (Chop != 0 || Mangled == true) + if (RewriteEntry(TargetFl,File) == false) { - if (RewriteEntry(Target,File) == false) - continue; + fclose(TargetFl); + return false; } - else - { - const char *Start; - const char *Stop; - Section.GetSection(Start,Stop); - if (Target.Write(Start,Stop-Start) == false) - return false; - } } + fclose(TargetFl); if (Debug == true) cout << " Processed by using Prefix '" << Prefix << "' and chop " << Chop << endl; @@ -448,44 +446,6 @@ bool IndexCopy::GrabFirst(string Path,string &To,unsigned int Depth) return true; } /*}}}*/ -// IndexCopy::CopyWithReplace - Copy a section and replace text /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool IndexCopy::CopyWithReplace(FileFd &Target,const char *Tag,string New) -{ - // Mangle the output filename - const char *Start; - const char *Stop; - const char *Filename; - Section->Find(Tag,Filename,Stop); - - /* We need to rewrite the filename field so we emit - all fields except the filename file and rewrite that one */ - for (unsigned int I = 0; I != Section->Count(); I++) - { - Section->Get(Start,Stop,I); - if (Start <= Filename && Stop > Filename) - { - char S[500]; - sprintf(S,"%s: %s\n",Tag,New.c_str()); - if (I + 1 == Section->Count()) - strcat(S,"\n"); - if (Target.Write(S,strlen(S)) == false) - return false; - } - else - { - if (Target.Write(Start,Stop-Start) == false) - return false; - if (Stop[-1] != '\n') - if (Target.Write("\n",1) == false) - return false; - } - } - if (Target.Write("\n",1) == false) - return false; -} - /*}}}*/ // PackageCopy::GetFile - Get the file information from the section /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -501,9 +461,15 @@ bool PackageCopy::GetFile(string &File,unsigned long &Size) // PackageCopy::RewriteEntry - Rewrite the entry with a new filename /*{{{*/ // --------------------------------------------------------------------- /* */ -bool PackageCopy::RewriteEntry(FileFd &Target,string File) +bool PackageCopy::RewriteEntry(FILE *Target,string File) { - return CopyWithReplace(Target,"Filename",File); + TFRewriteData Changes[] = {{"Filename",File.c_str()}, + {}}; + + if (TFRewrite(Target,*Section,TFRewritePackageOrder,Changes) == false) + return false; + fputc('\n',Target); + return true; } /*}}}*/ // SourceCopy::GetFile - Get the file information from the section /*{{{*/ @@ -520,7 +486,7 @@ bool SourceCopy::GetFile(string &File,unsigned long &Size) if (Base.empty() == false && Base[Base.length()-1] != '/') Base += '/'; - // Iterate over the entire list grabbing each triplet + // Read the first file triplet const char *C = Files.c_str(); string sSize; string MD5Hash; @@ -540,9 +506,15 @@ bool SourceCopy::GetFile(string &File,unsigned long &Size) // SourceCopy::RewriteEntry - Rewrite the entry with a new filename /*{{{*/ // --------------------------------------------------------------------- /* */ -bool SourceCopy::RewriteEntry(FileFd &Target,string File) +bool SourceCopy::RewriteEntry(FILE *Target,string File) { - return CopyWithReplace(Target,"Directory", - string(File,0,File.rfind('/'))); + string Dir(File,0,File.rfind('/')); + TFRewriteData Changes[] = {{"Directory",Dir.c_str()}, + {}}; + + if (TFRewrite(Target,*Section,TFRewriteSourceOrder,Changes) == false) + return false; + fputc('\n',Target); + return true; } /*}}}*/ |