diff --git a/src/index/recollindex.cpp b/src/index/recollindex.cpp index 92dced4e..36eb3f10 100644 --- a/src/index/recollindex.cpp +++ b/src/index/recollindex.cpp @@ -145,7 +145,7 @@ public: if (path_exists(m_stopfilename)) { LOGINF("recollindex: asking indexer to stop because " << m_stopfilename << " exists\n"); - unlink(m_stopfilename.c_str()); + path_unlink(m_stopfilename); stopindexing = true; } if (stopindexing) { diff --git a/src/index/webqueue.cpp b/src/index/webqueue.cpp index 808326f4..f1e2967a 100644 --- a/src/index/webqueue.cpp +++ b/src/index/webqueue.cpp @@ -472,10 +472,10 @@ WebQueueIndexer::processone(const string &path, dounlink = true; out: if (dounlink) { - if (unlink(path.c_str())) { + if (!path_unlink(path)) { LOGSYSERR("WebQueueIndexer::processone", "unlink", path); } - if (unlink(dotpath.c_str())) { + if (!path_unlink(dotpath)) { LOGSYSERR("WebQueueIndexer::processone", "unlink", dotpath); } } diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index 023bb59d..6cedda3c 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -246,7 +246,7 @@ void Db::Native::openWrite(const string& dir, Db::OpenMode mode) if (mode == DbTrunc) { if (path_exists(path_cat(dir, "iamchert"))) { wipedir(dir); - unlink(dir.c_str()); + path_unlink(dir); } } #endif diff --git a/src/utils/copyfile.cpp b/src/utils/copyfile.cpp index 8972ba3f..1cb2d6ee 100644 --- a/src/utils/copyfile.cpp +++ b/src/utils/copyfile.cpp @@ -23,6 +23,7 @@ #include #include "safesysstat.h" #include "safeunistd.h" +#include "pathut.h" #ifndef _WIN32 #include #include @@ -83,7 +84,7 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags) ret = true; out: if (ret == false && !(flags©FILE_NOERRUNLINK)) - ::unlink(dst); + path_unlink(dst); if (sfd >= 0) ::close(sfd); if (dfd >= 0) @@ -121,7 +122,7 @@ bool stringtofile(const string& dt, const char *dst, string& reason, ret = true; out: if (ret == false && !(flags©FILE_NOERRUNLINK)) - ::unlink(dst); + path_unlink(dst); if (dfd >= 0) ::close(dfd); return ret; @@ -133,7 +134,7 @@ bool renameormove(const char *src, const char *dst, string &reason) // Windows refuses to rename to an existing file. It appears that // there are workarounds (See MoveFile, MoveFileTransacted), but // anyway we are not expecting atomicity here. - unlink(dst); + path_unlink(dst); #endif // First try rename(2). If this succeeds we're done. If this fails @@ -182,7 +183,7 @@ bool renameormove(const char *src, const char *dst, string &reason) utimes(dst, times); #endif // All ok, get rid of origin - if (unlink(src) < 0) { + if (!path_unlink(src)) { reason += string("Can't unlink ") + src + "Error : " + strerror(errno); } diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 78839bd4..d44c21b6 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -854,6 +854,12 @@ bool path_chdir(const std::string& path) return CHDIR(syspath) == 0; } +bool path_unlink(const std::string& path) +{ + SYSPATH(path, syspath); + return UNLINK(syspath); +} + #if !defined(__GNUC__) || __GNUC__ > 4 || defined(__clang__) // Not sure what g++ version supports fstream assignment but 4.9 // (jessie) certainly does not diff --git a/src/utils/pathut.h b/src/utils/pathut.h index 646a0517..cf447e3e 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -135,6 +135,7 @@ extern bool path_makepath(const std::string& path, int mode); /// extern bool path_chdir(const std::string& path); +extern bool path_unlink(const std::string& path); /* Open file, trying to do the right thing with non-ASCII paths on * Windows, where it only works with MSVC at the moment if the path is diff --git a/src/utils/rclutil.cpp b/src/utils/rclutil.cpp index 7902c79f..a7d67666 100644 --- a/src/utils/rclutil.cpp +++ b/src/utils/rclutil.cpp @@ -170,7 +170,7 @@ static bool path_gettempfilename(string& filename, string& reason) return false; } close(fd); - unlink(cp); + path_unlink(cp); filename = cp; free(cp); return true; @@ -474,7 +474,7 @@ TempFile::Internal::~Internal() { if (!m_filename.empty() && !m_noremove) { LOGDEB1("TempFile:~: unlinking " << m_filename << endl); - if (unlink(m_filename.c_str()) != 0) { + if (!path_unlink(m_filename)) { LOGSYSERR("TempFile:~", "unlink", m_filename); #ifdef _WIN32 { @@ -500,7 +500,7 @@ void TempFile::tryRemoveAgain() std::unique_lock lock(remTmpFNMutex); std::list::iterator pos = remainingTempFileNames.begin(); while (pos != remainingTempFileNames.end()) { - if (unlink(pos->c_str()) != 0) { + if (!path_unlink(*pos)) { LOGSYSERR("TempFile::tryRemoveAgain", "unlink", *pos); pos++; } else {