Skip to content

fix(gui): change app.lock location#310

Open
tristanmsct wants to merge 2 commits intocachebag:masterfrom
tristanmsct:fix-app-lock
Open

fix(gui): change app.lock location#310
tristanmsct wants to merge 2 commits intocachebag:masterfrom
tristanmsct:fix-app-lock

Conversation

@tristanmsct
Copy link

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 nmrs subfolder. Or at least if it stays in $XDG_DATA_DIR, then it can be in an nmrs subfolder.

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.lock instead of just my_app.lock which is clearer for the user.
The changes are only in this file nmrs-gui/src/file_lock.rs.

Testing

  • cargo test --all-features : all tests were ok except 15 tests that were ignored.
  • cargo test --test integration_test --all-features : 43 tests, all ok

I 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.lock but 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.

Copy link
Owner

@cachebag cachebag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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): ...

@cachebag cachebag added bug Something isn't working nmrs-gui Changes to nmrs-gui labels Mar 26, 2026
@tristanmsct tristanmsct changed the title refactor: change app.lock location fix(gui): change app.lock location Mar 26, 2026
Tries to write app.lock to $XDG_RUNTIME_DIR/nmrs/app.lock
Falls back to $XDG_DATA_DIR/nmrs/app.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working nmrs-gui Changes to nmrs-gui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants