--- synaptic-0.36.1/common/rsources.cc.sourcepart 2003-03-10 22:40:22.000000000 +0200 +++ synaptic-0.36.1/common/rsources.cc 2003-04-24 21:28:15.000000000 +0300 @@ -1,5 +1,9 @@ +#include <sys/stat.h> +#include <dirent.h> + #include "rsources.h" #include <apt-pkg/configuration.h> +#include <apt-pkg/fileutl.h> #include <apt-pkg/sourcelist.h> #include <apt-pkg/strutl.h> #include <apt-pkg/error.h> @@ -26,15 +30,13 @@ return newrec; } -bool SourcesList::ReadSources() +bool SourcesList::ReadSourcePart(string listpath) { char buf[512]; const char *p; - - ifstream ifs(_config->FindFile("Dir::Etc::sourcelist").c_str(), ios::in ); + ifstream ifs(listpath.c_str(), ios::in ); // cannot open file - if (!ifs != 0) return _error->Error(_("Can't read "), - _config->FindFile("Dir::Etc::sourcelist").c_str()); + if (!ifs != 0) return _error->Error(_("Can't read "), listpath.c_str()); while (ifs.eof() == false) { p = buf; @@ -45,6 +47,7 @@ ifs.getline(buf, sizeof(buf)); + rec.SourceFile = listpath; while (isspace(*p)) p++; if (*p == '#') { rec.Type = Disabled; @@ -113,7 +116,6 @@ while (ParseQuoteWord(p, Section) == true) rec.Sections[rec.NumSections++] = Section; } - AddSourceNode(rec); } @@ -121,11 +123,72 @@ return true; } -SourcesList::SourceRecord *SourcesList::AddSource(RecType Type, string VendorID, string URI, string Dist, string *Sections, unsigned short count) +bool SourcesList::ReadSourceDir(string Dir) +{ + DIR *D = opendir(Dir.c_str()); + if (D == 0) + return _error->Errno("opendir",_("Unable to read "),Dir.c_str()); + + vector<string> List; + + for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) + { + if (Ent->d_name[0] == '.') + continue; + + // Skip bad file names ala run-parts + const char *C = Ent->d_name; + for (; *C != 0; C++) + if (isalpha(*C) == 0 && isdigit(*C) == 0 + && *C != '_' && *C != '-' && *C != '.') + break; + if (*C != 0) + continue; + + // Only look at files ending in .list to skip .rpmnew etc files + if (strcmp(Ent->d_name+strlen(Ent->d_name)-5, ".list") != 0) + continue; + + // Make sure it is a file and not something else + string File = flCombine(Dir,Ent->d_name); + struct stat St; + if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0) + continue; + + List.push_back(File); + } + closedir(D); + + sort(List.begin(),List.end()); + + // Read the files + for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++) + if (ReadSourcePart(*I) == false) + return false; + return true; +} + + +bool SourcesList::ReadSources() +{ + bool Res = true; + + string Parts = _config->FindDir("Dir::Etc::sourceparts"); + if (FileExists(Parts) == true) + Res &= ReadSourceDir(Parts); + string Main = _config->FindFile("Dir::Etc::sourcelist"); + if (FileExists(Main) == true) + Res &= ReadSourcePart(Main); + + return Res; +} + +SourcesList::SourceRecord *SourcesList::AddSource(RecType Type, string VendorID, string URI, string Dist, string *Sections, unsigned short count, string SourceFile) { SourceRecord rec; rec.Type = Type; rec.VendorID = VendorID; + rec.SourceFile = SourceFile; if (rec.SetURI(URI) == false) { return NULL; @@ -148,36 +211,51 @@ bool SourcesList::UpdateSources() { - ofstream ofs(_config->FindFile("Dir::Etc::sourcelist").c_str(), ios::out); - if (!ofs != 0) return false; + list<string> filenames; + for(list<SourceRecord*>::iterator it = SourceRecords.begin(); + it != SourceRecords.end(); it++) + { + if ((*it)->SourceFile == "") continue; + filenames.push_front((*it)->SourceFile); + } + filenames.sort(); + filenames.unique(); - for(list<SourceRecord*>::iterator it = SourceRecords.begin(); - it != SourceRecords.end(); it++) + for(list<string>::iterator fi = filenames.begin(); fi != filenames.end(); fi++) + { + ofstream ofs((*fi).c_str(), ios::out); + if (!ofs != 0) return false; + + for(list<SourceRecord*>::iterator it = SourceRecords.begin(); + it != SourceRecords.end(); it++) { - string S; - if (((*it)->Type & Comment) != 0) { - S = (*it)->Comment; - } else { - if (((*it)->Type & Disabled) != 0) - S = "# "; - - S += (*it)->GetType() + " "; - - if ((*it)->VendorID.empty() == false) { - S += "[" + (*it)->VendorID + "] "; - } - - S += (*it)->URI + " "; - S += (*it)->Dist + " "; - - for (unsigned int J = 0; J < (*it)->NumSections; J++) - S += (*it)->Sections[J] + " "; - } - ofs << S << endl; + if ((*fi) != (*it)->SourceFile) { + continue; + } + string S; + if (((*it)->Type & Comment) != 0) { + S = (*it)->Comment; + } else { + if (((*it)->Type & Disabled) != 0) + S = "# "; + + S += (*it)->GetType() + " "; + + if ((*it)->VendorID.empty() == false) { + S += "[" + (*it)->VendorID + "] "; + } + + S += (*it)->URI + " "; + S += (*it)->Dist + " "; + + for (unsigned int J = 0; J < (*it)->NumSections; J++) + S += (*it)->Sections[J] + " "; + } + ofs << S << endl; + } + ofs.close(); } - - ofs.close(); - return true; + return true; } bool SourcesList::SourceRecord::SetType(string S) @@ -234,6 +312,7 @@ Sections[I] = rhs.Sections[I]; NumSections = rhs.NumSections; Comment = rhs.Comment; + SourceFile = rhs.SourceFile; return *this; } @@ -342,6 +421,7 @@ if ((rec.Type & SourcesList::Rpm) != 0) os << "Rpm"; if ((rec.Type & SourcesList::RpmSrc) != 0) os << "RpmSrc"; os << endl; + os << "SourceFile: " << rec.SourceFile << endl; os << "VendorID: " << rec.VendorID << endl; os << "URI: " << rec.URI << endl; os << "Dist: " << rec.Dist << endl; --- synaptic-0.36.1/common/rsources.h.sourcepart 2003-03-10 22:40:57.000000000 +0200 +++ synaptic-0.36.1/common/rsources.h 2003-04-24 21:10:01.000000000 +0300 @@ -28,6 +28,7 @@ string *Sections; unsigned short NumSections; string Comment; + string SourceFile; bool SetType(string); string GetType(); @@ -58,8 +59,11 @@ string URI, string Dist, string *Sections, - unsigned short count); + unsigned short count, + string SourceFile); void RemoveSource(SourceRecord *&); + bool ReadSourcePart(string listpath); + bool ReadSourceDir(string Dir); bool ReadSources(); bool UpdateSources(); --- synaptic-0.36.1/common/rpackagelister.cc.sourcepart 2003-04-28 18:09:47.000000000 +0300 +++ synaptic-0.36.1/common/rpackagelister.cc 2003-04-29 08:24:04.000000000 +0300 @@ -1150,7 +1150,7 @@ //pkgSourceList List; //if (_cache->list()->ReadMainList() == false) //return false; - if (_cache->list()->Read(_config->FindFile("Dir::Etc::sourcelist")) == false) + if (_cache->list()->ReadMainList() == false) return false; // Lock the list directory @@ -1240,7 +1240,7 @@ //if (_cache->list()->ReadMainList() == false) { //return _error->Error(_("The list of sources could not be read.")); //} - if (_cache->list()->Read(_config->FindFile("Dir::Etc::sourcelist")) == false) { + if (_cache->list()->ReadMainList() == false) { return _error->Error(_("The list of sources could not be read.")); } --- synaptic-0.36.1/gtk/rgsrcwindow.cc.sourcepart 2003-03-29 13:58:34.000000000 +0200 +++ synaptic-0.36.1/gtk/rgsrcwindow.cc 2003-04-24 21:24:24.000000000 +0300 @@ -219,6 +219,8 @@ (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), (GtkAttachOptions) (0), 0, 0); + sourceFile = gtk_entry_new(); + dialog_action_area1 = GTK_DIALOG (dlgSrcList)->action_area; gtk_widget_show (dialog_action_area1); gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 10); @@ -370,6 +372,8 @@ string Dist; string Sections[5]; unsigned short count = 0; + // XXX user added entries go to sources.list for now.. + string SourceFile = "/etc/apt/sources.list"; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(me->cbDisabled))) Type |= SourcesList::Disabled; @@ -395,11 +399,12 @@ URI = gtk_entry_get_text(GTK_ENTRY(me->entryURI)); Dist = gtk_entry_get_text(GTK_ENTRY(me->entryDist)); Section = gtk_entry_get_text(GTK_ENTRY(me->entrySect)); + SourceFile = gtk_entry_get_text(GTK_ENTRY(me->sourceFile)); if (Section != 0 && Section[0] != 0) Sections[count++] = Section; - SourcesList::SourceRecord *rec = me->lst.AddSource((SourcesList::RecType)Type, VendorID, URI, Dist, Sections, count); + SourcesList::SourceRecord *rec = me->lst.AddSource((SourcesList::RecType)Type, VendorID, URI, Dist, Sections, count, SourceFile); if(rec == NULL) { me->_userDialog->error(_("Invalid URL")); @@ -468,6 +473,7 @@ rec.URI = gtk_entry_get_text(GTK_ENTRY(me->entryURI)); rec.Dist = gtk_entry_get_text(GTK_ENTRY(me->entryDist)); + rec.SourceFile = gtk_entry_get_text(GTK_ENTRY(me->sourceFile)); delete [] rec.Sections; rec.NumSections = 0; @@ -558,6 +564,7 @@ gtk_entry_set_text(GTK_ENTRY(me->entryURI), ""); gtk_entry_set_text(GTK_ENTRY(me->entryDist), ""); gtk_entry_set_text(GTK_ENTRY(me->entrySect), ""); + gtk_entry_set_text(GTK_ENTRY(me->sourceFile), ""); } void RGSrcEditor::UpdateDisplay(GtkCList *clist, gint row, gint col, @@ -584,6 +591,7 @@ gtk_entry_set_text(GTK_ENTRY(me->entryURI), rec.URI.c_str()); gtk_entry_set_text(GTK_ENTRY(me->entryDist), rec.Dist.c_str()); + gtk_entry_set_text(GTK_ENTRY(me->sourceFile), rec.SourceFile.c_str()); gtk_entry_set_text(GTK_ENTRY(me->entrySect), ""); for (unsigned int I = 0; I < rec.NumSections; I++) { --- synaptic-0.36.1/gtk/rgsrcwindow.h.sourcepart 2003-03-29 13:58:30.000000000 +0200 +++ synaptic-0.36.1/gtk/rgsrcwindow.h 2003-04-24 21:10:01.000000000 +0300 @@ -24,6 +24,7 @@ GtkWidget *optTypeMenu; GtkWidget *entryDist; GtkWidget *cbDisabled; + GtkWidget *sourceFile; int selectedrow;