# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2021 Mikhail Morfikov
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/czkawka_gui
profile czkawka-gui @{exec_path} {
  include <abstractions/base>
  include <abstractions/dconf-write>
  include <abstractions/gtk>
  include <abstractions/fonts>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/freedesktop.org>

  @{exec_path} mr,

  @{bin}/xdg-open   rCx -> open,

  # Dirs to scan for duplicates
  #owner @{HOME}/** rw,
  owner @{MOUNTS}/** rw,

  owner @{user_config_dirs}/czkawka/ rw,
  owner @{user_config_dirs}/czkawka/** rw,

  owner @{user_cache_dirs}/ rw,
  owner @{user_cache_dirs}/czkawka/ rw,
  owner @{user_cache_dirs}/czkawka/** rw,

  owner @{PROC}/@{pid}/cmdline r,
  owner @{PROC}/@{pid}/cgroup r,
  owner @{PROC}/@{pid}/mountinfo r,
  owner @{PROC}/@{pid}/mounts r,

  @{sys}/fs/cgroup/{,**} r,

  profile open {
    include <abstractions/base>
    include <abstractions/xdg-open>

    @{bin}/xdg-open mr,

    @{sh_path}             rix,
    @{bin}/{m,g,}awk       rix,
    @{bin}/readlink        rix,
    @{bin}/basename        rix,

    owner @{HOME}/ r,

    owner @{run}/user/@{uid}/ r,

    # Allowed apps to open
    #@{lib}/firefox/firefox  rPx,
    @{bin}/smplayer          rPx,
    @{bin}/geany             rPx,
    @{bin}/viewnior         rPUx,

    # file_inherit
    owner @{HOME}/.xsession-errors w,

  }

  include if exists <local/czkawka-gui>
}
