summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2017-07-15 15:08:35 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2017-07-26 19:09:04 +0200
commit51751106976b1c6afa8f7991790db87b239fcc84 (patch)
tree1c92d91123c7d27a37ed427d54719516bd0b345a /apt-pkg/contrib
parent3317ad864c997f4897756c0a2989c4199e9cda62 (diff)
show warnings instead of errors if files are unreadable
We used to fail on unreadable config/preferences/sources files, but at least for sources we didn't in the past and it seems harsh to refuse to work because of a single file, especially as the error messages are inconsistent and end up being silly (like suggesting to run apt update to fix the problem…). LP: #1701852
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/configuration.cc11
-rw-r--r--apt-pkg/contrib/fileutl.cc13
-rw-r--r--apt-pkg/contrib/fileutl.h1
3 files changed, 16 insertions, 9 deletions
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 65242bec5..eb873bdba 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -1150,13 +1150,10 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio
bool ReadConfigDir(Configuration &Conf,const string &Dir,
bool const &AsSectional, unsigned const &Depth)
{
- vector<string> const List = GetListOfFilesInDir(Dir, "conf", true, true);
-
- // Read the files
- for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I)
- if (ReadConfigFile(Conf,*I,AsSectional,Depth) == false)
- return false;
- return true;
+ bool good = true;
+ for (auto const &I : GetListOfFilesInDir(Dir, "conf", true, true))
+ good = ReadConfigFile(Conf, I, AsSectional, Depth) && good;
+ return good;
}
/*}}}*/
// MatchAgainstConfig Constructor /*{{{*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 7633b07ef..33f4f7e09 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -402,7 +402,10 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
DIR *D = opendir(Dir.c_str());
if (D == 0)
{
- _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
+ if (errno == EACCES)
+ _error->WarningE("opendir", _("Unable to read %s"), Dir.c_str());
+ else
+ _error->Errno("opendir", _("Unable to read %s"), Dir.c_str());
return List;
}
@@ -3126,7 +3129,13 @@ bool DropPrivileges() /*{{{*/
/*}}}*/
bool OpenConfigurationFileFd(std::string const &File, FileFd &Fd) /*{{{*/
{
+ int const fd = open(File.c_str(), O_RDONLY | O_CLOEXEC | O_NOCTTY);
+ if (fd == -1)
+ return _error->WarningE("open", _("Unable to read %s"), File.c_str());
APT::Configuration::Compressor none(".", "", "", nullptr, nullptr, 0);
- return Fd.Open(File, FileFd::ReadOnly, none);
+ if (Fd.OpenDescriptor(fd, FileFd::ReadOnly, none) == false)
+ return false;
+ Fd.SetFileName(File);
+ return true;
}
/*}}}*/
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 06c303809..19b4ed49e 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -161,6 +161,7 @@ class FileFd
inline bool Eof() {return (Flags & HitEof) == HitEof;};
inline bool IsCompressed() {return (Flags & Compressed) == Compressed;};
inline std::string &Name() {return FileName;};
+ inline void SetFileName(std::string const &name) { FileName = name; };
FileFd(std::string FileName,unsigned int const Mode,unsigned long AccessMode = 0666);
FileFd(std::string FileName,unsigned int const Mode, CompressMode Compress, unsigned long AccessMode = 0666);