~mvo/apt/mvo

« back to all changes in this revision

Viewing changes to cmdline/apt-cdrom.cc

  • Committer: Arch Librarian
  • Date: 2004-09-20 16:56:32 UTC
  • Revision ID: Arch-1:apt@arch.ubuntu.com%apt--MAIN--0--patch-614
Join with aliencode
Author: jgg
Date: 2001-02-20 07:03:16 GMT
Join with aliencode

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- mode: cpp; mode: fold -*-
2
2
// Description                                                          /*{{{*/
3
 
// $Id: apt-cdrom.cc,v 1.35 2000/05/10 06:03:52 jgg Exp $
 
3
// $Id: apt-cdrom.cc,v 1.36 2001/02/20 07:03:17 jgg Exp $
4
4
/* ######################################################################
5
5
   
6
6
   APT CDROM - Tool for handling APT's CDROM database.
19
19
#include <apt-pkg/cdromutl.h>
20
20
#include <apt-pkg/strutl.h>
21
21
#include <config.h>
22
 
 
 
22
#include <apti18n.h>
 
23
    
23
24
#include "indexcopy.h"
24
25
 
25
26
#include <iostream>
119
120
         break;
120
121
 
121
122
      if (chdir(CD.c_str()) != 0)
122
 
         return _error->Errno("chdir","Unable to change to ",CD.c_str());
 
123
         return _error->Errno("chdir","Unable to change to %s",CD.c_str());
123
124
   };
124
125
 
125
126
   closedir(D);
255
256
// ---------------------------------------------------------------------
256
257
/* This takes the list of source list expressed entires and collects
257
258
   similar ones to form a single entry for each dist */
258
 
bool ReduceSourcelist(string CD,vector<string> &List)
 
259
void ReduceSourcelist(string CD,vector<string> &List)
259
260
{
260
261
   sort(List.begin(),List.end());
261
262
   
269
270
      string::size_type SSpace = (*I).find(' ',Space + 1);
270
271
      if (SSpace == string::npos)
271
272
         continue;
272
 
      
 
273
 
273
274
      string Word1 = string(*I,Space,SSpace-Space);
 
275
      string Prefix = string(*I,0,Space);
274
276
      for (vector<string>::iterator J = List.begin(); J != I; J++)
275
277
      {
276
278
         // Find a space..
281
283
         if (SSpace2 == string::npos)
282
284
            continue;
283
285
         
 
286
         if (string(*J,0,Space2) != Prefix)
 
287
            continue;
284
288
         if (string(*J,Space2,SSpace2-Space2) != Word1)
285
289
            continue;
286
290
         
358
362
   string File = _config->FindFile("Dir::Etc::sourcelist");
359
363
 
360
364
   // Open the stream for reading
361
 
   ifstream F(File.c_str(),ios::in | ios::nocreate);
 
365
   ifstream F((FileExists(File)?File.c_str():"/dev/null"),
 
366
              ios::in | ios::nocreate);
362
367
   if (!F != 0)
363
368
      return _error->Errno("ifstream::ifstream","Opening %s",File.c_str());
364
369
 
577
582
 
578
583
         if (Name.empty() == false)
579
584
         {
 
585
            // Escape special characters
 
586
            string::iterator J = Name.begin();
 
587
            for (; J != Name.end(); J++)
 
588
               if (*J == '"' || *J == ']' || *J == '[')
 
589
                  *J = '_';
 
590
            
580
591
            cout << "Found label '" << Name << "'" << endl;
581
592
            Database.Set("CD::" + ID + "::Label",Name);
582
593
         }       
663
674
   return true;
664
675
}
665
676
                                                                        /*}}}*/
 
677
// DoIdent - Ident a CDROM                                              /*{{{*/
 
678
// ---------------------------------------------------------------------
 
679
/* */
 
680
bool DoIdent(CommandLine &)
 
681
{
 
682
   // Startup
 
683
   string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
 
684
   if (CDROM[0] == '.')
 
685
      CDROM= SafeGetCWD() + '/' + CDROM;
 
686
   
 
687
   cout << "Using CD-ROM mount point " << CDROM << endl;
 
688
   cout << "Mounting CD-ROM" << endl;
 
689
   if (MountCdrom(CDROM) == false)
 
690
      return _error->Error("Failed to mount the cdrom.");
 
691
   
 
692
   // Hash the CD to get an ID
 
693
   cout << "Identifying.. " << flush;
 
694
   string ID;
 
695
   if (IdentCdrom(CDROM,ID) == false)
 
696
   {
 
697
      cout << endl;
 
698
      return false;
 
699
   }
 
700
   
 
701
   cout << '[' << ID << ']' << endl;
 
702
 
 
703
   // Read the database
 
704
   Configuration Database;
 
705
   string DFile = _config->FindFile("Dir::State::cdroms");
 
706
   if (FileExists(DFile) == true)
 
707
   {
 
708
      if (ReadConfigFile(Database,DFile) == false)
 
709
         return _error->Error("Unable to read the cdrom database %s",
 
710
                              DFile.c_str());
 
711
   }
 
712
   cout << "Stored Label: '" << Database.Find("CD::" + ID) << "'" << endl;
 
713
   return true;
 
714
}
 
715
                                                                        /*}}}*/
666
716
 
667
717
// ShowHelp - Show the help screen                                      /*{{{*/
668
718
// ---------------------------------------------------------------------
669
719
/* */
670
720
int ShowHelp()
671
721
{
672
 
   cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
673
 
       " compiled on " << __DATE__ << "  " << __TIME__ << endl;
 
722
   ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
 
723
            COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
674
724
   if (_config->FindB("version") == true)
675
 
      return 100;
 
725
      return 0;
676
726
   
677
 
   cout << "Usage: apt-cdrom [options] command" << endl;
678
 
   cout << endl;
679
 
   cout << "apt-cdrom is a tool to add CDROM's to APT's source list. The " << endl;
680
 
   cout << "CDROM mount point and device information is taken from apt.conf" << endl;
681
 
   cout << "and /etc/fstab." << endl;
682
 
   cout << endl;
683
 
   cout << "Commands:" << endl;
684
 
   cout << "   add - Add a CDROM" << endl;
685
 
   cout << endl;
686
 
   cout << "Options:" << endl;
687
 
   cout << "  -h   This help text" << endl;
688
 
   cout << "  -d   CD-ROM mount point" << endl;
689
 
   cout << "  -r   Rename a recognized CD-ROM" << endl;
690
 
   cout << "  -m   No mounting" << endl;
691
 
   cout << "  -f   Fast mode, don't check package files" << endl;
692
 
   cout << "  -a   Thorough scan mode" << endl;
693
 
   cout << "  -c=? Read this configuration file" << endl;
694
 
   cout << "  -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl;
695
 
   cout << "See fstab(5)" << endl;
696
 
   return 100;
 
727
   cout << 
 
728
      "Usage: apt-cdrom [options] command\n"
 
729
      "\n"
 
730
      "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
 
731
      "CDROM mount point and device information is taken from apt.conf\n"
 
732
      "and /etc/fstab.\n"
 
733
      "\n"
 
734
      "Commands:\n"
 
735
      "   add - Add a CDROM\n"
 
736
      "   ident - Report the identity of a CDROM\n"
 
737
      "\n"
 
738
      "Options:\n"
 
739
      "  -h   This help text\n"
 
740
      "  -d   CD-ROM mount point\n"
 
741
      "  -r   Rename a recognized CD-ROM\n"
 
742
      "  -m   No mounting\n"
 
743
      "  -f   Fast mode, don't check package files\n"
 
744
      "  -a   Thorough scan mode\n"
 
745
      "  -c=? Read this configuration file\n"
 
746
      "  -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
 
747
      "See fstab(5)\n";
 
748
   return 0;
697
749
}
698
750
                                                                        /*}}}*/
699
751
 
715
767
      {0,0,0,0}};
716
768
   CommandLine::Dispatch Cmds[] = {
717
769
      {"add",&DoAdd},
 
770
      {"ident",&DoIdent},
718
771
      {0,0}};
719
772
         
720
773
   // Parse the command line and initialize the package library
721
774
   CommandLine CmdL(Args,_config);
722
 
   if (pkgInitialize(*_config) == false ||
723
 
       CmdL.Parse(argc,argv) == false)
 
775
   if (pkgInitConfig(*_config) == false ||
 
776
       CmdL.Parse(argc,argv) == false ||
 
777
       pkgInitSystem(*_config,_system) == false)
724
778
   {
725
779
      _error->DumpErrors();
726
780
      return 100;