]> git.saurik.com Git - apt.git/blob - apt-private/private-sources.cc
eipp: provide the internal planer as an external one
[apt.git] / apt-private / private-sources.cc
1 #include <config.h>
2
3 #include <apt-pkg/hashes.h>
4 #include <apt-pkg/strutl.h>
5 #include <apt-pkg/configuration.h>
6 #include <apt-pkg/sourcelist.h>
7 #include <apt-pkg/cmndline.h>
8 #include <apt-pkg/error.h>
9 #include <apt-pkg/fileutl.h>
10
11 #include <apt-private/private-output.h>
12 #include <apt-private/private-sources.h>
13 #include <apt-private/private-utils.h>
14
15 #include <stddef.h>
16 #include <unistd.h>
17 #include <iostream>
18 #include <string>
19
20 #include <apti18n.h>
21
22 /* Interface discussion with donkult (for the future):
23 apt [add-{archive,release,component}|edit|change-release|disable]-sources
24 and be clever and work out stuff from the Release file
25 */
26
27 // EditSource - EditSourcesList /*{{{*/
28 // ---------------------------------------------------------------------
29 bool EditSources(CommandLine &CmdL)
30 {
31 bool res;
32 pkgSourceList sl;
33
34 std::string sourceslist;
35 if (CmdL.FileList[1] != NULL)
36 {
37 sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1];
38 if (!APT::String::Endswith(sourceslist, ".list"))
39 sourceslist += ".list";
40 } else {
41 sourceslist = _config->FindFile("Dir::Etc::sourcelist");
42 }
43 HashString before;
44 if (FileExists(sourceslist))
45 before.FromFile(sourceslist);
46
47 int lockfd = GetLock(sourceslist);
48 if (lockfd < 0)
49 return false;
50
51 do {
52 EditFileInSensibleEditor(sourceslist);
53 _error->PushToStack();
54 res = sl.Read(sourceslist);
55 if (!res) {
56 std::string outs;
57 strprintf(outs, _("Failed to parse %s. Edit again? "), sourceslist.c_str());
58 // FIXME: should we add a "restore previous" option here?
59 res = !YnPrompt(outs.c_str(), true);
60 }
61 _error->RevertToStack();
62 } while (res == false);
63 close(lockfd);
64
65 if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) {
66 ioprintf(
67 std::cout, _("Your '%s' file changed, please run 'apt-get update'."),
68 sourceslist.c_str());
69 }
70
71 return true;
72 }
73 /*}}}*/