]>
Commit | Line | Data |
---|---|---|
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 | std::string outs; | |
34 | ||
35 | std::string sourceslist; | |
36 | if (CmdL.FileList[1] != NULL) | |
37 | { | |
38 | sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1]; | |
39 | if (!APT::String::Endswith(sourceslist, ".list")) | |
40 | sourceslist += ".list"; | |
41 | } else { | |
42 | sourceslist = _config->FindFile("Dir::Etc::sourcelist"); | |
43 | } | |
44 | HashString before; | |
45 | if (FileExists(sourceslist)) | |
46 | before.FromFile(sourceslist); | |
47 | ||
48 | int lockfd = GetLock(sourceslist); | |
49 | if (lockfd < 0) | |
50 | return false; | |
51 | ||
52 | do { | |
53 | EditFileInSensibleEditor(sourceslist); | |
54 | _error->PushToStack(); | |
55 | res = sl.Read(sourceslist); | |
56 | if (!res) { | |
57 | _error->DumpErrors(); | |
58 | strprintf(outs, _("Failed to parse %s. Edit again? "), | |
59 | sourceslist.c_str()); | |
60 | std::cout << outs; | |
61 | // FIXME: should we add a "restore previous" option here? | |
62 | res = !YnPrompt(true); | |
63 | } | |
64 | _error->RevertToStack(); | |
65 | } while (res == false); | |
66 | close(lockfd); | |
67 | ||
68 | if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) { | |
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 | /*}}}*/ |