]>
Commit | Line | Data |
---|---|---|
453b82a3 | 1 | #include <config.h> |
9e6b13f3 MV |
2 | |
3 | #include <apt-pkg/hashes.h> | |
453b82a3 DK |
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> | |
9e6b13f3 | 14 | |
453b82a3 DK |
15 | #include <stddef.h> |
16 | #include <unistd.h> | |
17 | #include <iostream> | |
18 | #include <string> | |
19 | ||
20 | #include <apti18n.h> | |
9e6b13f3 | 21 | |
a8f671c1 MV |
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 | ||
9e6b13f3 MV |
27 | // EditSource - EditSourcesList /*{{{*/ |
28 | // --------------------------------------------------------------------- | |
29 | bool EditSources(CommandLine &CmdL) | |
30 | { | |
31 | bool res; | |
32 | pkgSourceList sl; | |
33 | std::string outs; | |
34 | ||
a8f671c1 MV |
35 | std::string sourceslist; |
36 | if (CmdL.FileList[1] != NULL) | |
cf993341 MV |
37 | { |
38 | sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1]; | |
39 | if (!APT::String::Endswith(sourceslist, ".list")) | |
40 | sourceslist += ".list"; | |
41 | } else { | |
a8f671c1 | 42 | sourceslist = _config->FindFile("Dir::Etc::sourcelist"); |
cf993341 | 43 | } |
9e6b13f3 | 44 | HashString before; |
a8f671c1 MV |
45 | if (FileExists(sourceslist)) |
46 | before.FromFile(sourceslist); | |
9e6b13f3 | 47 | |
c189f87d MV |
48 | int lockfd = GetLock(sourceslist); |
49 | if (lockfd < 0) | |
50 | return false; | |
51 | ||
9e6b13f3 MV |
52 | do { |
53 | EditFileInSensibleEditor(sourceslist); | |
54 | _error->PushToStack(); | |
55 | res = sl.Read(sourceslist); | |
56 | if (!res) { | |
a8f671c1 | 57 | _error->DumpErrors(); |
9e6b13f3 MV |
58 | strprintf(outs, _("Failed to parse %s. Edit again? "), |
59 | sourceslist.c_str()); | |
60 | std::cout << outs; | |
cf993341 | 61 | // FIXME: should we add a "restore previous" option here? |
9e6b13f3 MV |
62 | res = !YnPrompt(true); |
63 | } | |
64 | _error->RevertToStack(); | |
65 | } while (res == false); | |
c189f87d | 66 | close(lockfd); |
9e6b13f3 | 67 | |
a8f671c1 | 68 | if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) { |
9e6b13f3 MV |
69 | strprintf( |
70 | outs, _("Your '%s' file changed, please run 'apt-get update'."), | |
71 | sourceslist.c_str()); | |
72 | std::cout << outs << std::endl; | |
73 | } | |
74 | ||
75 | return true; | |
76 | } | |
77 | /*}}}*/ |