Windows: replace unlink() with unicode-capable path_unlink()

This commit is contained in:
Jean-Francois Dockes 2020-06-02 10:56:55 +01:00
parent cb3a59f88f
commit f15e3f21fa
7 changed files with 19 additions and 11 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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

View File

@ -23,6 +23,7 @@
#include <sys/types.h>
#include "safesysstat.h"
#include "safeunistd.h"
#include "pathut.h"
#ifndef _WIN32
#include <sys/time.h>
#include <utime.h>
@ -83,7 +84,7 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags)
ret = true;
out:
if (ret == false && !(flags&COPYFILE_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&COPYFILE_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);
}

View File

@ -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

View File

@ -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

View File

@ -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<std::mutex> lock(remTmpFNMutex);
std::list<string>::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 {