~racb/ubuntu/quantal/apt/by_hash

« back to all changes in this revision

Viewing changes to apt-pkg/contrib/configuration.cc

  • Committer: Package Import Robot
  • Author(s): Steve Langasek, Michael Vogt, Steve Langasek
  • Date: 2012-06-11 22:36:16 UTC
  • mfrom: (1.4.47 sid)
  • Revision ID: package-import@ubuntu.com-20120611223616-1cctfc7qrxrx4vcu
Tags: 0.9.6ubuntu1
[ Michael Vogt ]
* merged from Debian, remaining changes:
  - use ubuntu keyring and ubuntu archive keyring in apt-key
  - run update-apt-xapian-index in apt.cron
  - support apt-key net-update and verify keys against master-keyring
  - run apt-key net-update in cron.daily
  - different example sources.list
  - APT::pkgPackageManager::MaxLoopCount set to 5000
  - apport pkgfailure handling
  - ubuntu changelog download handling
  - patch for apt cross-building, see http://bugs.debian.org/666772

[ Steve Langasek ]
* Drop upgrade handling for obsolete conffile /etc/apt/apt.conf.d/01ubuntu,
  removed in previous LTS.
* prepare-release: declare the packages needed as source build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
171
171
string Configuration::FindFile(const char *Name,const char *Default) const
172
172
{
173
173
   const Item *RootItem = Lookup("RootDir");
174
 
   std::string rootDir =  (RootItem == 0) ? "" : RootItem->Value;
175
 
   if(rootDir.size() > 0 && rootDir[rootDir.size() - 1] != '/')
176
 
     rootDir.push_back('/');
 
174
   std::string result =  (RootItem == 0) ? "" : RootItem->Value;
 
175
   if(result.empty() == false && result[result.size() - 1] != '/')
 
176
     result.push_back('/');
177
177
 
178
178
   const Item *Itm = Lookup(Name);
179
179
   if (Itm == 0 || Itm->Value.empty() == true)
180
180
   {
181
 
      if (Default == 0)
182
 
         return rootDir;
183
 
      else
184
 
         return rootDir + Default;
 
181
      if (Default != 0)
 
182
         result.append(Default);
185
183
   }
186
 
   
187
 
   string val = Itm->Value;
188
 
   while (Itm->Parent != 0)
 
184
   else
189
185
   {
190
 
      if (Itm->Parent->Value.empty() == true)
 
186
      string val = Itm->Value;
 
187
      while (Itm->Parent != 0)
191
188
      {
 
189
         if (Itm->Parent->Value.empty() == true)
 
190
         {
 
191
            Itm = Itm->Parent;
 
192
            continue;
 
193
         }
 
194
 
 
195
         // Absolute
 
196
         if (val.length() >= 1 && val[0] == '/')
 
197
         {
 
198
            if (val.compare(0, 9, "/dev/null") == 0)
 
199
               val.erase(9);
 
200
            break;
 
201
         }
 
202
 
 
203
         // ~/foo or ./foo
 
204
         if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/')
 
205
            break;
 
206
 
 
207
         // ../foo
 
208
         if (val.length() >= 3 && val[0] == '.' && val[1] == '.' && val[2] == '/')
 
209
            break;
 
210
 
 
211
         if (Itm->Parent->Value.end()[-1] != '/')
 
212
            val.insert(0, "/");
 
213
 
 
214
         val.insert(0, Itm->Parent->Value);
192
215
         Itm = Itm->Parent;
193
 
         continue;
194
216
      }
195
 
 
196
 
      // Absolute
197
 
      if (val.length() >= 1 && val[0] == '/')
198
 
         break;
199
 
 
200
 
      // ~/foo or ./foo 
201
 
      if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/')
202
 
         break;
203
 
         
204
 
      // ../foo 
205
 
      if (val.length() >= 3 && val[0] == '.' && val[1] == '.' && val[2] == '/')
206
 
         break;
207
 
      
208
 
      if (Itm->Parent->Value.end()[-1] != '/')
209
 
         val.insert(0, "/");
210
 
 
211
 
      val.insert(0, Itm->Parent->Value);
212
 
      Itm = Itm->Parent;
 
217
      result.append(val);
213
218
   }
214
219
 
215
 
   return rootDir + val;
 
220
   // do some normalisation by removing // and /./ from the path
 
221
   size_t found = string::npos;
 
222
   while ((found = result.find("/./")) != string::npos)
 
223
      result.replace(found, 3, "/");
 
224
   while ((found = result.find("//")) != string::npos)
 
225
      result.replace(found, 2, "/");
 
226
 
 
227
   return result;
216
228
}
217
229
                                                                        /*}}}*/
218
230
// Configuration::FindDir - Find a directory name                       /*{{{*/
222
234
{
223
235
   string Res = FindFile(Name,Default);
224
236
   if (Res.end()[-1] != '/')
 
237
   {
 
238
      size_t const found = Res.rfind("/dev/null");
 
239
      if (found != string::npos && found == Res.size() - 9)
 
240
         return Res; // /dev/null returning
225
241
      return Res + '/';
 
242
   }
226
243
   return Res;
227
244
}
228
245
                                                                        /*}}}*/
482
499
/* Dump the entire configuration space */
483
500
void Configuration::Dump(ostream& str)
484
501
{
485
 
   /* Write out all of the configuration directives by walking the 
 
502
   Dump(str, NULL, "%f \"%v\";\n", true);
 
503
}
 
504
void Configuration::Dump(ostream& str, char const * const root,
 
505
                         char const * const formatstr, bool const emptyValue)
 
506
{
 
507
   const Configuration::Item* Top = Tree(root);
 
508
   if (Top == 0)
 
509
      return;
 
510
   const Configuration::Item* const Root = (root == NULL) ? NULL : Top;
 
511
   std::vector<std::string> const format = VectorizeString(formatstr, '%');
 
512
 
 
513
   /* Write out all of the configuration directives by walking the
486
514
      configuration tree */
487
 
   const Configuration::Item *Top = Tree(0);
488
 
   for (; Top != 0;)
489
 
   {
490
 
      str << Top->FullTag() << " \"" << Top->Value << "\";" << endl;
491
 
      
 
515
   do {
 
516
      if (emptyValue == true || Top->Value.empty() == emptyValue)
 
517
      {
 
518
         std::vector<std::string>::const_iterator f = format.begin();
 
519
         str << *f;
 
520
         for (++f; f != format.end(); ++f)
 
521
         {
 
522
            if (f->empty() == true)
 
523
            {
 
524
               ++f;
 
525
               str << '%' << *f;
 
526
               continue;
 
527
            }
 
528
            char const type = (*f)[0];
 
529
            if (type == 'f')
 
530
               str << Top->FullTag();
 
531
            else if (type == 't')
 
532
               str << Top->Tag;
 
533
            else if (type == 'v')
 
534
               str << Top->Value;
 
535
            else if (type == 'F')
 
536
               str << QuoteString(Top->FullTag(), "=\"\n");
 
537
            else if (type == 'T')
 
538
               str << QuoteString(Top->Tag, "=\"\n");
 
539
            else if (type == 'V')
 
540
               str << QuoteString(Top->Value, "=\"\n");
 
541
            else if (type == 'n')
 
542
               str << "\n";
 
543
            else if (type == 'N')
 
544
               str << "\t";
 
545
            else
 
546
               str << '%' << type;
 
547
            str << f->c_str() + 1;
 
548
         }
 
549
      }
 
550
 
492
551
      if (Top->Child != 0)
493
552
      {
494
553
         Top = Top->Child;
495
554
         continue;
496
555
      }
497
 
      
 
556
 
498
557
      while (Top != 0 && Top->Next == 0)
499
558
         Top = Top->Parent;
500
559
      if (Top != 0)
501
560
         Top = Top->Next;
502
 
   }
 
561
 
 
562
      if (Root != NULL)
 
563
      {
 
564
         const Configuration::Item* I = Top;
 
565
         while(I != 0)
 
566
         {
 
567
            if (I == Root)
 
568
               break;
 
569
            else
 
570
               I = I->Parent;
 
571
         }
 
572
         if (I == 0)
 
573
            break;
 
574
      }
 
575
   } while (Top != 0);
503
576
}
504
577
                                                                        /*}}}*/
505
578