fix typo in apt-pkg/acquire.cc which prevents Dl-Limit to work
[ntk/apt.git] / cmdline / apt-cdrom.cc
CommitLineData
83d89a9f
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
a3f6ea20 3// $Id: apt-cdrom.cc,v 1.45 2003/11/19 23:50:51 mdz Exp $
83d89a9f
AL
4/* ######################################################################
5
18444708
AL
6 APT CDROM - Tool for handling APT's CDROM database.
7
8 Currently the only option is 'add' which will take the current CD
9 in the drive and add it into the database.
83d89a9f
AL
10
11 ##################################################################### */
12 /*}}}*/
13// Include Files /*{{{*/
14#include <apt-pkg/cmndline.h>
15#include <apt-pkg/error.h>
16#include <apt-pkg/init.h>
83d89a9f
AL
17#include <apt-pkg/fileutl.h>
18#include <apt-pkg/progress.h>
65ae8fab 19#include <apt-pkg/cdromutl.h>
cdcc6d34 20#include <apt-pkg/strutl.h>
a75c6a6e
MZ
21#include <apt-pkg/acquire.h>
22#include <apt-pkg/acquire-item.h>
23#include <apt-pkg/cdrom.h>
83d89a9f 24#include <config.h>
b2e465d6
AL
25#include <apti18n.h>
26
a75c6a6e 27//#include "indexcopy.h"
143abaeb 28
233c2b66 29#include <locale.h>
83d89a9f 30#include <iostream>
18444708 31#include <fstream>
83d89a9f
AL
32#include <vector>
33#include <algorithm>
83d89a9f
AL
34#include <sys/stat.h>
35#include <fcntl.h>
36#include <dirent.h>
37#include <unistd.h>
38#include <stdio.h>
39 /*}}}*/
40
076d01b0
AL
41using namespace std;
42
a75c6a6e
MZ
43 /*{{{*/
44class pkgCdromTextStatus : public pkgCdromStatus
83d89a9f 45{
a75c6a6e
MZ
46protected:
47 OpTextProgress Progress;
48 void Prompt(const char *Text);
49 string PromptLine(const char *Text);
50 bool AskCdromName(string &name);
51
52public:
53 virtual void Update(string text, int current);
54 virtual bool ChangeCdrom();
55 virtual OpProgress* GetOpProgress();
8a579291 56};
83d89a9f 57
a75c6a6e 58void pkgCdromTextStatus::Prompt(const char *Text)
83d89a9f 59{
a75c6a6e
MZ
60 char C;
61 cout << Text << ' ' << flush;
62 read(STDIN_FILENO,&C,1);
63 if (C != '\n')
64 cout << endl;
83d89a9f 65}
4dfaa253 66
a75c6a6e 67string pkgCdromTextStatus::PromptLine(const char *Text)
83d89a9f 68{
a75c6a6e 69 cout << Text << ':' << endl;
83d89a9f 70
a75c6a6e
MZ
71 string Res;
72 getline(cin,Res);
83d89a9f
AL
73 return Res;
74}
18444708 75
a75c6a6e 76bool pkgCdromTextStatus::AskCdromName(string &name)
83d89a9f 77{
4a5e5089 78 cout << _("Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'") << flush;
a75c6a6e 79 name = PromptLine("");
83d89a9f 80
83d89a9f
AL
81 return true;
82}
83d89a9f 83
83d89a9f 84
a75c6a6e 85void pkgCdromTextStatus::Update(string text, int current)
18444708 86{
a75c6a6e
MZ
87 if(text.size() > 0)
88 cout << text << flush;
18444708 89}
4dfaa253 90
8a579291 91bool pkgCdromTextStatus::ChangeCdrom()
83d89a9f 92{
4a5e5089 93 Prompt(_("Please insert a Disc in the drive and press enter"));
18444708
AL
94 return true;
95}
83d89a9f 96
8a579291 97OpProgress* pkgCdromTextStatus::GetOpProgress()
a75c6a6e
MZ
98{
99 return &Progress;
100};
101
83d89a9f
AL
102 /*}}}*/
103
104// DoAdd - Add a new CDROM /*{{{*/
105// ---------------------------------------------------------------------
4dfaa253
AL
106/* This does the main add bit.. We show some status and things. The
107 sequence is to mount/umount the CD, Ident it then scan it for package
108 files and reduce that list. Then we copy over the package files and
109 verify them. Then rewrite the database files */
83d89a9f
AL
110bool DoAdd(CommandLine &)
111{
a75c6a6e
MZ
112 bool res = false;
113 pkgCdromTextStatus log;
114 pkgCdrom cdrom;
115 res = cdrom.Add(&log);
116 if(res)
4a5e5089 117 cout << _("Repeat this process for the rest of the CDs in your set.") << endl;
a75c6a6e 118 return res;
83d89a9f
AL
119}
120 /*}}}*/
b2e465d6
AL
121// DoIdent - Ident a CDROM /*{{{*/
122// ---------------------------------------------------------------------
123/* */
124bool DoIdent(CommandLine &)
125{
a75c6a6e
MZ
126 string ident;
127 pkgCdromTextStatus log;
128 pkgCdrom cdrom;
129 return cdrom.Ident(ident, &log);
b2e465d6
AL
130}
131 /*}}}*/
83d89a9f
AL
132
133// ShowHelp - Show the help screen /*{{{*/
134// ---------------------------------------------------------------------
135/* */
136int ShowHelp()
137{
5b28c804
OS
138 ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION,
139 COMMON_ARCH,__DATE__,__TIME__);
04aa15a8 140 if (_config->FindB("version") == true)
b2e465d6
AL
141 return 0;
142
143 cout <<
144 "Usage: apt-cdrom [options] command\n"
145 "\n"
146 "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
147 "CDROM mount point and device information is taken from apt.conf\n"
148 "and /etc/fstab.\n"
149 "\n"
150 "Commands:\n"
151 " add - Add a CDROM\n"
152 " ident - Report the identity of a CDROM\n"
153 "\n"
154 "Options:\n"
155 " -h This help text\n"
156 " -d CD-ROM mount point\n"
157 " -r Rename a recognized CD-ROM\n"
158 " -m No mounting\n"
159 " -f Fast mode, don't check package files\n"
160 " -a Thorough scan mode\n"
161 " -c=? Read this configuration file\n"
a2884e32 162 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
b2e465d6
AL
163 "See fstab(5)\n";
164 return 0;
83d89a9f
AL
165}
166 /*}}}*/
167
168int main(int argc,const char *argv[])
169{
170 CommandLine::Args Args[] = {
171 {'h',"help","help",0},
04aa15a8 172 {'v',"version","version",0},
83d89a9f
AL
173 {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg},
174 {'r',"rename","APT::CDROM::Rename",0},
175 {'m',"no-mount","APT::CDROM::NoMount",0},
176 {'f',"fast","APT::CDROM::Fast",0},
c60d151b 177 {'n',"just-print","APT::CDROM::NoAct",0},
18444708 178 {'n',"recon","APT::CDROM::NoAct",0},
c60d151b
AL
179 {'n',"no-act","APT::CDROM::NoAct",0},
180 {'a',"thorough","APT::CDROM::Thorough",0},
83d89a9f
AL
181 {'c',"config-file",0,CommandLine::ConfigFile},
182 {'o',"option",0,CommandLine::ArbItem},
183 {0,0,0,0}};
184 CommandLine::Dispatch Cmds[] = {
185 {"add",&DoAdd},
b2e465d6 186 {"ident",&DoIdent},
83d89a9f 187 {0,0}};
67111687
AL
188
189 // Set up gettext support
190 setlocale(LC_ALL,"");
191 textdomain(PACKAGE);
192
83d89a9f
AL
193 // Parse the command line and initialize the package library
194 CommandLine CmdL(Args,_config);
b2e465d6
AL
195 if (pkgInitConfig(*_config) == false ||
196 CmdL.Parse(argc,argv) == false ||
197 pkgInitSystem(*_config,_system) == false)
83d89a9f
AL
198 {
199 _error->DumpErrors();
200 return 100;
201 }
202
203 // See if the help should be shown
5633a7c2 204 if (_config->FindB("help") == true || _config->FindB("version") == true ||
83d89a9f
AL
205 CmdL.FileSize() == 0)
206 return ShowHelp();
a9a5908d
AL
207
208 // Deal with stdout not being a tty
a3f6ea20 209 if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
a9a5908d 210 _config->Set("quiet","1");
83d89a9f
AL
211
212 // Match the operation
213 CmdL.DispatchArg(Cmds);
214
215 // Print any errors or warnings found during parsing
216 if (_error->empty() == false)
217 {
218 bool Errors = _error->PendingError();
219 _error->DumpErrors();
220 return Errors == true?100:0;
221 }
222
223 return 0;
224}