Fix stale extraction cleanup in cache-manager

Problem

After cache extraction, _restore_pgdata_permissions() changes ownership to postgres (UID 105) with mode 700. On subsequent runs on the same builder, tar extraction fails because the GitLab runner (different UID, e.g., 2000) can't write to these directories.

This causes errors like:

tar: ./datadir/haf_db_store/pgdata/...: Cannot open: Permission denied
mkdir: cannot create directory '...': Permission denied

Solution

Add _cleanup_stale_extraction() function that:

  1. Checks if destination directory exists
  2. Tests if we can write to it
  3. If not writable, removes it (with sudo fallback for postgres-owned files)

This function is called before extraction in cmd_get().

Testing

This fix was validated by manually cleaning up stale caches on CI builders, confirming that fresh extractions work correctly.

Merge request reports

Loading