# SPDX-FileCopyrightText: 2017 - 2025 Slavi Pantaleev # SPDX-FileCopyrightText: 2018 - 2022 MDAD project contributors # SPDX-FileCopyrightText: 2019 Stuart Mumford # SPDX-FileCopyrightText: 2020 Béla Becker # SPDX-FileCopyrightText: 2020 Chris van Dijk # SPDX-FileCopyrightText: 2020 Horvath Gergely # SPDX-FileCopyrightText: 2022 Sebastian Gumprich # SPDX-FileCopyrightText: 2024 - 2025 Suguru Hirahara # SPDX-FileCopyrightText: 2024 László Várady # SPDX-FileCopyrightText: 2026 Chiu Ki Sit # # SPDX-License-Identifier: AGPL-3.0-or-later --- # On Synology, name-based chown works for directly-touched paths but leaves # existing sub-paths with stale numeric ownership when uid/gid changes between # runs. We recurse only when the base path's gid doesn't match, so normal runs # skip the expensive tree walk entirely. Its uid is not compared, as the base path is owned by root, not the matrix user. # The recursive chown runs before the base paths are ensured below, so they get their own ownership back. # chown -R is used instead of the file module's recurse option to avoid Ansible iterating every entry in Python. - name: Check current ownership of Matrix base path (Synology) ansible.builtin.stat: path: "{{ matrix_base_data_path }}" register: matrix_base_data_path_stat when: matrix_base_host_is_synology - name: Ensure Matrix base path ownership is correct using numeric UID/GID (Synology) ansible.builtin.command: chown -R {{ matrix_user_uid }}:{{ matrix_user_gid }} {{ matrix_base_data_path }} changed_when: true when: >- matrix_base_host_is_synology and matrix_base_data_path_stat.stat.exists and matrix_base_data_path_stat.stat.gid | int != matrix_user_gid | int - name: Ensure Matrix base paths exists ansible.builtin.file: path: "{{ item }}" state: directory mode: "{{ matrix_base_data_path_mode }}" owner: "{{ matrix_base_data_path_owner }}" group: "{{ matrix_base_data_path_group }}" with_items: - "{{ matrix_base_data_path }}" - "{{ matrix_bin_path }}" - name: Ensure remove-all script created ansible.builtin.template: src: "{{ role_path }}/templates/bin/remove-all.j2" dest: "{{ matrix_bin_path }}/remove-all" mode: '0750'