diff options
author | David Kalnischkies <david@kalnischkies.de> | 2019-01-23 22:50:45 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2019-01-24 00:33:16 +0100 |
commit | 73e3459689c05cd62f15c29d2faddb0fc215ef5e (patch) | |
tree | 5cdddd899253499de6f9b43b171ee27a8674a0f7 /apt-pkg/contrib/fileutl.cc | |
parent | e2965b0b6bdd68ffcad0e06d11755412a7e16e50 (diff) |
Merge and reuse tmp file handling across the board
Having many rather similar implementations especially if one is exported
while others aren't (and the rest of it not factored out at all) seems
suboptimal.
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index eab05de4f..52be3a6a6 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -3114,7 +3114,7 @@ FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * co snprintf(fn, sizeof(fn), "%s/%s.XXXXXX", tempdir.c_str(), Prefix.c_str()); int const fd = mkstemp(fn); - if(ImmediateUnlink) + if (ImmediateUnlink) unlink(fn); if (fd < 0) { @@ -3123,13 +3123,15 @@ FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * co delete Fd; return nullptr; } - if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite, FileFd::None, true)) + if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite | FileFd::BufferedWrite, FileFd::None, true)) { _error->Errno("GetTempFile",_("Unable to write to %s"),fn); if (TmpFd == nullptr) delete Fd; return nullptr; } + if (ImmediateUnlink == false) + Fd->SetFileName(fn); return Fd; } /*}}}*/ |