matrix-org / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://matrix-org.github.io/synapse
Apache License 2.0
11.82k stars 2.13k forks source link

Remote media purge leaves a lot of directories #16229

Closed namazso closed 1 year ago

namazso commented 1 year ago

Description

I recently noticed my remote media folder grew to 5 GB again, so I ran a media purge for all files (timestamp in future). However, after finishing the remote media folder still weighed 500 MB. It turns out that was the combined size of the empty folders left behind.

Steps to reproduce

Homeserver

namazso.eu

Synapse Version

1.91.0

Installation Method

Docker (matrixdotorg/synapse)

Database

PostgreSQL 15

Workers

Single process

Platform

Linux 6.5.0

Configuration

No response

Relevant log output

-

Anything else that would be useful to know?

No response

DMRobertson commented 1 year ago

Relevant source: https://github.com/matrix-org/synapse/blob/3de82bb2af28f56696a79bf41ccffc81385b6e2c/synapse/media/media_repository.py#L934-L970

I suppose when deleting a file on disk we could try to os.rmdir() its parent directories, catching and ignoring OSError due to the directory not being empty?

Would probably also want to do something similar in delete_old_local_media.

As a one-time cleanup job I guess one could find -empty -type d -delete?

clokep commented 1 year ago

Duplicate of #7690.