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 screenshot cache contains many large files, #4899 #4903

Merged
merged 1 commit into from May 26, 2024

Conversation

low-batt
Copy link
Contributor

This commit will change the screenshotCallback method in PlayerCore to remove the cached screenshot file when not displaying a preview.


Description:

This commit will change the screenshotCallback method in PlayerCore to
remove the cached screenshot file when not displaying a preview.
@low-batt low-batt linked an issue Apr 28, 2024 that may be closed by this pull request
1 task
@low-batt low-batt requested a review from uiryuu April 28, 2024 18:54
@svobs
Copy link
Contributor

svobs commented May 2, 2024

Could use a defer after initing lastScreenshotURL, instead of duplicating the code 3 times, like so:

    defer {
      if !saveToFile {
        try? FileManager.default.removeItem(at: lastScreenshotURL)
      }
    }

@low-batt
Copy link
Contributor Author

low-batt commented May 3, 2024

I did not do that because I was worried that there was a reason the current code retains the file until all operations have completed. Since currently that happens asynchronously, deleting the file when exiting the method would create a race condition if there is a reason it must be retained until after it has been sent to the OSD.

How threading is handled between PlayerCore and MPVController is being refactored for the feature release. That will eliminate the "split processing" where some work occurs on the thread MPVController uses to read events and the main thread. This will simplify some of this code.

@uiryuu
Copy link
Member

uiryuu commented May 22, 2024

What about clearing all the cached images when quitting (or starting) IINA? This can not only avoid synchronicity issue but also clear up previous (possibly large) cache after we ship the new version.

@low-batt
Copy link
Contributor Author

Synchronicity is only an issue with the suggestion to use defer.

The best practice is always to cleanup the temp file right after you finish with it. For example, I leave IINA running for weeks at a time on my non-development machine. It would be wrong to allow temp files to build up during that time. So the above code is needed regardless of whether IINA cleans up during startup/shutdown.

As noted the benefit of cleaning up during startup/shutdown is that it would clean up the files left from this defect. It would also clean up if IINA is killed with a temp file outstanding. But I'm too terrified of deleting all files in a directory to code that.

Copy link
Member

@uiryuu uiryuu left a comment

Choose a reason for hiding this comment

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

Oh, I was thinking that self.sendOSD(.screenshot) would also use the image file somehow. The changes are okay to me. Maybe we can state in our wiki that users can clear up the cache folder manually if they have used a older version of IINA.

@lhc70000 lhc70000 merged commit 18cf623 into develop May 26, 2024
1 check passed
@lhc70000 lhc70000 deleted the screenshot-cache branch May 26, 2024 05:36
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.

Screenshot cache contains many large files
4 participants