summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2013-05-31 19:27:57 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2014-03-13 13:58:46 +0100
commit84baaae93badc2da7c1f4f356456762895cef278 (patch)
tree2c19ad39934b9fd814e25bffc73aa1f5454ea62f
parent68134bda8868a8614edf137aad7e9be61cd2a6ee (diff)
move fd duplication closer to the gz/bz2 open calls
Git-Dch: Ignore
-rw-r--r--apt-pkg/contrib/fileutl.cc41
1 files changed, 20 insertions, 21 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 55ba41128..2188f616a 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1067,30 +1067,12 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration:
{
Close();
Flags = (AutoClose) ? FileFd::AutoClose : 0;
- if (AutoClose == false && (
-#ifdef HAVE_ZLIB
- compressor.Name == "gzip" ||
-#endif
-#ifdef HAVE_BZ2
- compressor.Name == "bzip2" ||
-#endif
- false))
- {
- // Need to duplicate fd here or gzclose for cleanup will close the fd as well
- iFd = dup(Fd);
- }
- else
- iFd = Fd;
+ iFd = Fd;
this->FileName = "";
- if (Fd == -1 || OpenInternDescriptor(Mode, compressor) == false)
+ if (OpenInternDescriptor(Mode, compressor) == false)
{
if (iFd != -1 && (
-#ifdef HAVE_ZLIB
- compressor.Name == "gzip" ||
-#endif
-#ifdef HAVE_BZ2
- compressor.Name == "bzip2" ||
-#endif
+ (Flags & Compressed) == Compressed ||
AutoClose == true))
{
close (iFd);
@@ -1102,6 +1084,8 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration:
}
bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor)
{
+ if (iFd == -1)
+ return false;
if (compressor.Name == "." || compressor.Binary.empty() == true)
return true;
@@ -1110,6 +1094,21 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C
d = new FileFdPrivate();
d->openmode = Mode;
d->compressor = compressor;
+ if (AutoClose == false && (
+#ifdef HAVE_ZLIB
+ compressor.Name == "gzip" ||
+#endif
+#ifdef HAVE_BZ2
+ compressor.Name == "bzip2" ||
+#endif
+ false))
+ {
+ // Need to duplicate fd here or gz/bz2 close for cleanup will close the fd as well
+ int const internFd = dup(iFd);
+ if (internFd == -1)
+ return FileFdErrno("OpenInternDescriptor", _("Could not open file descriptor %d"), iFd);
+ iFd = internFd;
+ }
}
#ifdef HAVE_ZLIB