]>
git.saurik.com Git - apt.git/blob - apt-private/private-sources.cc
   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> 
  16 #include <sys/types.h> 
  25 /* Interface discussion with donkult (for the future): 
  26   apt [add-{archive,release,component}|edit|change-release|disable]-sources 
  27  and be clever and work out stuff from the Release file 
  30 // EditSource - EditSourcesList                                         /*{{{*/ 
  31 class APT_HIDDEN ScopedGetLock 
{ 
  34    ScopedGetLock(std::string 
const &filename
) : fd(GetLock(filename
)) {} 
  35    ~ScopedGetLock() { close(fd
); } 
  37 bool EditSources(CommandLine 
&CmdL
) 
  39    std::string sourceslist
; 
  40    if (CmdL
.FileList
[1] != NULL
) 
  42       sourceslist 
= _config
->FindDir("Dir::Etc::sourceparts") + CmdL
.FileList
[1]; 
  43       if (!APT::String::Endswith(sourceslist
, ".list")) 
  44          sourceslist 
+= ".list"; 
  46       sourceslist 
= _config
->FindFile("Dir::Etc::sourcelist"); 
  49    if (FileExists(sourceslist
)) 
  50        before
.FromFile(sourceslist
); 
  54       if (filefd
.Open(sourceslist
, FileFd::Create 
| FileFd::WriteOnly
, FileFd::None
, 0644) == false) 
  58    ScopedGetLock 
lock(sourceslist
); 
  63    bool file_changed 
= false; 
  65       if (EditFileInSensibleEditor(sourceslist
) == false) 
  70          if (stat(sourceslist
.c_str(), &St
) == 0 && St
.st_size 
== 0) 
  71                RemoveFile("edit-sources", sourceslist
); 
  73       else if (FileExists(sourceslist
) && !before
.VerifyFile(sourceslist
)) 
  76          pkgCacheFile::RemoveCaches(); 
  78       pkgCacheFile CacheFile
; 
  79       res 
= CacheFile
.BuildCaches(nullptr); 
  80       if (res 
== false || _error
->empty(GlobalError::WARNING
) == false) { 
  82          strprintf(outs
, _("Failed to parse %s. Edit again? "), sourceslist
.c_str()); 
  83          // FIXME: should we add a "restore previous" option here? 
  84          if (YnPrompt(outs
.c_str(), true) == false) 
  86             if (res 
== false && _error
->PendingError() == false) 
  89                pkgCacheFile::RemoveCaches(); 
  90                res 
= CacheFile
.BuildCaches(nullptr); 
  95    } while (res 
== false); 
  97    if (res 
== true && file_changed 
== true) 
 100          std::cout
, _("Your '%s' file changed, please run 'apt-get update'."), 
 101          sourceslist
.c_str());