summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2017-03-19 12:59:44 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2017-06-26 23:31:15 +0200
commit24fbb6adb071c39e24f9b0a89aadc7d5673a8775 (patch)
tree021630fdf588125bad82f2385000e54431c86efa /apt-pkg/contrib/fileutl.cc
parent0cbe571a44468806af95f3d8661b07b01704eb26 (diff)
Avoid chdir in acquire clean with unlinkat
POSIX.1-2008 gives us a range of *at calls to deal with files including the unlinkat so we can remove a file from a directory based on a path to the file relative to the directory. (In our case here the path we have is just the filename) We avoid changing directories in this way which e.g. fails if the directory we started in no longer exists or is otherwise inaccessible. Closes: 860738
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index e4c40fb4f..8ce8d5baf 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -178,6 +178,21 @@ bool CopyFile(FileFd &From,FileFd &To)
return true;
}
/*}}}*/
+bool RemoveFileAt(char const * const Function, int const dirfd, std::string const &FileName)/*{{{*/
+{
+ if (FileName == "/dev/null")
+ return true;
+ errno = 0;
+ if (unlinkat(dirfd, FileName.c_str(), 0) != 0)
+ {
+ if (errno == ENOENT)
+ return true;
+
+ return _error->WarningE(Function,_("Problem unlinking the file %s"), FileName.c_str());
+ }
+ return true;
+}
+ /*}}}*/
bool RemoveFile(char const * const Function, std::string const &FileName)/*{{{*/
{
if (FileName == "/dev/null")