From ce1f3a2c616b86da657c1c796efa5f4d18c30c39 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 2 Nov 2015 18:49:52 +0100 Subject: wrap every unlink call to check for != /dev/null Unlinking /dev/null is bad, we shouldn't do that. Also, we should print at least a warning if we tried to unlink a file but didn't manage to pull it of (ignoring the case were the file is /dev/null or doesn't exist in the first place). This got triggered by a relatively unlikely to cause problem in pkgAcquire::Worker::PrepareFiles which would while temporary uncompressed files (which are set to keep compressed) figure out that to files are the same and prepare for sharing by deleting them. Bad move. That also shows why not printing a warning is a bad idea as this hide the error for in non-root test runs. Git-Dch: Ignore --- apt-pkg/cdrom.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg/cdrom.cc') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index b950648b9..29eeca066 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -426,8 +426,8 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf) { string DFile = _config->FindFile("Dir::State::cdroms"); string NewFile = DFile + ".new"; - - unlink(NewFile.c_str()); + + RemoveFile("WriteDatabase", NewFile); ofstream Out(NewFile.c_str()); if (!Out) return _error->Errno("ofstream::ofstream", @@ -468,7 +468,7 @@ bool pkgCdrom::WriteSourceList(string Name,vector &List,bool Source) return _error->Errno("ifstream::ifstream","Opening %s",File.c_str()); string NewFile = File + ".new"; - unlink(NewFile.c_str()); + RemoveFile("WriteDatabase", NewFile); ofstream Out(NewFile.c_str()); if (!Out) return _error->Errno("ofstream::ofstream", -- cgit v1.2.3