rtw icon indicating copy to clipboard operation
rtw copied to clipboard

Add file locking

Open PicoJr opened this issue 5 years ago • 4 comments

Currently there is no file locking.

Running several rtw commands may lead to undefined behavior.

PicoJr avatar Dec 28 '19 17:12 PicoJr

If I have spare time this week, I can try to add file locking with https://docs.rs/fs2/0.4.3/fs2/trait.FileExt.html.

I need a tool for tracking the work on my bachelor thesis.

maikwoehl avatar Aug 24 '20 20:08 maikwoehl

If I have spare time this week, I can try to add file locking with https://docs.rs/fs2/0.4.3/fs2/trait.FileExt.html.

I need a tool for tracking the work on my bachelor thesis.

As per the flock man page,

Furthermore, the lock is released either by an explicit LOCK_UN operation on any of these duplicate descriptors, or when all such descriptors have been closed.

I believe the file locking with this trait won't work in this case because the program writes the status into ~/.rtwh.json and ~/.rtw.json and exits, thereby closing all the file descriptors and releasing the lock.

nohupped avatar Sep 29 '20 14:09 nohupped

Do it really need some file locking mechanism with the filesystem already enforcing exclusive write access to the file while executing multiple instances?

Or is this issue about a wait until unlocked and then get the lock? Or is it about synchronizing the reads and writes like atomic transactions?

maikwoehl avatar Sep 29 '20 21:09 maikwoehl

Apologies, I was too soon to say that. As I ran multiple tasks manually, I realised that when a job is already in progress and another job is created, it gets appended to the "activities":[] list, so creating a new task while an existing task exists is not a problem. The only case of a race condition I can think of is when two rtw process starts at the same time and writes to the same file at the same file, which leads to undefined behaviour, which could be addressed by the https://docs.rs/fs2/0.4.3/fs2/trait.FileExt.html. trait. Thank you.

nohupped avatar Sep 30 '20 11:09 nohupped