---
- name: "Ensure {{ app_name }}'s dependencies are installed"
  community.general.pacman:
    name: "{{ timeshift_dependencies }}"
    state: "{{ app_state | default('present') }}"
    update_cache: "{{ omit if skip_package_cache_update is defined else 'true' }}"

- name: "Ensure {{ app_name }}'s source directory is present"
  file:
    mode: 0755
    path: "{{ timeshift_src_dir }}"
    owner: "{{ ansible_user | default(lookup('env', 'USER')) }}"
    state: directory

- name: "Ensure {{ app_name }}'s source is cloned and up-to-date"
  become: false
  git:
    dest: "{{ timeshift_src_dir }}"
    repo: "{{ timeshift_aur_git_repository }}"
    version: master
  register: timeshift_git

- name: "Remove /usr/bin/timeshift if the source files have changed" # noqa 503
  file:
    path: /usr/bin/timeshift
    state: absent
  when: timeshift_git.changed

- name: "Ensure {{ app_name }} is installed"
  become: false
  command: makepkg -sic --noconfirm
  args:
    chdir: "{{ timeshift_src_dir }}"
    creates: /usr/bin/timeshift

- name: Run generic configuration tasks
  include_tasks: config-Linux.yml
  when: "'btrfs' in root_fs_type.stdout"
