From f6f42d79534783e7be7a011854a9d2bfa3e52a04 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 4 Jun 2016 17:00:40 +0200 Subject: [PATCH] Fixed: Error 18 when moving a file between different file systems --- code/nel/src/misc/path.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index b4057e315..061c938a5 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -2374,11 +2374,33 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c #else if (rename (ssrc.c_str(), sdest.c_str()) == -1) { - nlwarning ("PATH: CopyMoveFile error: can't rename '%s' into '%s', error %u", - ssrc.c_str(), - sdest.c_str(), - errno); - return false; + // unable to move because file systems are different + if (errno == EXDEV) + { + // different file system, we need to copy and delete file manually + if (!CopyMoveFile(dest, src, true, failIfExists, progress)) return false; + + // get modification time + uint32 modificationTime = CFile::getFileModificationDate(src); + + // delete original file + if (!CFile::deleteFile(src)) return false; + + // set same modification time + if (!CFile::setFileModificationDate(dest, modificationTime)) + { + nlwarning("Unable to set modification time %s (%u) for %s", timestampToHumanReadable(modificationTime).c_str(), modificationTime, dest.c_str()); + } + } + else + { + nlwarning("PATH: CopyMoveFile error: can't rename '%s' into '%s', error %u", + ssrc.c_str(), + sdest.c_str(), + errno); + + return false; + } } #endif }