move EditSources into its own file
[ntk/apt.git] / apt-private / private-sources.cc
1
2 #include <apt-pkg/hashes.h>
3 #include <apti18n.h>
4
5 #include "private-output.h"
6 #include "private-sources.h"
7 #include "private-utils.h"
8
9 // EditSource - EditSourcesList /*{{{*/
10 // ---------------------------------------------------------------------
11 bool EditSources(CommandLine &CmdL)
12 {
13 bool res;
14 pkgSourceList sl;
15 std::string outs;
16
17 // FIXME: suport CmdL.FileList to specify sources.list.d files
18 std::string sourceslist = _config->FindFile("Dir::Etc::sourcelist");
19
20 HashString before;
21 before.FromFile(sourceslist);
22
23 do {
24 EditFileInSensibleEditor(sourceslist);
25 _error->PushToStack();
26 res = sl.Read(sourceslist);
27 if (!res) {
28 strprintf(outs, _("Failed to parse %s. Edit again? "),
29 sourceslist.c_str());
30 std::cout << outs;
31 res = !YnPrompt(true);
32 }
33 _error->RevertToStack();
34 } while (res == false);
35
36 if (!before.VerifyFile(sourceslist)) {
37 strprintf(
38 outs, _("Your '%s' file changed, please run 'apt-get update'."),
39 sourceslist.c_str());
40 std::cout << outs << std::endl;
41 }
42
43 return true;
44 }
45 /*}}}*/