]> git.saurik.com Git - apt.git/blame_incremental - cmdline/apt-get.cc
Fixed held packages installing
[apt.git] / cmdline / apt-get.cc
... / ...
CommitLineData
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3// $Id: apt-get.cc,v 1.51 1999/04/12 02:25:25 jgg Exp $
4/* ######################################################################
5
6 apt-get - Cover for dpkg
7
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
10
11 The syntax is different,
12 apt-get [opt] command [things]
13 Where command is:
14 update - Resyncronize the package files from their sources
15 upgrade - Smart-Download the newest versions of all packages
16 dselect-upgrade - Follows dselect's changes to the Status: field
17 and installes new and removes old packages
18 dist-upgrade - Powerfull upgrader designed to handle the issues with
19 a new distribution.
20 install - Download and install a given package (by name, not by .deb)
21 check - Update the package cache and check for broken packages
22 clean - Erase the .debs downloaded to /var/cache/apt/archives and
23 the partial dir too
24
25 ##################################################################### */
26 /*}}}*/
27// Include Files /*{{{*/
28#include <apt-pkg/error.h>
29#include <apt-pkg/cmndline.h>
30#include <apt-pkg/init.h>
31#include <apt-pkg/depcache.h>
32#include <apt-pkg/sourcelist.h>
33#include <apt-pkg/pkgcachegen.h>
34#include <apt-pkg/algorithms.h>
35#include <apt-pkg/acquire-item.h>
36#include <apt-pkg/dpkgpm.h>
37#include <apt-pkg/dpkginit.h>
38#include <apt-pkg/strutl.h>
39#include <apt-pkg/clean.h>
40#include <apt-pkg/srcrecords.h>
41#include <apt-pkg/version.h>
42
43#include <config.h>
44
45#include "acqprogress.h"
46
47#include <fstream.h>
48#include <termios.h>
49#include <sys/ioctl.h>
50#include <sys/stat.h>
51#include <sys/vfs.h>
52#include <signal.h>
53#include <unistd.h>
54#include <stdio.h>
55 /*}}}*/
56
57ostream c0out;
58ostream c1out;
59ostream c2out;
60ofstream devnull("/dev/null");
61unsigned int ScreenWidth = 80;
62
63// YnPrompt - Yes No Prompt. /*{{{*/
64// ---------------------------------------------------------------------
65/* Returns true on a Yes.*/
66bool YnPrompt()
67{
68 if (_config->FindB("APT::Get::Assume-Yes",false) == true)
69 {
70 c1out << 'Y' << endl;
71 return true;
72 }
73
74 char C = 0;
75 char Jnk = 0;
76 read(STDIN_FILENO,&C,1);
77 while (C != '\n' && Jnk != '\n') read(STDIN_FILENO,&Jnk,1);
78
79 if (!(C == 'Y' || C == 'y' || C == '\n' || C == '\r'))
80 return false;
81 return true;
82}
83 /*}}}*/
84// AnalPrompt - Annoying Yes No Prompt. /*{{{*/
85// ---------------------------------------------------------------------
86/* Returns true on a Yes.*/
87bool AnalPrompt(const char *Text)
88{
89 char Buf[1024];
90 cin.getline(Buf,sizeof(Buf));
91 if (strcmp(Buf,Text) == 0)
92 return true;
93 return false;
94}
95 /*}}}*/
96// ShowList - Show a list /*{{{*/
97// ---------------------------------------------------------------------
98/* This prints out a string of space seperated words with a title and
99 a two space indent line wraped to the current screen width. */
100bool ShowList(ostream &out,string Title,string List)
101{
102 if (List.empty() == true)
103 return true;
104
105 // Acount for the leading space
106 int ScreenWidth = ::ScreenWidth - 3;
107
108 out << Title << endl;
109 string::size_type Start = 0;
110 while (Start < List.size())
111 {
112 string::size_type End;
113 if (Start + ScreenWidth >= List.size())
114 End = List.size();
115 else
116 End = List.rfind(' ',Start+ScreenWidth);
117
118 if (End == string::npos || End < Start)
119 End = Start + ScreenWidth;
120 out << " " << string(List,Start,End - Start) << endl;
121 Start = End + 1;
122 }
123 return false;
124}
125 /*}}}*/
126// ShowBroken - Debugging aide /*{{{*/
127// ---------------------------------------------------------------------
128/* This prints out the names of all the packages that are broken along
129 with the name of each each broken dependency and a quite version
130 description. */
131void ShowBroken(ostream &out,pkgDepCache &Cache)
132{
133 out << "Sorry, but the following packages have unmet dependencies:" << endl;
134 pkgCache::PkgIterator I = Cache.PkgBegin();
135 for (;I.end() != true; I++)
136 {
137 if (Cache[I].InstBroken() == false)
138 continue;
139
140 // Print out each package and the failed dependencies
141 out <<" " << I.Name() << ":";
142 int Indent = strlen(I.Name()) + 3;
143 bool First = true;
144 if (Cache[I].InstVerIter(Cache).end() == true)
145 {
146 cout << endl;
147 continue;
148 }
149
150 for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false;)
151 {
152 // Compute a single dependency element (glob or)
153 pkgCache::DepIterator Start;
154 pkgCache::DepIterator End;
155 D.GlobOr(Start,End);
156
157 if (Cache.IsImportantDep(End) == false ||
158 (Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
159 continue;
160
161 if (First == false)
162 for (int J = 0; J != Indent; J++)
163 out << ' ';
164 First = false;
165
166 cout << ' ' << End.DepType() << ": " << End.TargetPkg().Name();
167
168 // Show a quick summary of the version requirements
169 if (End.TargetVer() != 0)
170 out << " (" << End.CompType() << " " << End.TargetVer() <<
171 ")";
172
173 /* Show a summary of the target package if possible. In the case
174 of virtual packages we show nothing */
175
176 pkgCache::PkgIterator Targ = End.TargetPkg();
177 if (Targ->ProvidesList == 0)
178 {
179 out << " but ";
180 pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
181 if (Ver.end() == false)
182 out << Ver.VerStr() << " is installed";
183 else
184 {
185 if (Cache[Targ].CandidateVerIter(Cache).end() == true)
186 {
187 if (Targ->ProvidesList == 0)
188 out << "it is not installable";
189 else
190 out << "it is a virtual package";
191 }
192 else
193 out << "it is not installed";
194 }
195 }
196
197 out << endl;
198 }
199 }
200}
201 /*}}}*/
202// ShowNew - Show packages to newly install /*{{{*/
203// ---------------------------------------------------------------------
204/* */
205void ShowNew(ostream &out,pkgDepCache &Dep)
206{
207 /* Print out a list of packages that are going to be removed extra
208 to what the user asked */
209 pkgCache::PkgIterator I = Dep.PkgBegin();
210 string List;
211 for (;I.end() != true; I++)
212 if (Dep[I].NewInstall() == true)
213 List += string(I.Name()) + " ";
214 ShowList(out,"The following NEW packages will be installed:",List);
215}
216 /*}}}*/
217// ShowDel - Show packages to delete /*{{{*/
218// ---------------------------------------------------------------------
219/* */
220void ShowDel(ostream &out,pkgDepCache &Dep)
221{
222 /* Print out a list of packages that are going to be removed extra
223 to what the user asked */
224 pkgCache::PkgIterator I = Dep.PkgBegin();
225 string List;
226 for (;I.end() != true; I++)
227 if (Dep[I].Delete() == true)
228 List += string(I.Name()) + " ";
229
230 ShowList(out,"The following packages will be REMOVED:",List);
231}
232 /*}}}*/
233// ShowKept - Show kept packages /*{{{*/
234// ---------------------------------------------------------------------
235/* */
236void ShowKept(ostream &out,pkgDepCache &Dep)
237{
238 pkgCache::PkgIterator I = Dep.PkgBegin();
239 string List;
240 for (;I.end() != true; I++)
241 {
242 // Not interesting
243 if (Dep[I].Upgrade() == true || Dep[I].Upgradable() == false ||
244 I->CurrentVer == 0 || Dep[I].Delete() == true)
245 continue;
246
247 List += string(I.Name()) + " ";
248 }
249 ShowList(out,"The following packages have been kept back",List);
250}
251 /*}}}*/
252// ShowUpgraded - Show upgraded packages /*{{{*/
253// ---------------------------------------------------------------------
254/* */
255void ShowUpgraded(ostream &out,pkgDepCache &Dep)
256{
257 pkgCache::PkgIterator I = Dep.PkgBegin();
258 string List;
259 for (;I.end() != true; I++)
260 {
261 // Not interesting
262 if (Dep[I].Upgrade() == false || Dep[I].NewInstall() == true)
263 continue;
264
265 List += string(I.Name()) + " ";
266 }
267 ShowList(out,"The following packages will be upgraded",List);
268}
269 /*}}}*/
270// ShowHold - Show held but changed packages /*{{{*/
271// ---------------------------------------------------------------------
272/* */
273bool ShowHold(ostream &out,pkgDepCache &Dep)
274{
275 pkgCache::PkgIterator I = Dep.PkgBegin();
276 string List;
277 for (;I.end() != true; I++)
278 {
279 if (Dep[I].InstallVer != (pkgCache::Version *)I.CurrentVer() &&
280 I->SelectedState == pkgCache::State::Hold)
281 List += string(I.Name()) + " ";
282 }
283
284 return ShowList(out,"The following held packages will be changed:",List);
285}
286 /*}}}*/
287// ShowEssential - Show an essential package warning /*{{{*/
288// ---------------------------------------------------------------------
289/* This prints out a warning message that is not to be ignored. It shows
290 all essential packages and their dependents that are to be removed.
291 It is insanely risky to remove the dependents of an essential package! */
292bool ShowEssential(ostream &out,pkgDepCache &Dep)
293{
294 pkgCache::PkgIterator I = Dep.PkgBegin();
295 string List;
296 bool *Added = new bool[Dep.HeaderP->PackageCount];
297 for (unsigned int I = 0; I != Dep.HeaderP->PackageCount; I++)
298 Added[I] = false;
299
300 for (;I.end() != true; I++)
301 {
302 if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
303 continue;
304
305 // The essential package is being removed
306 if (Dep[I].Delete() == true)
307 {
308 if (Added[I->ID] == false)
309 {
310 Added[I->ID] = true;
311 List += string(I.Name()) + " ";
312 }
313 }
314
315 if (I->CurrentVer == 0)
316 continue;
317
318 // Print out any essential package depenendents that are to be removed
319 for (pkgDepCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; D++)
320 {
321 // Skip everything but depends
322 if (D->Type != pkgCache::Dep::PreDepends &&
323 D->Type != pkgCache::Dep::Depends)
324 continue;
325
326 pkgCache::PkgIterator P = D.SmartTargetPkg();
327 if (Dep[P].Delete() == true)
328 {
329 if (Added[P->ID] == true)
330 continue;
331 Added[P->ID] = true;
332
333 char S[300];
334 sprintf(S,"%s (due to %s) ",P.Name(),I.Name());
335 List += S;
336 }
337 }
338 }
339
340 delete [] Added;
341 if (List.empty() == false)
342 out << "WARNING: The following essential packages will be removed" << endl;
343 return ShowList(out,"This should NOT be done unless you know exactly what you are doing!",List);
344}
345 /*}}}*/
346// Stats - Show some statistics /*{{{*/
347// ---------------------------------------------------------------------
348/* */
349void Stats(ostream &out,pkgDepCache &Dep)
350{
351 unsigned long Upgrade = 0;
352 unsigned long Install = 0;
353 for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++)
354 {
355 if (Dep[I].NewInstall() == true)
356 Install++;
357 else
358 if (Dep[I].Upgrade() == true)
359 Upgrade++;
360 }
361
362 out << Upgrade << " packages upgraded, " <<
363 Install << " newly installed, " <<
364 Dep.DelCount() << " to remove and " <<
365 Dep.KeepCount() << " not upgraded." << endl;
366
367 if (Dep.BadCount() != 0)
368 out << Dep.BadCount() << " packages not fully installed or removed." << endl;
369}
370 /*}}}*/
371
372// class CacheFile - Cover class for some dependency cache functions /*{{{*/
373// ---------------------------------------------------------------------
374/* */
375class CacheFile
376{
377 public:
378
379 FileFd *File;
380 MMap *Map;
381 pkgDepCache *Cache;
382 pkgDpkgLock Lock;
383
384 inline operator pkgDepCache &() {return *Cache;};
385 inline pkgDepCache *operator ->() {return Cache;};
386 inline pkgDepCache &operator *() {return *Cache;};
387
388 bool Open(bool AllowBroken = false);
389 CacheFile() : File(0), Map(0), Cache(0) {};
390 ~CacheFile()
391 {
392 delete Cache;
393 delete Map;
394 delete File;
395 }
396};
397 /*}}}*/
398// CacheFile::Open - Open the cache file /*{{{*/
399// ---------------------------------------------------------------------
400/* This routine generates the caches and then opens the dependency cache
401 and verifies that the system is OK. */
402bool CacheFile::Open(bool AllowBroken)
403{
404 if (_error->PendingError() == true)
405 return false;
406
407 // Create a progress class
408 OpTextProgress Progress(*_config);
409
410 // Read the source list
411 pkgSourceList List;
412 if (List.ReadMainList() == false)
413 return _error->Error("The list of sources could not be read.");
414
415 // Build all of the caches
416 pkgMakeStatusCache(List,Progress);
417 if (_error->PendingError() == true)
418 return _error->Error("The package lists or status file could not be parsed or opened.");
419 if (_error->empty() == false)
420 _error->Warning("You may want to run apt-get update to correct theses missing files");
421
422 Progress.Done();
423
424 // Open the cache file
425 File = new FileFd(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
426 if (_error->PendingError() == true)
427 return false;
428
429 Map = new MMap(*File,MMap::Public | MMap::ReadOnly);
430 if (_error->PendingError() == true)
431 return false;
432
433 Cache = new pkgDepCache(*Map,Progress);
434 if (_error->PendingError() == true)
435 return false;
436
437 Progress.Done();
438
439 // Check that the system is OK
440 if (Cache->DelCount() != 0 || Cache->InstCount() != 0)
441 return _error->Error("Internal Error, non-zero counts");
442
443 // Apply corrections for half-installed packages
444 if (pkgApplyStatus(*Cache) == false)
445 return false;
446
447 // Nothing is broken
448 if (Cache->BrokenCount() == 0 || AllowBroken == true)
449 return true;
450
451 // Attempt to fix broken things
452 if (_config->FindB("APT::Get::Fix-Broken",false) == true)
453 {
454 c1out << "Correcting dependencies..." << flush;
455 if (pkgFixBroken(*Cache) == false || Cache->BrokenCount() != 0)
456 {
457 c1out << " failed." << endl;
458 ShowBroken(c1out,*this);
459
460 return _error->Error("Unable to correct dependencies");
461 }
462 if (pkgMinimizeUpgrade(*Cache) == false)
463 return _error->Error("Unable to minimize the upgrade set");
464
465 c1out << " Done" << endl;
466 }
467 else
468 {
469 c1out << "You might want to run `apt-get -f install' to correct these." << endl;
470 ShowBroken(c1out,*this);
471
472 return _error->Error("Unmet dependencies. Try using -f.");
473 }
474
475 return true;
476}
477 /*}}}*/
478
479// InstallPackages - Actually download and install the packages /*{{{*/
480// ---------------------------------------------------------------------
481/* This displays the informative messages describing what is going to
482 happen and then calls the download routines */
483bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,bool Saftey = true)
484{
485 bool Fail = false;
486 bool Essential = false;
487
488 // Show all the various warning indicators
489 ShowDel(c1out,Cache);
490 ShowNew(c1out,Cache);
491 if (ShwKept == true)
492 ShowKept(c1out,Cache);
493 Fail |= !ShowHold(c1out,Cache);
494 if (_config->FindB("APT::Get::Show-Upgraded",false) == true)
495 ShowUpgraded(c1out,Cache);
496 Essential = !ShowEssential(c1out,Cache);
497 Fail |= Essential;
498 Stats(c1out,Cache);
499
500 // Sanity check
501 if (Cache->BrokenCount() != 0)
502 {
503 ShowBroken(c1out,Cache);
504 return _error->Error("Internal Error, InstallPackages was called with broken packages!");
505 }
506
507 if (Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
508 Cache->BadCount() == 0)
509 return true;
510
511 // Run the simulator ..
512 if (_config->FindB("APT::Get::Simulate") == true)
513 {
514 pkgSimulate PM(Cache);
515 return PM.DoInstall();
516 }
517
518 // Create the text record parser
519 pkgRecords Recs(Cache);
520 if (_error->PendingError() == true)
521 return false;
522
523 // Lock the archive directory
524 FileFd Lock;
525 if (_config->FindB("Debug::NoLocking",false) == false)
526 {
527 Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
528 if (_error->PendingError() == true)
529 return _error->Error("Unable to lock the download directory");
530 }
531
532 // Create the download object
533 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
534 pkgAcquire Fetcher(&Stat);
535
536 // Read the source list
537 pkgSourceList List;
538 if (List.ReadMainList() == false)
539 return _error->Error("The list of sources could not be read.");
540
541 // Create the package manager and prepare to download
542 pkgDPkgPM PM(Cache);
543 if (PM.GetArchives(&Fetcher,&List,&Recs) == false ||
544 _error->PendingError() == true)
545 return false;
546
547 // Display statistics
548 unsigned long FetchBytes = Fetcher.FetchNeeded();
549 unsigned long FetchPBytes = Fetcher.PartialPresent();
550 unsigned long DebBytes = Fetcher.TotalNeeded();
551 if (DebBytes != Cache->DebSize())
552 {
553 c0out << DebBytes << ',' << Cache->DebSize() << endl;
554 c0out << "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl;
555 }
556
557 // Check for enough free space
558 struct statfs Buf;
559 string OutputDir = _config->FindDir("Dir::Cache::Archives");
560 if (statfs(OutputDir.c_str(),&Buf) != 0)
561 return _error->Errno("statfs","Couldn't determine free space in %s",
562 OutputDir.c_str());
563 if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
564 return _error->Error("Sorry, you don't have enough free space in %s",
565 OutputDir.c_str());
566
567 // Number of bytes
568 c1out << "Need to get ";
569 if (DebBytes != FetchBytes)
570 c1out << SizeToStr(FetchBytes) << "b/" << SizeToStr(DebBytes) << 'b';
571 else
572 c1out << SizeToStr(DebBytes) << 'b';
573
574 c1out << " of archives. After unpacking ";
575
576 // Size delta
577 if (Cache->UsrSize() >= 0)
578 c1out << SizeToStr(Cache->UsrSize()) << "b will be used." << endl;
579 else
580 c1out << SizeToStr(-1*Cache->UsrSize()) << "b will be freed." << endl;
581
582 if (_error->PendingError() == true)
583 return false;
584
585 // Fail safe check
586 if (_config->FindI("quiet",0) >= 2 ||
587 _config->FindB("APT::Get::Assume-Yes",false) == true)
588 {
589 if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false)
590 return _error->Error("There are problems and -y was used without --force-yes");
591 }
592
593 if (Essential == true && Saftey == true)
594 {
595 c2out << "You are about to do something potentially harmful" << endl;
596 c2out << "To continue type in the phrase 'Yes, I understand this may be bad'" << endl;
597 c2out << " ?] " << flush;
598 if (AnalPrompt("Yes, I understand this may be bad") == false)
599 {
600 c2out << "Abort." << endl;
601 exit(1);
602 }
603 }
604 else
605 {
606 // Prompt to continue
607 if (Ask == true || Fail == true)
608 {
609 if (_config->FindI("quiet",0) < 2 &&
610 _config->FindB("APT::Get::Assume-Yes",false) == false)
611 {
612 c2out << "Do you want to continue? [Y/n] " << flush;
613
614 if (YnPrompt() == false)
615 {
616 c2out << "Abort." << endl;
617 exit(1);
618 }
619 }
620 }
621 }
622
623 // Just print out the uris an exit if the --print-uris flag was used
624 if (_config->FindB("APT::Get::Print-URIs") == true)
625 {
626 pkgAcquire::UriIterator I = Fetcher.UriBegin();
627 for (; I != Fetcher.UriEnd(); I++)
628 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
629 I->Owner->FileSize << ' ' << I->Owner->MD5Sum() << endl;
630 return true;
631 }
632
633 // Run it
634 if (Fetcher.Run() == false)
635 return false;
636
637 // Print out errors
638 bool Failed = false;
639 bool Transient = false;
640 for (pkgAcquire::Item **I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
641 {
642 if ((*I)->Status == pkgAcquire::Item::StatDone &&
643 (*I)->Complete == true)
644 continue;
645
646 if ((*I)->Status == pkgAcquire::Item::StatIdle)
647 {
648 Transient = true;
649 Failed = true;
650 continue;
651 }
652
653 cerr << "Failed to fetch " << (*I)->DescURI() << endl;
654 cerr << " " << (*I)->ErrorText << endl;
655 Failed = true;
656 }
657
658 if (_config->FindB("APT::Get::Download-Only",false) == true)
659 return true;
660
661 if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
662 {
663 if (Transient == true)
664 {
665 c2out << "Upgrading with disk swapping is not supported in this version." << endl;
666 c2out << "Try running multiple times with --fix-missing" << endl;
667 }
668
669 return _error->Error("Unable to fetch some archives, maybe try with --fix-missing?");
670 }
671
672 // Try to deal with missing package files
673 if (PM.FixMissing() == false)
674 {
675 cerr << "Unable to correct missing packages." << endl;
676 return _error->Error("Aborting Install.");
677 }
678
679 Cache.Lock.Close();
680 return PM.DoInstall();
681}
682 /*}}}*/
683
684// DoUpdate - Update the package lists /*{{{*/
685// ---------------------------------------------------------------------
686/* */
687bool DoUpdate(CommandLine &)
688{
689 // Get the source list
690 pkgSourceList List;
691 if (List.ReadMainList() == false)
692 return false;
693
694 // Lock the list directory
695 FileFd Lock;
696 if (_config->FindB("Debug::NoLocking",false) == false)
697 {
698 Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
699 if (_error->PendingError() == true)
700 return _error->Error("Unable to lock the list directory");
701 }
702
703 // Create the download object
704 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
705 pkgAcquire Fetcher(&Stat);
706
707 // Populate it with the source selection
708 pkgSourceList::const_iterator I;
709 for (I = List.begin(); I != List.end(); I++)
710 {
711 new pkgAcqIndex(&Fetcher,I);
712 if (_error->PendingError() == true)
713 return false;
714 }
715
716 // Run it
717 if (Fetcher.Run() == false)
718 return false;
719
720 // Clean out any old list files
721 if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
722 Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
723 return false;
724
725 // Prepare the cache.
726 CacheFile Cache;
727 if (Cache.Open() == false)
728 return false;
729
730 return true;
731}
732 /*}}}*/
733// DoUpgrade - Upgrade all packages /*{{{*/
734// ---------------------------------------------------------------------
735/* Upgrade all packages without installing new packages or erasing old
736 packages */
737bool DoUpgrade(CommandLine &CmdL)
738{
739 CacheFile Cache;
740 if (Cache.Open() == false)
741 return false;
742
743 // Do the upgrade
744 if (pkgAllUpgrade(Cache) == false)
745 {
746 ShowBroken(c1out,Cache);
747 return _error->Error("Internal Error, AllUpgrade broke stuff");
748 }
749
750 return InstallPackages(Cache,true);
751}
752 /*}}}*/
753// DoInstall - Install packages from the command line /*{{{*/
754// ---------------------------------------------------------------------
755/* Install named packages */
756bool DoInstall(CommandLine &CmdL)
757{
758 CacheFile Cache;
759 if (Cache.Open(CmdL.FileSize() != 1) == false)
760 return false;
761
762 // Enter the special broken fixing mode if the user specified arguments
763 bool BrokenFix = false;
764 if (Cache->BrokenCount() != 0)
765 BrokenFix = true;
766
767 unsigned int ExpectedInst = 0;
768 unsigned int Packages = 0;
769 pkgProblemResolver Fix(Cache);
770
771 bool DefRemove = false;
772 if (strcasecmp(CmdL.FileList[0],"remove") == 0)
773 DefRemove = true;
774
775 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
776 {
777 // Duplicate the string
778 unsigned int Length = strlen(*I);
779 char S[300];
780 if (Length >= sizeof(S))
781 continue;
782 strcpy(S,*I);
783
784 // See if we are removing the package
785 bool Remove = DefRemove;
786 if (Cache->FindPkg(S).end() == true)
787 {
788 // Handle an optional end tag indicating what to do
789 if (S[Length - 1] == '-')
790 {
791 Remove = true;
792 S[--Length] = 0;
793 }
794 if (S[Length - 1] == '+')
795 {
796 Remove = false;
797 S[--Length] = 0;
798 }
799 }
800
801 // Locate the package
802 pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
803 Packages++;
804 if (Pkg.end() == true)
805 return _error->Error("Couldn't find package %s",S);
806
807 // Handle the no-upgrade case
808 if (_config->FindB("APT::Get::no-upgrade",false) == true &&
809 Pkg->CurrentVer != 0)
810 {
811 c1out << "Skipping " << Pkg.Name() << ", it is already installed and no-upgrade is set." << endl;
812 continue;
813 }
814
815 // Check if there is something new to install
816 pkgDepCache::StateCache &State = (*Cache)[Pkg];
817 if (State.CandidateVer == 0)
818 {
819 if (Pkg->ProvidesList != 0)
820 {
821 c1out << "Package " << S << " is a virtual package provided by:" << endl;
822
823 pkgCache::PrvIterator I = Pkg.ProvidesList();
824 for (; I.end() == false; I++)
825 {
826 pkgCache::PkgIterator Pkg = I.OwnerPkg();
827
828 if ((*Cache)[Pkg].CandidateVerIter(*Cache) == I.OwnerVer())
829 {
830 if ((*Cache)[Pkg].Install() == true && (*Cache)[Pkg].NewInstall() == false)
831 c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() <<
832 " [Installed]"<< endl;
833 else
834 c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << endl;
835 }
836 }
837 c1out << "You should explicly select one to install." << endl;
838 }
839 else
840 {
841 c1out << "Package " << S << " has no available version, but exists in the database." << endl;
842 c1out << "This typically means that the package was mentioned in a dependency and " << endl;
843 c1out << "never uploaded, or that it is an obsolete package." << endl;
844
845 string List;
846 pkgCache::DepIterator Dep = Pkg.RevDependsList();
847 for (; Dep.end() == false; Dep++)
848 {
849 if (Dep->Type != pkgCache::Dep::Replaces)
850 continue;
851 List += string(Dep.ParentPkg().Name()) + " ";
852 }
853 ShowList(c1out,"However the following packages replace it:",List);
854 }
855
856 return _error->Error("Package %s has no installation candidate",S);
857 }
858
859 Fix.Protect(Pkg);
860 if (Remove == true)
861 {
862 Fix.Remove(Pkg);
863 Cache->MarkDelete(Pkg);
864 continue;
865 }
866
867 // Install it
868 Cache->MarkInstall(Pkg,false);
869 if (State.Install() == false)
870 c1out << "Sorry, " << S << " is already the newest version" << endl;
871 else
872 ExpectedInst++;
873
874 // Install it with autoinstalling enabled.
875 if (State.InstBroken() == true && BrokenFix == false)
876 Cache->MarkInstall(Pkg,true);
877 }
878
879 /* If we are in the Broken fixing mode we do not attempt to fix the
880 problems. This is if the user invoked install without -f and gave
881 packages */
882 if (BrokenFix == true && Cache->BrokenCount() != 0)
883 {
884 c1out << "You might want to run `apt-get -f install' to correct these." << endl;
885 ShowBroken(c1out,Cache);
886
887 return _error->Error("Unmet dependencies. Try using -f.");
888 }
889
890 // Call the scored problem resolver
891 Fix.InstallProtect();
892 if (Fix.Resolve(true) == false)
893 _error->Discard();
894
895 // Now we check the state of the packages,
896 if (Cache->BrokenCount() != 0)
897 {
898 c1out << "Some packages could not be installed. This may mean that you have" << endl;
899 c1out << "requested an impossible situation or if you are using the unstable" << endl;
900 c1out << "distribution that some required packages have not yet been created" << endl;
901 c1out << "or been moved out of Incoming." << endl;
902 if (Packages == 1)
903 {
904 c1out << endl;
905 c1out << "Since you only requested a single operation it is extremely likely that" << endl;
906 c1out << "the package is simply not installable and a bug report against" << endl;
907 c1out << "that package should be filed." << endl;
908 }
909
910 c1out << "The following information may help to resolve the situation:" << endl;
911 c1out << endl;
912 ShowBroken(c1out,Cache);
913 return _error->Error("Sorry, broken packages");
914 }
915
916 /* Print out a list of packages that are going to be installed extra
917 to what the user asked */
918 if (Cache->InstCount() != ExpectedInst)
919 {
920 string List;
921 pkgCache::PkgIterator I = Cache->PkgBegin();
922 for (;I.end() != true; I++)
923 {
924 if ((*Cache)[I].Install() == false)
925 continue;
926
927 const char **J;
928 for (J = CmdL.FileList + 1; *J != 0; J++)
929 if (strcmp(*J,I.Name()) == 0)
930 break;
931
932 if (*J == 0)
933 List += string(I.Name()) + " ";
934 }
935
936 ShowList(c1out,"The following extra packages will be installed:",List);
937 }
938
939 // See if we need to prompt
940 if (Cache->InstCount() == ExpectedInst && Cache->DelCount() == 0)
941 return InstallPackages(Cache,false,false);
942
943 return InstallPackages(Cache,false);
944}
945 /*}}}*/
946// DoDistUpgrade - Automatic smart upgrader /*{{{*/
947// ---------------------------------------------------------------------
948/* Intelligent upgrader that will install and remove packages at will */
949bool DoDistUpgrade(CommandLine &CmdL)
950{
951 CacheFile Cache;
952 if (Cache.Open() == false)
953 return false;
954
955 c0out << "Calculating Upgrade... " << flush;
956 if (pkgDistUpgrade(*Cache) == false)
957 {
958 c0out << "Failed" << endl;
959 ShowBroken(c1out,Cache);
960 return false;
961 }
962
963 c0out << "Done" << endl;
964
965 return InstallPackages(Cache,true);
966}
967 /*}}}*/
968// DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
969// ---------------------------------------------------------------------
970/* Follows dselect's selections */
971bool DoDSelectUpgrade(CommandLine &CmdL)
972{
973 CacheFile Cache;
974 if (Cache.Open() == false)
975 return false;
976
977 // Install everything with the install flag set
978 pkgCache::PkgIterator I = Cache->PkgBegin();
979 for (;I.end() != true; I++)
980 {
981 /* Install the package only if it is a new install, the autoupgrader
982 will deal with the rest */
983 if (I->SelectedState == pkgCache::State::Install)
984 Cache->MarkInstall(I,false);
985 }
986
987 /* Now install their deps too, if we do this above then order of
988 the status file is significant for | groups */
989 for (I = Cache->PkgBegin();I.end() != true; I++)
990 {
991 /* Install the package only if it is a new install, the autoupgrader
992 will deal with the rest */
993 if (I->SelectedState == pkgCache::State::Install)
994 Cache->MarkInstall(I,true);
995 }
996
997 // Apply erasures now, they override everything else.
998 for (I = Cache->PkgBegin();I.end() != true; I++)
999 {
1000 // Remove packages
1001 if (I->SelectedState == pkgCache::State::DeInstall ||
1002 I->SelectedState == pkgCache::State::Purge)
1003 Cache->MarkDelete(I);
1004 }
1005
1006 /* Resolve any problems that dselect created, allupgrade cannot handle
1007 such things. We do so quite agressively too.. */
1008 if (Cache->BrokenCount() != 0)
1009 {
1010 pkgProblemResolver Fix(Cache);
1011
1012 // Hold back held packages.
1013 if (_config->FindB("APT::Ingore-Hold",false) == false)
1014 {
1015 for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; I++)
1016 {
1017 if (I->SelectedState == pkgCache::State::Hold)
1018 {
1019 Fix.Protect(I);
1020 Cache->MarkKeep(I);
1021 }
1022 }
1023 }
1024
1025 if (Fix.Resolve() == false)
1026 {
1027 ShowBroken(c1out,Cache);
1028 return _error->Error("Internal Error, problem resolver broke stuff");
1029 }
1030 }
1031
1032 // Now upgrade everything
1033 if (pkgAllUpgrade(Cache) == false)
1034 {
1035 ShowBroken(c1out,Cache);
1036 return _error->Error("Internal Error, problem resolver broke stuff");
1037 }
1038
1039 return InstallPackages(Cache,false);
1040}
1041 /*}}}*/
1042// DoClean - Remove download archives /*{{{*/
1043// ---------------------------------------------------------------------
1044/* */
1045bool DoClean(CommandLine &CmdL)
1046{
1047 pkgAcquire Fetcher;
1048 Fetcher.Clean(_config->FindDir("Dir::Cache::archives"));
1049 Fetcher.Clean(_config->FindDir("Dir::Cache::archives") + "partial/");
1050 return true;
1051}
1052 /*}}}*/
1053// DoAutoClean - Smartly remove downloaded archives /*{{{*/
1054// ---------------------------------------------------------------------
1055/* This is similar to clean but it only purges things that cannot be
1056 downloaded, that is old versions of cached packages. */
1057class LogCleaner : public pkgArchiveCleaner
1058{
1059 protected:
1060 virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St)
1061 {
1062 cout << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "b]" << endl;
1063 };
1064};
1065
1066bool DoAutoClean(CommandLine &CmdL)
1067{
1068 CacheFile Cache;
1069 if (Cache.Open(true) == false)
1070 return false;
1071
1072 LogCleaner Cleaner;
1073
1074 return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
1075 Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
1076}
1077 /*}}}*/
1078// DoCheck - Perform the check operation /*{{{*/
1079// ---------------------------------------------------------------------
1080/* Opening automatically checks the system, this command is mostly used
1081 for debugging */
1082bool DoCheck(CommandLine &CmdL)
1083{
1084 CacheFile Cache;
1085 Cache.Open();
1086
1087 return true;
1088}
1089 /*}}}*/
1090// DoSource - Fetch a source archive /*{{{*/
1091// ---------------------------------------------------------------------
1092/* */
1093bool DoSource(CommandLine &CmdL)
1094{
1095 CacheFile Cache;
1096 if (Cache.Open(true) == false)
1097 return false;
1098
1099 // Read the source list
1100 pkgSourceList List;
1101 if (List.ReadMainList() == false)
1102 return _error->Error("The list of sources could not be read.");
1103
1104 // Create the text record parsers
1105 pkgRecords Recs(Cache);
1106 pkgSrcRecords SrcRecs(List);
1107 if (_error->PendingError() == true)
1108 return false;
1109
1110 // Create the download object
1111 AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
1112 pkgAcquire Fetcher(&Stat);
1113
1114 // Load the requestd sources into the fetcher
1115 for (const char **I = CmdL.FileList + 1; *I != 0; I++)
1116 {
1117 string Src;
1118
1119 /* Lookup the version of the package we would install if we were to
1120 install a version and determine the source package name, then look
1121 in the archive for a source package of the same name. In theory
1122 we could stash the version string as well and match that too but
1123 today there aren't multi source versions in the archive. */
1124 pkgCache::PkgIterator Pkg = Cache->FindPkg(*I);
1125 if (Pkg.end() == false)
1126 {
1127 pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
1128 if (Ver.end() == false)
1129 {
1130 pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
1131 Src = Parse.SourcePkg();
1132 }
1133 }
1134
1135 // No source package name..
1136 if (Src.empty() == true)
1137 Src = *I;
1138
1139 // The best hit
1140 pkgSrcRecords::Parser *Last = 0;
1141 unsigned long Offset = 0;
1142 string Version;
1143
1144 // Iterate over all of the hits
1145 pkgSrcRecords::Parser *Parse;
1146 SrcRecs.Restart();
1147 while ((Parse = SrcRecs.Find(Src.c_str(),false)) != 0)
1148 {
1149 string Ver = Parse->Version();
1150 if (Last == 0 || pkgVersionCompare(Version,Ver) < 0)
1151 {
1152 Last = Parse;
1153 Offset = Parse->Offset();
1154 Version = Ver;
1155 }
1156 }
1157
1158 if (Last == 0)
1159 return _error->Error("Unable to find a source package for %s",Src.c_str());
1160
1161 // Back track
1162 vector<pkgSrcRecords::File> Lst;
1163 if (Last->Jump(Offset) == false || Last->Files(Lst) == false)
1164 return false;
1165
1166 // Load them into the fetcher
1167 for (vector<pkgSrcRecords::File>::const_iterator I = Lst.begin();
1168 I != Lst.end(); I++)
1169 {
1170 // Try to guess what sort of file it is we are getting.
1171 string Comp;
1172 if (I->Path.find(".dsc") != string::npos)
1173 Comp = "dsc";
1174 if (I->Path.find(".tar.gz") != string::npos)
1175 Comp = "tar";
1176 if (I->Path.find(".diff.gz") != string::npos)
1177 Comp = "diff";
1178
1179 new pkgAcqFile(&Fetcher,Last->Source()->ArchiveURI(I->Path),
1180 I->MD5Hash,I->Size,Last->Source()->SourceInfo(Src,
1181 Last->Version(),Comp),Src);
1182 }
1183 }
1184
1185 // Display statistics
1186 unsigned long FetchBytes = Fetcher.FetchNeeded();
1187 unsigned long FetchPBytes = Fetcher.PartialPresent();
1188 unsigned long DebBytes = Fetcher.TotalNeeded();
1189
1190 // Check for enough free space
1191 struct statfs Buf;
1192 string OutputDir = ".";
1193 if (statfs(OutputDir.c_str(),&Buf) != 0)
1194 return _error->Errno("statfs","Couldn't determine free space in %s",
1195 OutputDir.c_str());
1196 if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
1197 return _error->Error("Sorry, you don't have enough free space in %s",
1198 OutputDir.c_str());
1199
1200 // Number of bytes
1201 c1out << "Need to get ";
1202 if (DebBytes != FetchBytes)
1203 c1out << SizeToStr(FetchBytes) << "b/" << SizeToStr(DebBytes) << 'b';
1204 else
1205 c1out << SizeToStr(DebBytes) << 'b';
1206 c1out << " of source archives." << endl;
1207
1208 // Just print out the uris an exit if the --print-uris flag was used
1209 if (_config->FindB("APT::Get::Print-URIs") == true)
1210 {
1211 pkgAcquire::UriIterator I = Fetcher.UriBegin();
1212 for (; I != Fetcher.UriEnd(); I++)
1213 cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
1214 I->Owner->FileSize << ' ' << I->Owner->MD5Sum() << endl;
1215 return true;
1216 }
1217
1218 // Run it
1219 if (Fetcher.Run() == false)
1220 return false;
1221
1222 // Print error messages
1223 for (pkgAcquire::Item **I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
1224 {
1225 if ((*I)->Status == pkgAcquire::Item::StatDone &&
1226 (*I)->Complete == true)
1227 continue;
1228
1229 cerr << "Failed to fetch " << (*I)->DescURI() << endl;
1230 cerr << " " << (*I)->ErrorText << endl;
1231 }
1232
1233 return true;
1234}
1235 /*}}}*/
1236
1237// ShowHelp - Show a help screen /*{{{*/
1238// ---------------------------------------------------------------------
1239/* */
1240bool ShowHelp(CommandLine &CmdL)
1241{
1242 cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
1243 " compiled on " << __DATE__ << " " << __TIME__ << endl;
1244 if (_config->FindB("version") == true)
1245 return 100;
1246
1247 cout << "Usage: apt-get [options] command" << endl;
1248 cout << " apt-get [options] install pkg1 [pkg2 ...]" << endl;
1249 cout << endl;
1250 cout << "apt-get is a simple command line interface for downloading and" << endl;
1251 cout << "installing packages. The most frequently used commands are update" << endl;
1252 cout << "and install." << endl;
1253 cout << endl;
1254 cout << "Commands:" << endl;
1255 cout << " update - Retrieve new lists of packages" << endl;
1256 cout << " upgrade - Perform an upgrade" << endl;
1257 cout << " install - Install new packages (pkg is libc6 not libc6.deb)" << endl;
1258 cout << " remove - Remove packages" << endl;
1259 cout << " source - Download source archives" << endl;
1260 cout << " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl;
1261 cout << " dselect-upgrade - Follow dselect selections" << endl;
1262 cout << " clean - Erase downloaded archive files" << endl;
1263 cout << " autoclean - Erase old downloaded archive files" << endl;
1264 cout << " check - Verify that there are no broken dependencies" << endl;
1265 cout << endl;
1266 cout << "Options:" << endl;
1267 cout << " -h This help text." << endl;
1268 cout << " -q Loggable output - no progress indicator" << endl;
1269 cout << " -qq No output except for errors" << endl;
1270 cout << " -d Download only - do NOT install or unpack archives" << endl;
1271 cout << " -s No-act. Perform ordering simulation" << endl;
1272 cout << " -y Assume Yes to all queries and do not prompt" << endl;
1273 cout << " -f Attempt to continue if the integrity check fails" << endl;
1274 cout << " -m Attempt to continue if archives are unlocatable" << endl;
1275 cout << " -u Show a list of upgraded packages as well" << endl;
1276 cout << " -c=? Read this configuration file" << endl;
1277 cout << " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl;
1278 cout << "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl;
1279 cout << "pages for more information." << endl;
1280 return 100;
1281}
1282 /*}}}*/
1283// GetInitialize - Initialize things for apt-get /*{{{*/
1284// ---------------------------------------------------------------------
1285/* */
1286void GetInitialize()
1287{
1288 _config->Set("quiet",0);
1289 _config->Set("help",false);
1290 _config->Set("APT::Get::Download-Only",false);
1291 _config->Set("APT::Get::Simulate",false);
1292 _config->Set("APT::Get::Assume-Yes",false);
1293 _config->Set("APT::Get::Fix-Broken",false);
1294 _config->Set("APT::Get::Force-Yes",false);
1295}
1296 /*}}}*/
1297// SigWinch - Window size change signal handler /*{{{*/
1298// ---------------------------------------------------------------------
1299/* */
1300void SigWinch(int)
1301{
1302 // Riped from GNU ls
1303#ifdef TIOCGWINSZ
1304 struct winsize ws;
1305
1306 if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5)
1307 ScreenWidth = ws.ws_col - 1;
1308#endif
1309}
1310 /*}}}*/
1311
1312int main(int argc,const char *argv[])
1313{
1314 CommandLine::Args Args[] = {
1315 {'h',"help","help",0},
1316 {'v',"version","version",0},
1317 {'q',"quiet","quiet",CommandLine::IntLevel},
1318 {'q',"silent","quiet",CommandLine::IntLevel},
1319 {'d',"download-only","APT::Get::Download-Only",0},
1320 {'s',"simulate","APT::Get::Simulate",0},
1321 {'s',"just-print","APT::Get::Simulate",0},
1322 {'s',"recon","APT::Get::Simulate",0},
1323 {'s',"no-act","APT::Get::Simulate",0},
1324 {'y',"yes","APT::Get::Assume-Yes",0},
1325 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1326 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1327 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1328 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1329 {0,"fix-missing","APT::Get::Fix-Missing",0},
1330 {0,"ignore-hold","APT::Ingore-Hold",0},
1331 {0,"no-upgrade","APT::Get::no-upgrade",0},
1332 {0,"force-yes","APT::Get::force-yes",0},
1333 {0,"print-uris","APT::Get::Print-URIs",0},
1334 {'c',"config-file",0,CommandLine::ConfigFile},
1335 {'o',"option",0,CommandLine::ArbItem},
1336 {0,0,0,0}};
1337 CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate},
1338 {"upgrade",&DoUpgrade},
1339 {"install",&DoInstall},
1340 {"remove",&DoInstall},
1341 {"dist-upgrade",&DoDistUpgrade},
1342 {"dselect-upgrade",&DoDSelectUpgrade},
1343 {"clean",&DoClean},
1344 {"autoclean",&DoAutoClean},
1345 {"check",&DoCheck},
1346 {"source",&DoSource},
1347 {"help",&ShowHelp},
1348 {0,0}};
1349
1350 // Parse the command line and initialize the package library
1351 CommandLine CmdL(Args,_config);
1352 if (pkgInitialize(*_config) == false ||
1353 CmdL.Parse(argc,argv) == false)
1354 {
1355 _error->DumpErrors();
1356 return 100;
1357 }
1358
1359 // See if the help should be shown
1360 if (_config->FindB("help") == true ||
1361 _config->FindB("version") == true ||
1362 CmdL.FileSize() == 0)
1363 return ShowHelp(CmdL);
1364
1365 // Deal with stdout not being a tty
1366 if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1)
1367 _config->Set("quiet","1");
1368
1369 // Setup the output streams
1370 c0out.rdbuf(cout.rdbuf());
1371 c1out.rdbuf(cout.rdbuf());
1372 c2out.rdbuf(cout.rdbuf());
1373 if (_config->FindI("quiet",0) > 0)
1374 c0out.rdbuf(devnull.rdbuf());
1375 if (_config->FindI("quiet",0) > 1)
1376 c1out.rdbuf(devnull.rdbuf());
1377
1378 // Setup the signals
1379 signal(SIGPIPE,SIG_IGN);
1380 signal(SIGWINCH,SigWinch);
1381 SigWinch(0);
1382
1383 // Match the operation
1384 CmdL.DispatchArg(Cmds);
1385
1386 // Print any errors or warnings found during parsing
1387 if (_error->empty() == false)
1388 {
1389 bool Errors = _error->PendingError();
1390 _error->DumpErrors();
1391 return Errors == true?100:0;
1392 }
1393
1394 return 0;
1395}