summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc73
1 files changed, 46 insertions, 27 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index e4c40fb4f..630a98ce4 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -19,52 +19,52 @@
// Include Files /*{{{*/
#include <config.h>
-#include <apt-pkg/fileutl.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/sptr.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
#include <apt-pkg/macros.h>
+#include <apt-pkg/sptr.h>
+#include <apt-pkg/strutl.h>
-#include <ctype.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <sys/select.h>
-#include <time.h>
-#include <string>
-#include <vector>
+#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <cstdio>
#include <iostream>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/wait.h>
+#include <string>
+#include <vector>
+#include <ctype.h>
#include <dirent.h>
-#include <signal.h>
#include <errno.h>
+#include <fcntl.h>
#include <glob.h>
-#include <pwd.h>
#include <grp.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
-#include <set>
#include <algorithm>
#include <memory>
+#include <set>
#ifdef HAVE_ZLIB
- #include <zlib.h>
+#include <zlib.h>
#endif
#ifdef HAVE_BZ2
- #include <bzlib.h>
+#include <bzlib.h>
#endif
#ifdef HAVE_LZMA
- #include <lzma.h>
+#include <lzma.h>
#endif
#ifdef HAVE_LZ4
- #include <lz4frame.h>
+#include <lz4frame.h>
#endif
#include <endian.h>
#include <stdint.h>
@@ -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")
@@ -2832,7 +2847,7 @@ std::string GetTempDir(std::string const &User)
FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * const TmpFd) /*{{{*/
{
char fn[512];
- FileFd * const Fd = TmpFd == NULL ? new FileFd() : TmpFd;
+ FileFd * const Fd = TmpFd == nullptr ? new FileFd() : TmpFd;
std::string const tempdir = GetTempDir();
snprintf(fn, sizeof(fn), "%s/%s.XXXXXX",
@@ -2843,12 +2858,16 @@ FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * co
if (fd < 0)
{
_error->Errno("GetTempFile",_("Unable to mkstemp %s"), fn);
- return NULL;
+ if (TmpFd == nullptr)
+ delete Fd;
+ return nullptr;
}
if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite, FileFd::None, true))
{
_error->Errno("GetTempFile",_("Unable to write to %s"),fn);
- return NULL;
+ if (TmpFd == nullptr)
+ delete Fd;
+ return nullptr;
}
return Fd;
}