fix(gui): change app.lock location#310
Conversation
There was a problem hiding this comment.
@tristanmsct
Thanks for this! Always appreciate someone cleaning up my code lol.
Just make sure you run fmt and clippy and whatnot and amend your changes to your commit. Appreciate the patch!
also, let's add a test. at minimum one that calls acquire_app_lock() and asserts it succeeds, and a second call that asserts it fails with the "already running" error while the first lock is held. the existing tests in the project should give you a feel for the style.
for the commit message, please just write fix(gui): ...
Tries to write app.lock to $XDG_RUNTIME_DIR/nmrs/app.lock Falls back to $XDG_DATA_DIR/nmrs/app.lock
aedd11e to
3eccfef
Compare
|
Hello again I've tried to add two unit tests, one that call the The problem is, based on my very limited understanding of rust unittest, they are run in parallel, so I hit a race condition where the second test can cause the first test to fail. One solution would be to run all tests sequentially which slows down the tests by a lot. |
Adds two tests - A test to validate that the lock file is properly created - A test to see if trying to acquire the lock twice fails
|
I added the two tests mentioned above, in a I solved the race condition using this method : rust-lang/rust#43155 Hope this helps |
Hi
I did not find an issue for this small problem so I created a standalone PR
I'm trying to follow the contributing guidelines
This PR is really simple but this file has been bugging me, I'm sorry if I missed anything in terms of formating or type of commit, etc. Let me know if I need to correct anything
Motivation
The app creates a $XDG_DATA_DIR/my_app.lock when running to know if an instance is already running.
I think the name and place of the file can be improved.
The name of the file does not hint at which program creates it.
The file itself would be better placed in the XDG_RUNTIME_DIR within a
nmrssubfolder. Or at least if it stays in $XDG_DATA_DIR, then it can be in annmrssubfolder.Description
This PR simply tries to create the lock file in $XDG_RUNTIME_DIR instead of $XDG_DATA_DIR, and if it fails then it falls back to the old directory.
Also the lock file is now
nmrs/app.lockinstead of justmy_app.lockwhich is clearer for the user.The changes are only in this file
nmrs-gui/src/file_lock.rs.Testing
okexcept 15 tests that wereignored.okI build the app and tested it, the lock file is created at
/run/usr/1000/nmrs/app.lock.I could not get the creation at this specific place to fail, to confirm that it would indeed be created at
~/.local/share/nmrs/app.lockbut I see no reason why it would not work.AI Disclosure
I am not a rust developer and used a LLM to check my syntaxe and be sure to use the right functions for the job.