]> git.saurik.com Git - apt.git/blame_incremental - apt-private/private-sources.cc
warning: cast from type A to type B casts away qualifiers [-Wcast-qual]
[apt.git] / apt-private / private-sources.cc
... / ...
CommitLineData
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/* Interface discussion with donkult (for the future):
10 apt [add-{archive,release,component}|edit|change-release|disable]-sources
11 and be clever and work out stuff from the Release file
12*/
13
14// EditSource - EditSourcesList /*{{{*/
15// ---------------------------------------------------------------------
16bool EditSources(CommandLine &CmdL)
17{
18 bool res;
19 pkgSourceList sl;
20 std::string outs;
21
22 std::string sourceslist;
23 if (CmdL.FileList[1] != NULL)
24 {
25 sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1];
26 if (!APT::String::Endswith(sourceslist, ".list"))
27 sourceslist += ".list";
28 } else {
29 sourceslist = _config->FindFile("Dir::Etc::sourcelist");
30 }
31 HashString before;
32 if (FileExists(sourceslist))
33 before.FromFile(sourceslist);
34
35 int lockfd = GetLock(sourceslist);
36 if (lockfd < 0)
37 return false;
38
39 do {
40 EditFileInSensibleEditor(sourceslist);
41 _error->PushToStack();
42 res = sl.Read(sourceslist);
43 if (!res) {
44 _error->DumpErrors();
45 strprintf(outs, _("Failed to parse %s. Edit again? "),
46 sourceslist.c_str());
47 std::cout << outs;
48 // FIXME: should we add a "restore previous" option here?
49 res = !YnPrompt(true);
50 }
51 _error->RevertToStack();
52 } while (res == false);
53 close(lockfd);
54
55 if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) {
56 strprintf(
57 outs, _("Your '%s' file changed, please run 'apt-get update'."),
58 sourceslist.c_str());
59 std::cout << outs << std::endl;
60 }
61
62 return true;
63}
64 /*}}}*/