]>
git.saurik.com Git - apt.git/blob - apt-private/private-sources.cc
7e64d5d7f4e001c00a445f57d3c1a53c6abf24ea
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 #include <apt-pkg/cachefile.h>
12 #include <apt-private/private-output.h>
13 #include <apt-private/private-sources.h>
14 #include <apt-private/private-utils.h>
23 /* Interface discussion with donkult (for the future):
24 apt [add-{archive,release,component}|edit|change-release|disable]-sources
25 and be clever and work out stuff from the Release file
28 // EditSource - EditSourcesList /*{{{*/
29 class APT_HIDDEN ScopedGetLock
{
32 ScopedGetLock(std::string
const &filename
) : fd(GetLock(filename
)) {}
33 ~ScopedGetLock() { close(fd
); }
35 bool EditSources(CommandLine
&CmdL
)
37 std::string sourceslist
;
38 if (CmdL
.FileList
[1] != NULL
)
40 sourceslist
= _config
->FindDir("Dir::Etc::sourceparts") + CmdL
.FileList
[1];
41 if (!APT::String::Endswith(sourceslist
, ".list"))
42 sourceslist
+= ".list";
44 sourceslist
= _config
->FindFile("Dir::Etc::sourcelist");
47 if (FileExists(sourceslist
))
48 before
.FromFile(sourceslist
);
50 ScopedGetLock
lock(sourceslist
);
55 bool file_changed
= false;
57 if (EditFileInSensibleEditor(sourceslist
) == false)
59 if (FileExists(sourceslist
) && !before
.VerifyFile(sourceslist
))
62 pkgCacheFile::RemoveCaches();
64 pkgCacheFile CacheFile
;
65 res
= CacheFile
.BuildCaches(nullptr);
66 if (res
== false || _error
->empty(GlobalError::WARNING
) == false) {
68 strprintf(outs
, _("Failed to parse %s. Edit again? "), sourceslist
.c_str());
69 // FIXME: should we add a "restore previous" option here?
70 if (YnPrompt(outs
.c_str(), true) == false)
72 if (res
== false && _error
->PendingError() == false)
75 pkgCacheFile::RemoveCaches();
76 res
= CacheFile
.BuildCaches(nullptr);
81 } while (res
== false);
83 if (res
== true && file_changed
== true)
86 std::cout
, _("Your '%s' file changed, please run 'apt-get update'."),