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 --- ftparchive/byhash.cc | 5 ++--- ftparchive/multicompress.cc | 4 +--- ftparchive/writer.cc | 4 +--- 3 files changed, 4 insertions(+), 9 deletions(-) (limited to 'ftparchive') diff --git a/ftparchive/byhash.cc b/ftparchive/byhash.cc index 0a38457c0..354d089c3 100644 --- a/ftparchive/byhash.cc +++ b/ftparchive/byhash.cc @@ -41,9 +41,8 @@ void DeleteAllButMostRecent(std::string dir, int KeepFiles) auto files = GetListOfFilesInDir(dir, false); std::sort(files.begin(), files.end(), Cmp()); - for (auto I=files.begin(); INext) { I->TmpFile.Close(); - if (unlink(I->TmpFile.Name().c_str()) != 0) - _error->Errno("unlink",_("Problem unlinking %s"), - I->TmpFile.Name().c_str()); + RemoveFile("MultiCompress::Child", I->TmpFile.Name()); } return !_error->PendingError(); } diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 0bd2be566..c0223a74c 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -302,9 +302,7 @@ bool FTWScanner::Delink(string &FileName,const char *OriginalPath, _error->Errno("readlink",_("Failed to readlink %s"),OriginalPath); else { - if (unlink(OriginalPath) != 0) - _error->Errno("unlink",_("Failed to unlink %s"),OriginalPath); - else + if (RemoveFile("FTWScanner::Delink", OriginalPath)) { if (link(FileName.c_str(),OriginalPath) != 0) { -- cgit v1.2.3