summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/fileutl.cc20
-rw-r--r--apt-pkg/contrib/fileutl.h1
-rw-r--r--apt-pkg/depcache.cc4
-rw-r--r--apt-pkg/init.cc6
-rw-r--r--apt-pkg/policy.cc2
-rw-r--r--apt-pkg/sourcelist.cc6
-rw-r--r--apt-pkg/vendorlist.cc4
7 files changed, 31 insertions, 12 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index f4ab066d7..db6057ea3 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -191,7 +191,7 @@ int GetLock(string File,bool Errors)
/*}}}*/
// FileExists - Check if a file exists /*{{{*/
// ---------------------------------------------------------------------
-/* */
+/* Beware: Directories are also files! */
bool FileExists(string File)
{
struct stat Buf;
@@ -200,6 +200,17 @@ bool FileExists(string File)
return true;
}
/*}}}*/
+// RealFileExists - Check if a file exists and if it is really a file /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool RealFileExists(string File)
+{
+ struct stat Buf;
+ if (stat(File.c_str(),&Buf) != 0)
+ return false;
+ return ((Buf.st_mode & S_IFREG) != 0);
+}
+ /*}}}*/
// DirectoryExists - Check if a directory exists and is really one /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -304,6 +315,13 @@ std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> c
}
std::vector<string> List;
+
+ if (DirectoryExists(Dir.c_str()) == false)
+ {
+ _error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str());
+ return List;
+ }
+
Configuration::MatchAgainstConfig SilentIgnore("Dir::Ignore-Files-Silently");
DIR *D = opendir(Dir.c_str());
if (D == 0)
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 1380f06b4..146d917d8 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -93,6 +93,7 @@ bool RunScripts(const char *Cnf);
bool CopyFile(FileFd &From,FileFd &To);
int GetLock(string File,bool Errors = true);
bool FileExists(string File);
+bool RealFileExists(string File);
bool DirectoryExists(string const &Path) __attrib_const;
bool CreateDirectory(string const &Parent, string const &Path);
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index 594c085a5..d2557386d 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -167,7 +167,7 @@ bool pkgDepCache::readStateFile(OpProgress *Prog) /*{{{*/
{
FileFd state_file;
string const state = _config->FindFile("Dir::State::extended_states");
- if(FileExists(state)) {
+ if(RealFileExists(state)) {
state_file.Open(state, FileFd::ReadOnly);
int const file_size = state_file.Size();
if(Prog != NULL)
@@ -226,7 +226,7 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly) /*{{{*/
string const state = _config->FindFile("Dir::State::extended_states");
// if it does not exist, create a empty one
- if(!FileExists(state))
+ if(!RealFileExists(state))
{
StateFile.Open(state, FileFd::WriteAtomic);
StateFile.Close();
diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc
index f0bad78df..734f5b2c4 100644
--- a/apt-pkg/init.cc
+++ b/apt-pkg/init.cc
@@ -94,10 +94,10 @@ bool pkgInitConfig(Configuration &Cnf)
const char *Cfg = getenv("APT_CONFIG");
if (Cfg != 0)
{
- if (FileExists(Cfg) == true)
+ if (RealFileExists(Cfg) == true)
Res &= ReadConfigFile(Cnf,Cfg);
else
- _error->WarningE("FileExists",_("Unable to read %s"),Cfg);
+ _error->WarningE("RealFileExists",_("Unable to read %s"),Cfg);
}
// Read the configuration parts dir
@@ -109,7 +109,7 @@ bool pkgInitConfig(Configuration &Cnf)
// Read the main config file
string FName = Cnf.FindFile("Dir::Etc::main");
- if (FileExists(FName) == true)
+ if (RealFileExists(FName) == true)
Res &= ReadConfigFile(Cnf,FName);
if (Res == false)
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 4f9d56775..f05b6ca49 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -328,7 +328,7 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
if (File.empty() == true)
File = _config->FindFile("Dir::Etc::Preferences");
- if (FileExists(File) == false)
+ if (RealFileExists(File) == false)
return true;
FileFd Fd(File,FileFd::ReadOnly);
diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc
index c3ec9865a..851eefdfe 100644
--- a/apt-pkg/sourcelist.cc
+++ b/apt-pkg/sourcelist.cc
@@ -197,7 +197,7 @@ bool pkgSourceList::ReadMainList()
string Main = _config->FindFile("Dir::Etc::sourcelist");
string Parts = _config->FindDir("Dir::Etc::sourceparts");
- if (FileExists(Main) == true)
+ if (RealFileExists(Main) == true)
Res &= ReadAppend(Main);
else if (DirectoryExists(Parts) == false)
// Only warn if there are no sources.list.d.
@@ -205,9 +205,9 @@ bool pkgSourceList::ReadMainList()
if (DirectoryExists(Parts) == true)
Res &= ReadSourceDir(Parts);
- else if (FileExists(Main) == false)
+ else if (RealFileExists(Main) == false)
// Only warn if there is no sources.list file.
- _error->WarningE("FileExists", _("Unable to read %s"), Main.c_str());
+ _error->WarningE("RealFileExists", _("Unable to read %s"), Main.c_str());
return Res;
}
diff --git a/apt-pkg/vendorlist.cc b/apt-pkg/vendorlist.cc
index 589997081..92ff38894 100644
--- a/apt-pkg/vendorlist.cc
+++ b/apt-pkg/vendorlist.cc
@@ -21,11 +21,11 @@ bool pkgVendorList::ReadMainList()
Configuration Cnf;
string CnfFile = _config->FindDir("Dir::Etc::vendorparts");
- if (FileExists(CnfFile) == true)
+ if (DirectoryExists(CnfFile) == true)
if (ReadConfigDir(Cnf,CnfFile,true) == false)
return false;
CnfFile = _config->FindFile("Dir::Etc::vendorlist");
- if (FileExists(CnfFile) == true)
+ if (RealFileExists(CnfFile) == true)
if (ReadConfigFile(Cnf,CnfFile,true) == false)
return false;