From 4e12547b9efdf22928545906e415a5fb8eb7c674 Mon Sep 17 00:00:00 2001 From: parisni Date: Sat, 28 Feb 2026 22:48:08 +0100 Subject: [PATCH] feat: prune empty dir when migrate to s3 storage OTW many empty dirs are kept --- docs/configuring-playbook-synapse-s3-storage-provider.md | 2 ++ .../templates/synapse/ext/s3-storage-provider/bin/migrate.j2 | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/docs/configuring-playbook-synapse-s3-storage-provider.md b/docs/configuring-playbook-synapse-s3-storage-provider.md index 0d7c312ce..89e647445 100644 --- a/docs/configuring-playbook-synapse-s3-storage-provider.md +++ b/docs/configuring-playbook-synapse-s3-storage-provider.md @@ -177,6 +177,8 @@ By default, we periodically ensure that all local files are uploaded to S3 and a - … invoked via the `matrix-synapse-s3-storage-provider-migrate.service` service - … triggered by the `matrix-synapse-s3-storage-provider-migrate.timer` timer, every day at 05:00 +The same `migrate` script also prunes empty directories in the local media repository (`remote_content` and `remote_thumbnail`) after upload/delete operations. + So… you don't need to perform any maintenance yourself. The schedule is defined in the format of systemd timer calendar. To edit the schedule, add the following configuration to your `vars.yml` file (adapt to your needs): diff --git a/roles/custom/matrix-synapse/templates/synapse/ext/s3-storage-provider/bin/migrate.j2 b/roles/custom/matrix-synapse/templates/synapse/ext/s3-storage-provider/bin/migrate.j2 index b606729c0..70c201002 100644 --- a/roles/custom/matrix-synapse/templates/synapse/ext/s3-storage-provider/bin/migrate.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/ext/s3-storage-provider/bin/migrate.j2 @@ -24,3 +24,8 @@ container_id=$(\ {% endfor %} {{ devture_systemd_docker_base_host_command_docker }} start --attach $container_id + +for prune_dir in "{{ matrix_synapse_storage_path }}/{{ matrix_synapse_media_store_directory_name }}/remote_content" "{{ matrix_synapse_storage_path }}/{{ matrix_synapse_media_store_directory_name }}/remote_thumbnail"; do + [ -d "$prune_dir" ] || continue + find "$prune_dir" -depth -mindepth 1 -type d -empty -print -delete +done