mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - file locking
- While waiting for a lock, display a message to that effect, otherwise it looks like task is hung (thanks to John Florian).
This commit is contained in:
parent
73378dd67e
commit
5a1191300c
1 changed files with 6 additions and 2 deletions
|
@ -655,8 +655,12 @@ FILE* TDB::openAndLock (const std::string& file)
|
|||
// Lock if desired. Try three times before failing.
|
||||
int retry = 0;
|
||||
if (mLock)
|
||||
while (flock (fileno (in), LOCK_EX) && ++retry <= 3)
|
||||
delay (0.1);
|
||||
while (flock (fileno (in), LOCK_NB | LOCK_EX) && ++retry <= 3)
|
||||
{
|
||||
std::cout << "Waiting for file lock..." << std::endl;
|
||||
while (flock (fileno (in), LOCK_EX) && ++retry <= 3)
|
||||
delay (0.2);
|
||||
}
|
||||
|
||||
if (retry > 3)
|
||||
throw std::string ("Could not lock '") + file + "'.";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue