~ubuntu-branches/debian/experimental/apt/experimental

« back to all changes in this revision

Viewing changes to cmdline/apt-cdrom.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2010-02-18 22:07:23 UTC
  • mfrom: (9.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100218220723-zb7zdh6fmsmp30tr
Tags: 0.7.26~exp2
fix crash when LANGUAGE is not set

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   ##################################################################### */
12
12
                                                                        /*}}}*/
13
13
// Include Files                                                        /*{{{*/
14
 
#include <apt-pkg/contrib/cmndline.h>
15
 
#include <apt-pkg/contrib/error.h>
 
14
#include <apt-pkg/cmndline.h>
 
15
#include <apt-pkg/error.h>
16
16
#include <apt-pkg/init.h>
17
 
#include <apt-pkg/contrib/fileutl.h>
18
 
#include <apt-pkg/contrib/progress.h>
19
 
#include <apt-pkg/contrib/cdromutl.h>
20
 
#include <apt-pkg/contrib/strutl.h>
 
17
#include <apt-pkg/fileutl.h>
 
18
#include <apt-pkg/progress.h>
 
19
#include <apt-pkg/cdromutl.h>
 
20
#include <apt-pkg/strutl.h>
21
21
#include <apt-pkg/acquire.h>
22
22
#include <apt-pkg/acquire-item.h>
23
23
#include <apt-pkg/cdrom.h>
40
40
 
41
41
using namespace std;
42
42
 
43
 
                                                                        /*{{{*/
44
 
class pkgCdromTextStatus : public pkgCdromStatus
 
43
class pkgCdromTextStatus : public pkgCdromStatus                        /*{{{*/
45
44
{
46
45
protected:
47
46
   OpTextProgress Progress;
75
74
 
76
75
bool pkgCdromTextStatus::AskCdromName(string &name) 
77
76
{
78
 
   cout << _("Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'") << flush;
 
77
   cout << _("Please provide a name for this Disc, such as 'Debian 5.0.3 Disk 1'") << flush;
79
78
   name = PromptLine("");
80
79
         
81
80
   return true;
98
97
99
98
   return &Progress; 
100
99
};
101
 
 
 
100
                                                                        /*}}}*/
 
101
// SetupAutoDetect                                                      /*{{{*/
 
102
bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, unsigned int &i)
 
103
{
 
104
   bool Debug =  _config->FindB("Debug::Acquire::cdrom", false);
 
105
 
 
106
   vector<struct CdromDevice> v = UdevCdroms.Scan();
 
107
   if (i >= v.size())
 
108
      return false;
 
109
 
 
110
   if (Debug)
 
111
      clog << "Looking at devce " << i
 
112
           << " DeviveName: " << v[i].DeviceName 
 
113
           << " IsMounted: '" << v[i].Mounted << "'"
 
114
           << " MountPoint: '" << v[i].MountPath << "'"
 
115
           << endl;
 
116
 
 
117
   if (v[i].Mounted)
 
118
   {
 
119
      // set the right options
 
120
      _config->Set("Acquire::cdrom::mount", v[i].MountPath);
 
121
      _config->Set("APT::CDROM::NoMount", true);
 
122
   } else {
 
123
      string AptMountPoint = _config->FindDir("Dir::Media::MountPath");
 
124
      if (!FileExists(AptMountPoint))
 
125
         mkdir(AptMountPoint.c_str(), 0750);
 
126
      if(MountCdrom(AptMountPoint, v[i].DeviceName) == false)
 
127
         _error->Warning(_("Failed to mount '%s' to '%s'"), v[i].DeviceName.c_str(), AptMountPoint.c_str());
 
128
      _config->Set("Acquire::cdrom::mount", AptMountPoint);
 
129
      _config->Set("APT::CDROM::NoMount", true);
 
130
   }
 
131
   i++;
 
132
 
 
133
   return true;
 
134
}
102
135
                                                                        /*}}}*/
103
136
 
104
137
// DoAdd - Add a new CDROM                                              /*{{{*/
109
142
   verify them. Then rewrite the database files */
110
143
bool DoAdd(CommandLine &)
111
144
{
112
 
   bool res = false;
 
145
   pkgUdevCdromDevices UdevCdroms;
113
146
   pkgCdromTextStatus log;
114
147
   pkgCdrom cdrom;
115
 
   res = cdrom.Add(&log);
 
148
   bool res = true;
 
149
 
 
150
   bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect");
 
151
   unsigned int count = 0;
 
152
   
 
153
   if (AutoDetect && UdevCdroms.Dlopen())
 
154
   {
 
155
      while (AutoDetectCdrom(UdevCdroms, count))
 
156
         res &= cdrom.Add(&log);
 
157
   } else {
 
158
      res = cdrom.Add(&log);
 
159
   }
 
160
 
116
161
   if(res)
117
162
      cout << _("Repeat this process for the rest of the CDs in your set.") << endl;
 
163
 
118
164
   return res;
119
165
}
120
166
                                                                        /*}}}*/
123
169
/* */
124
170
bool DoIdent(CommandLine &)
125
171
{
 
172
   pkgUdevCdromDevices UdevCdroms;
126
173
   string ident;
127
174
   pkgCdromTextStatus log;
128
175
   pkgCdrom cdrom;
129
 
   return cdrom.Ident(ident, &log);
 
176
   bool res = true;
 
177
 
 
178
   bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect");
 
179
   unsigned int count = 0;
 
180
   
 
181
   if (AutoDetect && UdevCdroms.Dlopen())
 
182
   {
 
183
      while (AutoDetectCdrom(UdevCdroms, count))
 
184
         res &= cdrom.Ident(ident, &log);
 
185
   } else {
 
186
      return cdrom.Ident(ident, &log);
 
187
   }
 
188
 
 
189
   return res;
130
190
}
131
191
                                                                        /*}}}*/
132
 
 
133
192
// ShowHelp - Show the help screen                                      /*{{{*/
134
193
// ---------------------------------------------------------------------
135
194
/* */
158
217
      "  -m   No mounting\n"
159
218
      "  -f   Fast mode, don't check package files\n"
160
219
      "  -a   Thorough scan mode\n"
 
220
      "  --auto-detect Auto detect drive and mount point\n"
161
221
      "  -c=? Read this configuration file\n"
162
222
      "  -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
163
223
      "See fstab(5)\n";
164
224
   return 0;
165
225
}
166
226
                                                                        /*}}}*/
167
 
 
168
 
int main(int argc,const char *argv[])
 
227
int main(int argc,const char *argv[])                                   /*{{{*/
169
228
{
170
229
   CommandLine::Args Args[] = {
171
230
      {'h',"help","help",0},
 
231
      {  0,"auto-detect","Acquire::cdrom::AutoDetect",0},
172
232
      {'v',"version","version",0},
173
233
      {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg},
174
234
      {'r',"rename","APT::CDROM::Rename",0},
222
282
   
223
283
   return 0;
224
284
}
 
285
                                                                        /*}}}*/