From d6895ea035161e825686efc762ba877388560c1f Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Wed, 24 Oct 2018 20:48:25 +1100 Subject: [PATCH 1/9] #9: Add a handler for cache clearing --- handlers/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/handlers/main.yml b/handlers/main.yml index 8992704..294fd8d 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,3 +3,10 @@ - name: restart dock shell: "/usr/bin/killall Dock" failed_when: false + +- name: clear cache + shell: "{{ item }}" + with_items: + - 'sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {};' + - 'sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {};' + - 'sudo rm -rf /Library/Caches/com.apple.iconservices.store;' \ No newline at end of file From 95b38a663316edb414b730a69cf866bfdeb5bbd4 Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Wed, 24 Oct 2018 20:51:20 +1100 Subject: [PATCH 2/9] #9: Move the restart handler to the bottom of the handlers file --- handlers/main.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 294fd8d..d5b8441 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,12 +1,13 @@ --- # handlers file for fubarhouse.macdock -- name: restart dock - shell: "/usr/bin/killall Dock" - failed_when: false - name: clear cache shell: "{{ item }}" with_items: - 'sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {};' - 'sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {};' - - 'sudo rm -rf /Library/Caches/com.apple.iconservices.store;' \ No newline at end of file + - 'sudo rm -rf /Library/Caches/com.apple.iconservices.store;' + + - name: restart dock + shell: "/usr/bin/killall Dock" + failed_when: false From 8dd49a74a615a9c6b0a7943b4ed84cd2c2bc9a7c Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Wed, 24 Oct 2018 20:51:56 +1100 Subject: [PATCH 3/9] #9: Add cache clear notifications to tasks already calling the restart dock handler --- tasks/main.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 54b806e..8ab11b8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -34,7 +34,9 @@ when: - dockitems_remove_all|bool == false - (item.item ~ " was found in persistent-apps") in item.stdout - notify: restart dock + notify: + - clear cache + - restart dock - name: Dockutil | Get information on configured setup shell: "{{ dockutil_install_path }} --find '{{ item.name }}'" @@ -50,7 +52,9 @@ loop_control: label: "{{item.item}}" when: (item.item.name ~ " was not found in") in item.stdout - notify: restart dock + notify: + - clear cache + - restart dock - name: Dockutil | Get information on current setup shell: "{{ dockutil_install_path }} --find '{{ item.name }}'" @@ -68,4 +72,6 @@ when: - (item.item.name ~ " was found in persistent-apps at slot " ~ item.item.pos ~ " in") not in item.stdout - (item.item.name ~ " was not found") not in item.stdout - notify: restart dock + notify: + - clear cache + - restart dock From 14c37b6bdce550863c974908fac1acc93f8761dc Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Wed, 24 Oct 2018 20:55:55 +1100 Subject: [PATCH 4/9] #9: Fixes syntax for restart hander --- handlers/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index d5b8441..f7ccb21 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -8,6 +8,6 @@ - 'sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {};' - 'sudo rm -rf /Library/Caches/com.apple.iconservices.store;' - - name: restart dock - shell: "/usr/bin/killall Dock" - failed_when: false +- name: restart dock + shell: "/usr/bin/killall Dock" + failed_when: false From 206d981ba604894960b66988728a761dfce99779 Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Wed, 24 Oct 2018 21:02:37 +1100 Subject: [PATCH 5/9] #9: Adjusts syntax for items in cache handler --- handlers/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index f7ccb21..e14f387 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -4,9 +4,9 @@ - name: clear cache shell: "{{ item }}" with_items: - - 'sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {};' - - 'sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {};' - - 'sudo rm -rf /Library/Caches/com.apple.iconservices.store;' + - 'sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {}' + - 'sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {}' + - 'sudo rm -rf /Library/Caches/com.apple.iconservices.store' - name: restart dock shell: "/usr/bin/killall Dock" From bcc3c42fa78a4a80262ad21885404acab78f5504 Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Wed, 24 Oct 2018 21:10:49 +1100 Subject: [PATCH 6/9] #9: Adds a command exit on find commands in the cache clear command --- handlers/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index e14f387..88b7cd1 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -4,8 +4,8 @@ - name: clear cache shell: "{{ item }}" with_items: - - 'sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {}' - - 'sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {}' + - 'sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {} \;' + - 'sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {} \;' - 'sudo rm -rf /Library/Caches/com.apple.iconservices.store' - name: restart dock From 0f130ad2fe03a3459892e0036d1520161bb185f4 Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Wed, 24 Oct 2018 21:30:34 +1100 Subject: [PATCH 7/9] #9: Convert cache handler to not use sudo directly and to prevent failures --- handlers/main.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 88b7cd1..b254eb3 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -2,11 +2,13 @@ # handlers file for fubarhouse.macdock - name: clear cache + become: yes + become_user: root shell: "{{ item }}" with_items: - - 'sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {} \;' - - 'sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {} \;' - - 'sudo rm -rf /Library/Caches/com.apple.iconservices.store' + - 'find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {} \; | true' + - 'find /private/var/folders/ -name com.apple.dock.iconcache -exec rm -rf {} \; | true' + - 'rm -rf /Library/Caches/com.apple.iconservices.store | true' - name: restart dock shell: "/usr/bin/killall Dock" From a5d0e9ea16bc5144c5d134167c04d6ab6db4598c Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Sat, 27 Oct 2018 20:59:08 +1100 Subject: [PATCH 8/9] Removes become_user from cache handler See https://github.com/fubarhouse/ansible-role-macdock/issues/9#issuecomment-433393040 --- handlers/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/handlers/main.yml b/handlers/main.yml index b254eb3..e70fb97 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,7 +3,6 @@ - name: clear cache become: yes - become_user: root shell: "{{ item }}" with_items: - 'find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {} \; | true' From 6029b8c878300322740e4da0d4dd3efbdb278758 Mon Sep 17 00:00:00 2001 From: Karl Hepworth Date: Sat, 27 Oct 2018 21:04:11 +1100 Subject: [PATCH 9/9] #9: Add comment on restarts being required if cache is faulty --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f452b5f..f405fab 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Install [Dockutil](https://github.com/kcrawford/dockutil) and remove, add and and rotate items on OSX's dock on macOS. +During the roles execution, icon cache will also be cleared however may require a restart if there are continuing problems. + ## Requirements None.