maxgoedjen / secretive

Store SSH keys in the Secure Enclave
MIT License
7.16k stars 157 forks source link

tmp directory filled with the same icons using 1gb #478

Closed v57 closed 1 year ago

v57 commented 1 year ago

Problem

I noticed that my ~/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/tmp directory using 1gb of data. And it consists of the same GitHub desktop icon images. Looks like every time it fetches it accesses my private key and secretive creates a copy of icon to show notifications. If so, then first problem is that i never enabled notifications so it shouldn't even do this operation. Second problem is that those same icons of GitHub desktop are not even clones of each other, so they actually using disk space. I checked that using https://github.com/dyorgio/apfs-clone-checker

Solution:

Best solution would be just using hash of app icon as a file name, so it won't make duplicates. You can also use hash of app name and icon's last modified date for better performance

Additional optimizations:

There is no need to generate 1024x1024 icons for notifications, 256x256 would be pretty much enough for that. Just doing that it will increase GitHub desktop icon from 917KB to 47KB Also if you convert it to HEIC, you will decrease size even further, from 47KB to 5KB

Screenshot 2023-08-13 at 11 55 31

maxgoedjen commented 1 year ago

That's a great find and very silly of me – thank you for noticing and filing! Wouldn't be the first time I incorrectly thought "hey, it's the tmp directory, it'll get flushed without me having to worry about it."

I think you're exactly right that something derived from app name (I'm thinking just using the bundle ID – a hash is probably unnecessary) is the right way to go, I'll PR that shortly.

Can you do me a favor and try rebooting and seeing if that clears that folder out? Mine's pretty substantially smaller (~50mb), and I have some recollection that it might be purged on reboot. I'm just debating whether or not I should proactively clear that out on launch or not.

maxgoedjen commented 1 year ago

Sadly https://developer.apple.com/documentation/usernotifications/unnotificationattachment doesn't support HEIF so I'll have to put that one off until it does – that's a great suggestion though!

v57 commented 1 year ago

Thank you for fixing that, great job! I checked if reboot will clean this up, but for some reason - no 😅 My app also holds 2gb of images and videos in tmp that I upload so I will need to research this stuff and how it works

maxgoedjen commented 1 year ago

IIRC it's more or less undefined with a hand wavey "it'll be cleaned up when space is needed and/or on reboot" justification, but yeah it trips me up occasionally for sure.