| 57 | } |
| 58 | |
| 59 | def save(self) -> None: |
| 60 | if not self.last_found_secrets: |
| 61 | # if there are no found secrets, don't modify the cache file |
| 62 | return |
| 63 | try: |
| 64 | fd = os.open( |
| 65 | str(self.cache_path), os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600 |
| 66 | ) |
| 67 | f = os.fdopen(fd, "w") |
| 68 | except OSError: |
| 69 | # Hotfix: for the time being we skip cache handling if permission denied |
| 70 | return |
| 71 | with f: |
| 72 | try: |
| 73 | json.dump(self.to_dict(), f) |
| 74 | except Exception as e: |
| 75 | raise UnexpectedError( |
| 76 | f"Failed to save cache in {self.cache_path}:\n{str(e)}" |
| 77 | ) |
| 78 | |
| 79 | def purge(self) -> None: |
| 80 | self.last_found_secrets = [] |