Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Global flock file accessible by every user / Introducing FlockContext manager #1697

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

buhtz
Copy link
Member

@buhtz buhtz commented Apr 21, 2024

  • Introduce a context manager to handle (exclusive) file locks.
  • Move global flock file from /tmp to /run/lock to make it accessible for the root user. The background is that, because of a quit fresh Linux feature, the "root" user is not allowed to write into any file in /tmp no matter if file permissions would allow it.
  • There are much more other flock mechanics in BIT but I didn't touch them yet. Should be done in a separate PR.
  • The method Snapshots.backup() is the only one using the global flock. The method smells like hell. There are ~170 lines between the lock and its release. And I decided not to touch this in this PR. So I just indented that lines to use them inside the new context manager.

It is an idea.

Might...
Close #1676
Close #1122

EDIT: One of the two reporters tested and confirmed the PR.

@@ -0,0 +1,64 @@
# SPDX-FileCopyrightText: © 2024 Christian BUHTZ <c.buhtz@posteo.jp>
Copy link
Member Author

Choose a reason for hiding this comment

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

Not the only possible method but one of the recommended methods how to add copyright and license info to each file in a repo.

Further reading: REUSE Software and SPDX (ISO/IEC 5962:2021) specifications

self)


class GlobalFlock(FlockContext):
Copy link
Member Author

Choose a reason for hiding this comment

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

Other naming suggestions? GlobalFileLock, ...?


return True
return True
Copy link
Member Author

Choose a reason for hiding this comment

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

This might have caused bugs in the past. The flock was never released when this "return" took affect. Now with the context manager the flock is always released.


raise
raise
Copy link
Member Author

@buhtz buhtz Apr 21, 2024

Choose a reason for hiding this comment

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

Here the call to releaseFlock() was also missing.

@buhtz buhtz added the PR: Waiting for review PR won't be merged until review and approval from a member of the maintenance team. label Apr 23, 2024
@aryoda
Copy link
Contributor

aryoda commented Apr 26, 2024

SDPX looks quite promising to me to support machine-readable licenses too

@buhtz buhtz mentioned this pull request May 5, 2024
@buhtz
Copy link
Member Author

buhtz commented May 12, 2024

Hope it is OK to now treat is as reviewed?

I will also close the two related issues with merging this.

@buhtz buhtz added PR: Merge after creative-break Merge after creative-break (min. 1 week) and removed PR: Waiting for review PR won't be merged until review and approval from a member of the maintenance team. labels May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Merge after creative-break Merge after creative-break (min. 1 week)
Projects
None yet
2 participants