From e6e8a7ff6d5ecf0fec228ad91f3a0ff32987fc69 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 9 Oct 2015 12:50:37 +0300 Subject: [PATCH] Fix for build on drone.io. --HG-- branch : develop --- src/app/tape/tmainwindow.cpp | 23 ++++++----------- src/app/valentina/mainwindow.cpp | 43 +++++++++++--------------------- src/libs/vmisc/vlockguard.h | 21 ++++++---------- 3 files changed, 29 insertions(+), 58 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 8a5570d60..abef298c4 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -191,10 +191,9 @@ void TMainWindow::LoadFile(const QString &path) VlpCreateLock(lock, QFileInfo(path).fileName()+".lock"); - if (lock->GetLockError() == QLockFile::LockFailedError) + if (not lock->IsLocked()) { qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); - lock.reset(); if (qApp->IsTestMode()) { std::exit(V_EX_NOINPUT); @@ -515,16 +514,13 @@ void TMainWindow::FileSaveAs() if (QFileInfo(fileName).exists()) { + // Temporary try to lock the file before saving VLockGuard tmp(fileName + ".lock"); - if (not tmp.IsLocked()) { - if (lock->GetLockError() == QLockFile::LockFailedError) - { - qCCritical(tMainWindow, "%s", - qUtf8Printable(tr("Failed to lock. This file already opened in another window."))); - return; - } + qCCritical(tMainWindow, "%s", + qUtf8Printable(tr("Failed to lock. This file already opened in another window."))); + return; } } @@ -543,15 +539,11 @@ void TMainWindow::FileSaveAs() return; } - lock.reset(); - VlpCreateLock(lock, fileName + ".lock"); - - if (lock->GetLockError() == QLockFile::LockFailedError) + if (not lock->IsLocked()) { qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window. " "Expect collissions when run 2 copies of the program."))); - lock.reset(); return; } } @@ -952,8 +944,7 @@ void TMainWindow::ImportFromPattern() } VLockGuard tmp(QFileInfo(mPath).fileName()+".lock"); - - if (tmp.GetLockError() == QLockFile::LockFailedError) + if (not tmp.IsLocked()) { qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); return; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index d38ee33fb..7fe3b06f6 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1954,16 +1954,13 @@ bool MainWindow::SaveAs() if (QFileInfo(fileName).exists()) { + // Temporary try to lock the file before saving VLockGuard tmp(fileName + ".lock"); - if (not tmp.IsLocked()) { - if (lock->GetLockError() == QLockFile::LockFailedError) - { - qCCritical(vMainWindow, "%s", - qUtf8Printable(tr("Failed to lock. This file already opened in another window."))); - return false; - } + qCCritical(vMainWindow, "%s", + qUtf8Printable(tr("Failed to lock. This file already opened in another window."))); + return false; } } @@ -1982,9 +1979,6 @@ bool MainWindow::SaveAs() return result; } - qCDebug(vMainWindow, "Unlock old file"); - lock.reset(); - qCDebug(vMainWindow, "Locking file"); VlpCreateLock(lock, fileName+".lock"); @@ -1996,13 +1990,9 @@ bool MainWindow::SaveAs() { qCDebug(vMainWindow, "Failed to lock %s", qUtf8Printable(fileName)); qCDebug(vMainWindow, "Error type: %d", lock->GetLockError()); - if (lock->GetLockError() == QLockFile::LockFailedError) - { - qCCritical(vMainWindow, "%s", - qUtf8Printable(tr("Failed to lock. This file already opened in another window. Expect " - "collissions when run 2 copies of the program."))); - lock.reset(); - } + qCCritical(vMainWindow, "%s", + qUtf8Printable(tr("Failed to lock. This file already opened in another window. Expect " + "collissions when run 2 copies of the program."))); } return result; @@ -3310,18 +3300,15 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu { qCDebug(vMainWindow, "Failed to lock %s", qUtf8Printable(fileName)); qCDebug(vMainWindow, "Error type: %d", lock->GetLockError()); - if (lock->GetLockError() == QLockFile::LockFailedError) + qCCritical(vMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); + Clear(); + if (VApplication::CheckGUI()) { - qCCritical(vMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); - Clear(); - if (VApplication::CheckGUI()) - { - return false; - } - else - { - std::exit(V_EX_NOINPUT); - } + return false; + } + else + { + std::exit(V_EX_NOINPUT); } } diff --git a/src/libs/vmisc/vlockguard.h b/src/libs/vmisc/vlockguard.h index 395a1a265..ec7d822f6 100644 --- a/src/libs/vmisc/vlockguard.h +++ b/src/libs/vmisc/vlockguard.h @@ -145,21 +145,14 @@ bool VLockGuard::TryLock(const QString &lockName, int stale, int timeou lock.reset(new QLockFile(lockName)); lock->setStaleLockTime(stale); - for (int i = 0; i < 2 && !lock->tryLock(timeout); i++) + if (QLockFile::LockFailedError == lock->error()) { - if (QLockFile::LockFailedError != lock->error()) - { - break; - } - else - { - // This happens if a stale lock file exists and another process uses that PID. - // Try removing the stale file, which will fail if a real process is holding a - // file-level lock. A false error is more problematic than not locking properly - // on corner-case systems. - lock->removeStaleLockFile(); - lock->tryLock(timeout); - } + // This happens if a stale lock file exists and another process uses that PID. + // Try removing the stale file, which will fail if a real process is holding a + // file-level lock. A false error is more problematic than not locking properly + // on corner-case systems. + lock->removeStaleLockFile(); + lock->tryLock(timeout); } res = QLockFile::NoError == (lockError = lock->error()); if (!res)