From eae6fd5d91862a73b8bbebaaf321b8feb2347a96 Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Thu, 24 Dec 2015 18:34:15 +0100 Subject: [PATCH] #131: wrapped function "remove" into module FileSystem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit under name “DeleteFile”. --- daemon/connect/WebDownloader.cpp | 2 +- daemon/feed/FeedCoordinator.cpp | 2 +- daemon/main/nzbget.cpp | 2 +- daemon/nntp/ArticleWriter.cpp | 4 ++-- daemon/postprocess/Cleanup.cpp | 2 +- daemon/postprocess/ParChecker.cpp | 2 +- daemon/postprocess/PrePostProcessor.cpp | 2 +- daemon/postprocess/Unpack.cpp | 2 +- daemon/queue/DiskState.cpp | 4 ++-- daemon/queue/HistoryCoordinator.cpp | 2 +- daemon/queue/QueueCoordinator.cpp | 2 +- daemon/queue/Scanner.cpp | 2 +- daemon/remote/XmlRpc.cpp | 2 +- daemon/util/FileSystem.cpp | 9 +++++++-- daemon/util/FileSystem.h | 1 + daemon/util/Log.cpp | 2 +- daemon/windows/WinConsole.cpp | 2 +- tests/postprocess/DupeMatcherTest.cpp | 2 +- tests/postprocess/ParRenamerTest.cpp | 2 +- 19 files changed, 27 insertions(+), 21 deletions(-) diff --git a/daemon/connect/WebDownloader.cpp b/daemon/connect/WebDownloader.cpp index 6d9f495c..e4351b37 100644 --- a/daemon/connect/WebDownloader.cpp +++ b/daemon/connect/WebDownloader.cpp @@ -182,7 +182,7 @@ WebDownloader::EStatus WebDownloader::Download() if (Status != adFinished) { // Download failed, delete broken output file - remove(m_outputFilename); + FileSystem::DeleteFile(m_outputFilename); } return Status; diff --git a/daemon/feed/FeedCoordinator.cpp b/daemon/feed/FeedCoordinator.cpp index c22901f1..a02d1e18 100644 --- a/daemon/feed/FeedCoordinator.cpp +++ b/daemon/feed/FeedCoordinator.cpp @@ -376,7 +376,7 @@ void FeedCoordinator::FeedCompleted(FeedDownloader* feedDownloader) !Util::EmptyStr(feedInfo->GetFeedScript()) ? feedInfo->GetFeedScript(): g_Options->GetFeedScript(), feedInfo->GetOutputFilename(), feedInfo->GetId()); FeedFile* feedFile = FeedFile::Create(feedInfo->GetOutputFilename()); - remove(feedInfo->GetOutputFilename()); + FileSystem::DeleteFile(feedInfo->GetOutputFilename()); NzbList addedNzbs; diff --git a/daemon/main/nzbget.cpp b/daemon/main/nzbget.cpp index 87a6e7b2..a49253f4 100644 --- a/daemon/main/nzbget.cpp +++ b/daemon/main/nzbget.cpp @@ -792,7 +792,7 @@ void Cleanup() if (g_CommandLineParser->GetDaemonMode() && !g_Reloading) { info("Deleting lock file"); - remove(g_Options->GetLockFile()); + FileSystem::DeleteFile(g_Options->GetLockFile()); } delete g_Options; } diff --git a/daemon/nntp/ArticleWriter.cpp b/daemon/nntp/ArticleWriter.cpp index 64bbf566..a6f1c2cf 100644 --- a/daemon/nntp/ArticleWriter.cpp +++ b/daemon/nntp/ArticleWriter.cpp @@ -199,8 +199,8 @@ void ArticleWriter::Finish(bool success) if (!success) { - remove(m_tempFilename); - remove(m_resultFilename); + FileSystem::DeleteFile(m_tempFilename); + FileSystem::DeleteFile(m_resultFilename); return; } diff --git a/daemon/postprocess/Cleanup.cpp b/daemon/postprocess/Cleanup.cpp index 37eb165f..8bcd13ed 100644 --- a/daemon/postprocess/Cleanup.cpp +++ b/daemon/postprocess/Cleanup.cpp @@ -219,7 +219,7 @@ bool CleanupController::Cleanup(const char* destDir, bool *deleted) if (deleteIt) { PrintMessage(Message::mkInfo, "Deleting file %s", filename); - if (remove(fullFilename) != 0) + if (!FileSystem::DeleteFile(fullFilename)) { PrintMessage(Message::mkError, "Could not delete file %s: %s", *fullFilename, *FileSystem::GetLastErrorMessage()); diff --git a/daemon/postprocess/ParChecker.cpp b/daemon/postprocess/ParChecker.cpp index a6bbb5bd..259d2cab 100644 --- a/daemon/postprocess/ParChecker.cpp +++ b/daemon/postprocess/ParChecker.cpp @@ -1323,7 +1323,7 @@ void ParChecker::DeleteLeftovers() if (!found) { PrintMessage(Message::mkInfo, "Deleting file %s", FileSystem::BaseFileName(sourceFile->FileName().c_str())); - remove(sourceFile->FileName().c_str()); + FileSystem::DeleteFile(sourceFile->FileName().c_str()); } } } diff --git a/daemon/postprocess/PrePostProcessor.cpp b/daemon/postprocess/PrePostProcessor.cpp index c2c5821e..e675f92d 100644 --- a/daemon/postprocess/PrePostProcessor.cpp +++ b/daemon/postprocess/PrePostProcessor.cpp @@ -319,7 +319,7 @@ void PrePostProcessor::DeleteCleanup(NzbInfo* nzbInfo) if (FileSystem::FileExists(fullFileName)) { detail("Deleting file %s", completedFile->GetFileName()); - remove(fullFileName); + FileSystem::DeleteFile(fullFileName); } } diff --git a/daemon/postprocess/Unpack.cpp b/daemon/postprocess/Unpack.cpp index e280c886..062a4dc4 100644 --- a/daemon/postprocess/Unpack.cpp +++ b/daemon/postprocess/Unpack.cpp @@ -734,7 +734,7 @@ bool UnpackController::Cleanup() BString<1024> dstFile("%s%c%s", !m_finalDir.Empty() ? *m_finalDir : *m_destDir, PATH_SEPARATOR, filename); // silently overwrite existing files - remove(dstFile); + FileSystem::DeleteFile(dstFile); bool hiddenFile = filename[0] == '.'; diff --git a/daemon/queue/DiskState.cpp b/daemon/queue/DiskState.cpp index 9484d440..c8e1f5b5 100644 --- a/daemon/queue/DiskState.cpp +++ b/daemon/queue/DiskState.cpp @@ -101,7 +101,7 @@ StateFile::~StateFile() void StateFile::Discard() { - remove(m_destFilename); + FileSystem::DeleteFile(m_destFilename); } bool StateFile::FileExists() @@ -144,7 +144,7 @@ bool StateFile::FinishWriteTransaction() // now rename to dest file name remove(m_destFilename); - if (rename(m_tempFilename, m_destFilename)) + if (!FileSystem::MoveFile(m_tempFilename, m_destFilename)) { error("Error saving diskstate: Could not rename file %s to %s: %s", *m_tempFilename, *m_destFilename, *FileSystem::GetLastErrorMessage()); diff --git a/daemon/queue/HistoryCoordinator.cpp b/daemon/queue/HistoryCoordinator.cpp index 415180a1..787d464d 100644 --- a/daemon/queue/HistoryCoordinator.cpp +++ b/daemon/queue/HistoryCoordinator.cpp @@ -131,7 +131,7 @@ void HistoryCoordinator::DeleteDiskFiles(NzbInfo* nzbInfo) if (FileSystem::FileExists(name1)) { info("Deleting file %s", name1); - remove(name1); + FileSystem::DeleteFile(name1); } } diff --git a/daemon/queue/QueueCoordinator.cpp b/daemon/queue/QueueCoordinator.cpp index e6122af6..160aabbb 100644 --- a/daemon/queue/QueueCoordinator.cpp +++ b/daemon/queue/QueueCoordinator.cpp @@ -820,7 +820,7 @@ void QueueCoordinator::DiscardDiskFile(FileInfo* fileInfo) ArticleInfo* pa = *it; if (pa->GetResultFilename()) { - remove(pa->GetResultFilename()); + FileSystem::DeleteFile(pa->GetResultFilename()); } } } diff --git a/daemon/queue/Scanner.cpp b/daemon/queue/Scanner.cpp index 0c85f710..8c3187e3 100644 --- a/daemon/queue/Scanner.cpp +++ b/daemon/queue/Scanner.cpp @@ -622,7 +622,7 @@ Scanner::EAddStatus Scanner::AddExternalFile(const char* nzbName, const char* ca { error("Could not move file %s to %s: %s", *tempFileName, *scanFileName, *FileSystem::GetLastErrorMessage()); - remove(tempFileName); + FileSystem::DeleteFile(tempFileName); m_scanMutex.Unlock(); // UNLOCK return asFailed; } diff --git a/daemon/remote/XmlRpc.cpp b/daemon/remote/XmlRpc.cpp index 3084e22f..7727f27f 100644 --- a/daemon/remote/XmlRpc.cpp +++ b/daemon/remote/XmlRpc.cpp @@ -3097,7 +3097,7 @@ void ReadUrlXmlCommand::Execute() BuildErrorResponse(3, "Could not read url"); } - remove(tempFileName); + FileSystem::DeleteFile(tempFileName); } // string checkupdates() diff --git a/daemon/util/FileSystem.cpp b/daemon/util/FileSystem.cpp index 7f76e8ef..2b98da47 100644 --- a/daemon/util/FileSystem.cpp +++ b/daemon/util/FileSystem.cpp @@ -363,7 +363,7 @@ bool FileSystem::MoveFile(const char* srcFilename, const char* dstFilename) #ifndef WIN32 if (!ok && errno == EXDEV) { - ok = CopyFile(srcFilename, dstFilename) && remove(srcFilename) == 0; + ok = CopyFile(srcFilename, dstFilename) && DeleteFile(srcFilename); } #endif @@ -402,6 +402,11 @@ bool FileSystem::CopyFile(const char* srcFilename, const char* dstFilename) return true; } +bool FileSystem::DeleteFile(const char* filename) +{ + return remove(filename) == 0; +} + bool FileSystem::FileExists(const char* filename) { #ifdef WIN32 @@ -425,7 +430,7 @@ bool FileSystem::FileExists(const char* filename) bool FileSystem::FileExists(const char* path, const char* filenameWithoutPath) { BString<1024> fullFilename("%s%c%s", path, (int)PATH_SEPARATOR, filenameWithoutPath); - bool exists = FileSystem::FileExists(fullFilename); + bool exists = FileExists(fullFilename); return exists; } diff --git a/daemon/util/FileSystem.h b/daemon/util/FileSystem.h index 4b45f11f..a9e3455c 100644 --- a/daemon/util/FileSystem.h +++ b/daemon/util/FileSystem.h @@ -43,6 +43,7 @@ public: static CString MakeUniqueFilename(const char* destDir, const char* basename); static bool MoveFile(const char* srcFilename, const char* dstFilename); static bool CopyFile(const char* srcFilename, const char* dstFilename); + static bool DeleteFile(const char* filename); static bool FileExists(const char* filename); static bool FileExists(const char* path, const char* filenameWithoutPath); static bool DirectoryExists(const char* dirFilename); diff --git a/daemon/util/Log.cpp b/daemon/util/Log.cpp index 65d0c33f..3fdc6671 100644 --- a/daemon/util/Log.cpp +++ b/daemon/util/Log.cpp @@ -343,7 +343,7 @@ void Log::UnlockMessages() void Log::ResetLog() { - remove(g_Options->GetLogFile()); + FileSystem::DeleteFile(g_Options->GetLogFile()); } void Log::RotateLog() diff --git a/daemon/windows/WinConsole.cpp b/daemon/windows/WinConsole.cpp index 365d97a0..99381e13 100644 --- a/daemon/windows/WinConsole.cpp +++ b/daemon/windows/WinConsole.cpp @@ -1032,7 +1032,7 @@ void WinConsole::ResetFactoryDefaults() // delete old config file in the program's directory path.Format("%s\\nzbget.conf", g_Options->GetAppDir()); - remove(path); + FileSystem::DeleteFile(path); errmsg = FileSystem::GetLastErrorMessage(); if (FileSystem::FileExists(path)) diff --git a/tests/postprocess/DupeMatcherTest.cpp b/tests/postprocess/DupeMatcherTest.cpp index e1b4911c..c88da0e1 100644 --- a/tests/postprocess/DupeMatcherTest.cpp +++ b/tests/postprocess/DupeMatcherTest.cpp @@ -49,7 +49,7 @@ TEST_CASE("Disk matcher", "[Par][DupeMatcher][Slow][TestData]") std::string dupe2(TestUtil::WorkingDir() + "/dupe2"); REQUIRE(FileSystem::ForceDirectories(dupe2.c_str(), errmsg)); TestUtil::CopyAllFiles(dupe2, TestUtil::TestDataDir() + "/parchecker"); - remove((dupe2 + "/testfile.nfo").c_str()); + FileSystem::DeleteFile((dupe2 + "/testfile.nfo").c_str()); std::string rardupe1(TestUtil::TestDataDir() + "/dupematcher1"); std::string rardupe2(TestUtil::TestDataDir() + "/dupematcher2"); diff --git a/tests/postprocess/ParRenamerTest.cpp b/tests/postprocess/ParRenamerTest.cpp index 59bd4fbf..211ed2e8 100644 --- a/tests/postprocess/ParRenamerTest.cpp +++ b/tests/postprocess/ParRenamerTest.cpp @@ -99,7 +99,7 @@ TEST_CASE("Par-renamer: detecting missing", "[Par][ParRenamer][Slow][TestData]") ParRenamerMock parRenamer; FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile.dat").c_str(), (TestUtil::WorkingDir() + "/123456").c_str()); parRenamer.SetDetectMissing(true); - REQUIRE(remove((TestUtil::WorkingDir() + "/testfile.nfo").c_str()) == 0); + REQUIRE(FileSystem::DeleteFile((TestUtil::WorkingDir() + "/testfile.nfo").c_str())); parRenamer.Execute(); REQUIRE(parRenamer.GetStatus() == ParRenamer::psSuccess);