是否可以使用gio通过非GUI会话修改GNOME桌面文件元数据?

时间:2018-08-08 13:01:15

标签: ansible desktop gnome gio

在GNOME 3.22.2上运行CentOS 7,我试图编写Ansible剧本,将图标从/ usr / share / applications复制到预定义用户的桌面,然后授予受信任的权限(使用gio set "metadata::trusted" yes )。

当我尝试使用gio info -w /home/demo/Desktop/google-chrome.desktop在终端会话中查看桌面图标的可写属性时,得到以下结果:

Settable attributes:
 standard::symlink-target (bytestring)
 time::access (uint64, Keep with file when moved)
 time::access-usec (uint32, Keep with file when moved)
 time::modified (uint64, Copy with file, Keep with file when moved)
 time::modified-usec (uint32, Copy with file, Keep with file when moved)
 unix::gid (uint32, Keep with file when moved)
 unix::mode (uint32, Copy with file, Keep with file when moved)
 unix::uid (uint32, Keep with file when moved)
Writable attribute namespaces:
 xattr (string, Copy with file, Keep with file when moved)
 xattr-sys (string, Keep with file when moved)

因此,当我尝试运行上述gio set命令时,它无法运行gio: Setting attribute metadata::trusted not supported,因为无法写入元数据。但是,如果我登录到GUI会话并从终端运行相同的命令,那么我会看到元数据现在是可写的属性:

Settable attributes:
 standard::symlink-target (bytestring)
 time::access (uint64, Keep with file when moved)
 time::access-usec (uint32, Keep with file when moved)
 time::modified (uint64, Copy with file, Keep with file when moved)
 time::modified-usec (uint32, Copy with file, Keep with file when moved)
 unix::gid (uint32, Keep with file when moved)
 unix::mode (uint32, Copy with file, Keep with file when moved)
 unix::uid (uint32, Keep with file when moved)
Writable attribute namespaces:
 metadata (string, Copy with file, Keep with file when moved)
 xattr (string, Copy with file, Keep with file when moved)
 xattr-sys (string, Keep with file when moved)

这意味着gio set命令在GNOME GUI会话中有效,但在终端会话中无效。我试图找出是否有办法允许终端会话进行修改(以便我的剧本可以进行修改)。如果这样做的话,我不反对必须使用其他脚本语言来做到这一点。

有关信息,当前的Ansible剧本部分如下所示:

- name: Make Chrome Launcher Trusted
  shell: gio set /home/demo/Desktop/google-chrome.desktop "metadata::trusted" yes

1 个答案:

答案 0 :(得分:2)

您需要dbus,如果您的用户尚未登录,则该dbus不会运行。您可以使用dbus-launch启动gio使用的dbus:

- name: Make Chrome Launcher Trusted
  shell: dbus-launch gio set /home/demo/Desktop/google-chrome.desktop "metadata::trusted" yes