From: Richard Kimberly Heck Date: Sun, 7 Jul 2019 17:13:52 +0000 (-0400) Subject: Fix bug #10091. X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0b71b0b4ba7a6d0178cba36394ab9f8c33c6a24f;p=features.git Fix bug #10091. See the discussion. The decision was just to keep re-trying for a bit, since the lock preventing us from removing the old file seems to clear after a bit. --- diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index b485ae9395..7c47de0948 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -30,6 +30,10 @@ #include #include +#ifdef _WIN32 +#include +#endif + #include #include @@ -263,9 +267,22 @@ bool FileName::renameTo(FileName const & name) const bool FileName::moveTo(FileName const & name) const { LYXERR(Debug::FILES, "Moving " << *this << " to " << name); +#ifdef _WIN32 + // there's a locking problem on Windows sometimes, so + // we will keep trying for five seconds, in the hope + // that clears. + bool removed = QFile::remove(name.d->fi.absoluteFilePath()); + int tries = 1; + while (!removed && tries < 6) { + QThread::sleep(1); + removed = QFile::remove(name.d->fi.absoluteFilePath()); + tries++; + } +#else QFile::remove(name.d->fi.absoluteFilePath()); +#endif - bool success = QFile::rename(d->fi.absoluteFilePath(), + bool const success = QFile::rename(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath()); if (!success) LYXERR0("Could not move file " << *this << " to " << name);