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

Atomically rename saved image to avoid race condition with other processes #5119

Merged
merged 1 commit into from
Dec 10, 2022

Conversation

0xb8
Copy link
Contributor

@0xb8 0xb8 commented Nov 27, 2022

I use some other program to monitor output directory and display new images automatically. However, sometimes it opens newly added image too soon, before it's completely written. Because of that the image is not displayed correctly – the program might even crash or hang.

To avoid the race condition, this PR changes the way the image is saved:

  1. Write the image with .tmp extension
  2. Update EXIF metadata if necessary
  3. Atomically rename the file with final extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants