Fix for build on drone.io.
--HG-- branch : develop
This commit is contained in:
parent
894444297b
commit
e6e8a7ff6d
|
@ -191,10 +191,9 @@ void TMainWindow::LoadFile(const QString &path)
|
||||||
|
|
||||||
VlpCreateLock(lock, QFileInfo(path).fileName()+".lock");
|
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.")));
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
|
||||||
lock.reset();
|
|
||||||
if (qApp->IsTestMode())
|
if (qApp->IsTestMode())
|
||||||
{
|
{
|
||||||
std::exit(V_EX_NOINPUT);
|
std::exit(V_EX_NOINPUT);
|
||||||
|
@ -515,16 +514,13 @@ void TMainWindow::FileSaveAs()
|
||||||
|
|
||||||
if (QFileInfo(fileName).exists())
|
if (QFileInfo(fileName).exists())
|
||||||
{
|
{
|
||||||
|
// Temporary try to lock the file before saving
|
||||||
VLockGuard<char> tmp(fileName + ".lock");
|
VLockGuard<char> tmp(fileName + ".lock");
|
||||||
|
|
||||||
if (not tmp.IsLocked())
|
if (not tmp.IsLocked())
|
||||||
{
|
{
|
||||||
if (lock->GetLockError() == QLockFile::LockFailedError)
|
qCCritical(tMainWindow, "%s",
|
||||||
{
|
qUtf8Printable(tr("Failed to lock. This file already opened in another window.")));
|
||||||
qCCritical(tMainWindow, "%s",
|
return;
|
||||||
qUtf8Printable(tr("Failed to lock. This file already opened in another window.")));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,15 +539,11 @@ void TMainWindow::FileSaveAs()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock.reset();
|
|
||||||
|
|
||||||
VlpCreateLock(lock, fileName + ".lock");
|
VlpCreateLock(lock, fileName + ".lock");
|
||||||
|
if (not lock->IsLocked())
|
||||||
if (lock->GetLockError() == QLockFile::LockFailedError)
|
|
||||||
{
|
{
|
||||||
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window. "
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window. "
|
||||||
"Expect collissions when run 2 copies of the program.")));
|
"Expect collissions when run 2 copies of the program.")));
|
||||||
lock.reset();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -952,8 +944,7 @@ void TMainWindow::ImportFromPattern()
|
||||||
}
|
}
|
||||||
|
|
||||||
VLockGuard<char> tmp(QFileInfo(mPath).fileName()+".lock");
|
VLockGuard<char> tmp(QFileInfo(mPath).fileName()+".lock");
|
||||||
|
if (not tmp.IsLocked())
|
||||||
if (tmp.GetLockError() == QLockFile::LockFailedError)
|
|
||||||
{
|
{
|
||||||
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1954,16 +1954,13 @@ bool MainWindow::SaveAs()
|
||||||
|
|
||||||
if (QFileInfo(fileName).exists())
|
if (QFileInfo(fileName).exists())
|
||||||
{
|
{
|
||||||
|
// Temporary try to lock the file before saving
|
||||||
VLockGuard<char> tmp(fileName + ".lock");
|
VLockGuard<char> tmp(fileName + ".lock");
|
||||||
|
|
||||||
if (not tmp.IsLocked())
|
if (not tmp.IsLocked())
|
||||||
{
|
{
|
||||||
if (lock->GetLockError() == QLockFile::LockFailedError)
|
qCCritical(vMainWindow, "%s",
|
||||||
{
|
qUtf8Printable(tr("Failed to lock. This file already opened in another window.")));
|
||||||
qCCritical(vMainWindow, "%s",
|
return false;
|
||||||
qUtf8Printable(tr("Failed to lock. This file already opened in another window.")));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1982,9 +1979,6 @@ bool MainWindow::SaveAs()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(vMainWindow, "Unlock old file");
|
|
||||||
lock.reset();
|
|
||||||
|
|
||||||
qCDebug(vMainWindow, "Locking file");
|
qCDebug(vMainWindow, "Locking file");
|
||||||
VlpCreateLock(lock, fileName+".lock");
|
VlpCreateLock(lock, fileName+".lock");
|
||||||
|
|
||||||
|
@ -1996,13 +1990,9 @@ bool MainWindow::SaveAs()
|
||||||
{
|
{
|
||||||
qCDebug(vMainWindow, "Failed to lock %s", qUtf8Printable(fileName));
|
qCDebug(vMainWindow, "Failed to lock %s", qUtf8Printable(fileName));
|
||||||
qCDebug(vMainWindow, "Error type: %d", lock->GetLockError());
|
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 "
|
||||||
qCCritical(vMainWindow, "%s",
|
"collissions when run 2 copies of the program.")));
|
||||||
qUtf8Printable(tr("Failed to lock. This file already opened in another window. Expect "
|
|
||||||
"collissions when run 2 copies of the program.")));
|
|
||||||
lock.reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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, "Failed to lock %s", qUtf8Printable(fileName));
|
||||||
qCDebug(vMainWindow, "Error type: %d", lock->GetLockError());
|
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.")));
|
return false;
|
||||||
Clear();
|
}
|
||||||
if (VApplication::CheckGUI())
|
else
|
||||||
{
|
{
|
||||||
return false;
|
std::exit(V_EX_NOINPUT);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::exit(V_EX_NOINPUT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,21 +145,14 @@ bool VLockGuard<Guarded>::TryLock(const QString &lockName, int stale, int timeou
|
||||||
lock.reset(new QLockFile(lockName));
|
lock.reset(new QLockFile(lockName));
|
||||||
lock->setStaleLockTime(stale);
|
lock->setStaleLockTime(stale);
|
||||||
|
|
||||||
for (int i = 0; i < 2 && !lock->tryLock(timeout); i++)
|
if (QLockFile::LockFailedError == lock->error())
|
||||||
{
|
{
|
||||||
if (QLockFile::LockFailedError != lock->error())
|
// 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
|
||||||
break;
|
// file-level lock. A false error is more problematic than not locking properly
|
||||||
}
|
// on corner-case systems.
|
||||||
else
|
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());
|
res = QLockFile::NoError == (lockError = lock->error());
|
||||||
if (!res)
|
if (!res)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user