diff options
author | Michael Vogt <mvo@debian.org> | 2005-10-17 14:20:25 +0000 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2005-10-17 14:20:25 +0000 |
commit | c511502fcec38680fff2f27aec75908e348e5905 (patch) | |
tree | 113bdb52474c1111110da47939342c9fd2994f1a /apt-pkg/indexcopy.cc | |
parent | 3226f06e15d6c9816c26e87bb58f5589b84a467b (diff) | |
parent | 422eeaaadf17904bf2f08cdf9e8998bec645097c (diff) |
* merged ddtp support
Patches applied:
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--base-0
tag of otavio@debian.org--2005/apt--ddtp--0.6--patch-14
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-1
* fixed a problem when it comes to the cache rebuilding
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-2
* try harder to get the correct language code
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-3
* fix for output of the description and the debTranslationsIndex::Exists()
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-4
* made the translation downloading work
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-5
* FindInCache() uses the correct file now
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-6
* don't throw any more warnings
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-7
* merged with otavoi
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-8
* merged with otavios branch
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-9
* code cleanups (thanks matt!), moved UsePackage before the description list build in pkgcachegen to catch MMap errors early
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-10
* added a BUGS file with known problem, added apt-cdrom support for translated package descriptions
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-11
* updated with mainline
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-12
* added README.ddtp
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-13
* merged with apt--mvo
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-14
* added DDTP::URL-Remap. KILL THIS FEATURE once ddtp support is offical
* michael.vogt@ubuntu.com--2005/apt--ddtp--0--patch-15
* remvoed the remap feature again, dosn't work anyway
* otavio@debian.org--2005/apt--ddtp--0.6--base-0
tag of apt@packages.debian.org/apt--main--0--patch-71
* otavio@debian.org--2005/apt--ddtp--0.6--patch-1
Port DDTP to APT 0.6 branch
* otavio@debian.org--2005/apt--ddtp--0.6--patch-2
Fix sintax error on apt-cache
* otavio@debian.org--2005/apt--ddtp--0.6--patch-3
Remove a unused var.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-4
Fix problems due APT and structural changes.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-5
Fix problems due APT and structural changes.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-6
Sync with apt@packages.debian.org/apt--main--0--patch-74
* otavio@debian.org--2005/apt--ddtp--0.6--patch-7
Sync with apt@packages.debian.org/apt--main--0--patch-75
* otavio@debian.org--2005/apt--ddtp--0.6--patch-8
Sync with apt--main--0--patch-76
* otavio@debian.org--2005/apt--ddtp--0.6--patch-9
Remote a changelog entry added by mistake while merging.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-10
Sync with apt--main--0--patch-78
* otavio@debian.org--2005/apt--ddtp--0.6--patch-11
Revert fixes changes to move these to apt--fixes--0 branch.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-12
Another fix included here by mistake. Moving it to apt--fixes--0 branch.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-13
Merge last changes from apt--main--0.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-14
Add FindInCache method to skip the rebuild of cache every time.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-15
Merge changes did by Michael Vogt to solve some rebuilding mistakes.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-16
Does't show Description twice
* otavio@debian.org--2005/apt--ddtp--0.6--patch-17
Merge last fixes did by Michael but preserve my version of apt-cache.cc fix.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-18
Revert changes did by mistake on translation files.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-19
Merge last changes did from upstream side.
* otavio@debian.org--2005/apt--ddtp--0.6--patch-20
Sync with apt--main--0--patch-87
Diffstat (limited to 'apt-pkg/indexcopy.cc')
-rw-r--r-- | apt-pkg/indexcopy.cc | 183 |
1 files changed, 180 insertions, 3 deletions
diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index 1f65062f7..c9dded134 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -32,6 +32,8 @@ using namespace std; + + // IndexCopy::CopyPackages - Copy the package files from the CD /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -512,10 +514,10 @@ bool SourceCopy::RewriteEntry(FILE *Target,string File) fputc('\n',Target); return true; } - - /*}}}*/ - +// SigVerify::Verify - Verify a files md5sum against its metaindex /*{{{*/ +// --------------------------------------------------------------------- +/* */ bool SigVerify::Verify(string prefix, string file, indexRecords *MetaIndex) { const indexRecords::checkSum *Record = MetaIndex->Lookup(file); @@ -670,3 +672,178 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList, return true; } + + +bool TranslationsCopy::CopyTranslations(string CDROM,string Name,vector<string> &List, + pkgCdromStatus *log) +{ + OpProgress *Progress = NULL; + if (List.size() == 0) + return true; + + if(log) + Progress = log->GetOpProgress(); + + bool Debug = _config->FindB("Debug::aptcdrom",false); + + // Prepare the progress indicator + unsigned long TotalSize = 0; + for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + { + struct stat Buf; + if (stat(string(*I).c_str(),&Buf) != 0 && + stat(string(*I + ".gz").c_str(),&Buf) != 0) + return _error->Errno("stat","Stat failed for %s", + string(*I).c_str()); + TotalSize += Buf.st_size; + } + + unsigned long CurrentSize = 0; + unsigned int NotFound = 0; + unsigned int WrongSize = 0; + unsigned int Packages = 0; + for (vector<string>::iterator I = List.begin(); I != List.end(); I++) + { + string OrigPath = string(*I,CDROM.length()); + unsigned long FileSize = 0; + + // Open the package file + FileFd Pkg; + if (FileExists(*I) == true) + { + Pkg.Open(*I,FileFd::ReadOnly); + FileSize = Pkg.Size(); + } + else + { + FileFd From(*I + ".gz",FileFd::ReadOnly); + if (_error->PendingError() == true) + return false; + FileSize = From.Size(); + + // Get a temp file + FILE *tmp = tmpfile(); + if (tmp == 0) + return _error->Errno("tmpfile","Unable to create a tmp file"); + Pkg.Fd(dup(fileno(tmp))); + fclose(tmp); + + // Fork gzip + pid_t Process = fork(); + if (Process < 0) + return _error->Errno("fork","Couldn't fork gzip"); + + // The child + if (Process == 0) + { + dup2(From.Fd(),STDIN_FILENO); + dup2(Pkg.Fd(),STDOUT_FILENO); + SetCloseExec(STDIN_FILENO,false); + SetCloseExec(STDOUT_FILENO,false); + + const char *Args[3]; + string Tmp = _config->Find("Dir::bin::gzip","gzip"); + Args[0] = Tmp.c_str(); + Args[1] = "-d"; + Args[2] = 0; + execvp(Args[0],(char **)Args); + exit(100); + } + + // Wait for gzip to finish + if (ExecWait(Process,_config->Find("Dir::bin::gzip","gzip").c_str(),false) == false) + return _error->Error("gzip failed, perhaps the disk is full."); + + Pkg.Seek(0); + } + pkgTagFile Parser(&Pkg); + if (_error->PendingError() == true) + return false; + + // Open the output file + char S[400]; + snprintf(S,sizeof(S),"cdrom:[%s]/%s",Name.c_str(), + (*I).c_str() + CDROM.length()); + string TargetF = _config->FindDir("Dir::State::lists") + "partial/"; + TargetF += URItoFileName(S); + if (_config->FindB("APT::CDROM::NoAct",false) == true) + TargetF = "/dev/null"; + 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 + if(Progress) + Progress->OverallProgress(CurrentSize,TotalSize,FileSize, + string("Reading Translation Indexes")); + + // Parse + if(Progress) + Progress->SubProgress(Pkg.Size()); + pkgTagSection Section; + this->Section = &Section; + string Prefix; + unsigned long Hits = 0; + unsigned long Chop = 0; + while (Parser.Step(Section) == true) + { + if(Progress) + Progress->Progress(Parser.Offset()); + + const char *Start; + const char *Stop; + Section.GetSection(Start,Stop); + fwrite(Start,Stop-Start, 1, TargetFl); + fputc('\n',TargetFl); + + Packages++; + Hits++; + } + fclose(TargetFl); + + if (Debug == true) + cout << " Processed by using Prefix '" << Prefix << "' and chop " << Chop << endl; + + if (_config->FindB("APT::CDROM::NoAct",false) == false) + { + // Move out of the partial directory + Target.Close(); + string FinalF = _config->FindDir("Dir::State::lists"); + FinalF += URItoFileName(S); + if (rename(TargetF.c_str(),FinalF.c_str()) != 0) + return _error->Errno("rename","Failed to rename"); + } + + + CurrentSize += FileSize; + } + if(Progress) + Progress->Done(); + + // Some stats + if(log) { + stringstream msg; + if(NotFound == 0 && WrongSize == 0) + ioprintf(msg, _("Wrote %i records.\n"), Packages); + else if (NotFound != 0 && WrongSize == 0) + ioprintf(msg, _("Wrote %i records with %i missing files.\n"), + Packages, NotFound); + else if (NotFound == 0 && WrongSize != 0) + ioprintf(msg, _("Wrote %i records with %i mismatched files\n"), + Packages, WrongSize); + if (NotFound != 0 && WrongSize != 0) + ioprintf(msg, _("Wrote %i records with %i missing files and %i mismatched files\n"), Packages, NotFound, WrongSize); + } + + if (Packages == 0) + _error->Warning("No valid records were found."); + + if (NotFound + WrongSize > 10) + _error->Warning("Alot of entries were discarded, something may be wrong.\n"); + + + return true; +} |