Merge lp:~ted/ubuntu-app-launch/cache-sync-in-file into lp:ubuntu-app-launch/15.04

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 203
Merged at revision: 194
Proposed branch: lp:~ted/ubuntu-app-launch/cache-sync-in-file
Merge into: lp:ubuntu-app-launch/15.04
Diff against target: 233 lines (+157/-1)
5 files modified
desktop-hook.c (+58/-1)
libubuntu-app-launch/ubuntu-app-launch.c (+1/-0)
tests/CMakeLists.txt (+5/-0)
tests/click-desktop-hook-db/test.conf.in (+2/-0)
tests/desktop-hook-test.sh.in (+91/-0)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/cache-sync-in-file
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+255307@code.launchpad.net

Commit message

Have desktop hook verify source file still exists

Description of the change

The change was relatively small with adding the path that it was created in to the desktop file, then checking it. But upon doing that I realized that there were no desktop-hook tests, so those are added as well (including testing the change).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :
review: Approve
204. By Ted Gould

Fix typo

205. By Ted Gould

Move unref so that there's only one, error or not.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktop-hook.c'
2--- desktop-hook.c 2014-09-19 15:48:29 +0000
3+++ desktop-hook.c 2015-04-08 20:44:39 +0000
4@@ -67,6 +67,7 @@
5 #define EXEC_KEY "Exec"
6 #define ICON_KEY "Icon"
7 #define SYMBOLIC_ICON_KEY "X-Ubuntu-SymbolicIcon"
8+#define SOURCE_FILE_KEY "X-Ubuntu-UAL-Source-Desktop"
9 /* Other */
10 #define OLD_KEY_PREFIX "X-Ubuntu-Old-"
11
12@@ -136,6 +137,42 @@
13 return;
14 }
15
16+/* Look at the desktop file and ensure that it was built by us, and if it
17+ was that its source still exists */
18+gboolean
19+desktop_source_exists (const gchar * dir, const gchar * name)
20+{
21+ gchar * desktopfile = g_build_filename(dir, name, NULL);
22+
23+ GKeyFile * keyfile = g_key_file_new();
24+ g_key_file_load_from_file(keyfile,
25+ desktopfile,
26+ G_KEY_FILE_NONE,
27+ NULL); /* No error */
28+
29+ if (!g_key_file_has_key(keyfile, DESKTOP_GROUP, SOURCE_FILE_KEY, NULL)) {
30+ g_free(desktopfile);
31+ g_key_file_free(keyfile);
32+ return FALSE;
33+ }
34+
35+ /* At this point we know the key exists, so if we can't find the source
36+ file we want to delete the file as well. We need to replace it. */
37+ gchar * originalfile = g_key_file_get_string(keyfile, DESKTOP_GROUP, SOURCE_FILE_KEY, NULL);
38+ g_key_file_free(keyfile);
39+ gboolean found = TRUE;
40+
41+ if (!g_file_test(originalfile, G_FILE_TEST_EXISTS)) {
42+ g_remove(desktopfile);
43+ found = FALSE;
44+ }
45+
46+ g_free(originalfile);
47+ g_free(desktopfile);
48+
49+ return found;
50+}
51+
52 /* Look at an desktop file entry */
53 void
54 add_desktop_file (const gchar * dir, const gchar * name, GArray * app_array)
55@@ -144,6 +181,10 @@
56 return;
57 }
58
59+ if (!desktop_source_exists(dir, name)) {
60+ return;
61+ }
62+
63 gchar * appid = g_strdup(name);
64 g_strstr_len(appid, -1, ".desktop")[0] = '\0';
65
66@@ -392,6 +433,9 @@
67 /* Adding an Application ID */
68 g_key_file_set_string(keyfile, DESKTOP_GROUP, APP_ID_KEY, app_id);
69
70+ /* Adding the source file path */
71+ g_key_file_set_string(keyfile, DESKTOP_GROUP, SOURCE_FILE_KEY, from);
72+
73 /* Output */
74 gsize datalen = 0;
75 gchar * data = g_key_file_to_data(keyfile, &datalen, &error);
76@@ -426,14 +470,27 @@
77 return;
78 }
79
80+ /* Read in the database */
81+ ClickDB * db = click_db_new();
82+ click_db_read(db, g_getenv("TEST_CLICK_DB"), &error);
83+ if (error != NULL) {
84+ g_warning("Unable to read Click database: %s", error->message);
85+ g_error_free(error);
86+ g_free(package);
87+ g_object_unref(db);
88+ return;
89+ }
90+
91 /* Check click to find out where the files are */
92- ClickUser * user = click_user_new_for_user(NULL, NULL, &error);
93+ ClickUser * user = click_user_new_for_user(db, g_getenv("TEST_CLICK_USER"), &error);
94+ g_object_unref(db);
95 if (error != NULL) {
96 g_warning("Unable to read Click database: %s", error->message);
97 g_error_free(error);
98 g_free(package);
99 return;
100 }
101+
102 gchar * pkgdir = click_user_get_path(user, package, &error);
103 if (error != NULL) {
104 g_warning("Unable to get the Click package directory for %s: %s", package, error->message);
105
106=== modified file 'libubuntu-app-launch/ubuntu-app-launch.c'
107--- libubuntu-app-launch/ubuntu-app-launch.c 2015-03-02 19:59:55 +0000
108+++ libubuntu-app-launch/ubuntu-app-launch.c 2015-04-08 20:44:39 +0000
109@@ -1596,6 +1596,7 @@
110 if (error != NULL) {
111 g_warning("Unable to read Click database: %s", error->message);
112 g_error_free(error);
113+ g_object_unref(db);
114 return NULL;
115 }
116 /* If TEST_CLICK_USER is unset, this uses the current user name. */
117
118=== modified file 'tests/CMakeLists.txt'
119--- tests/CMakeLists.txt 2014-11-11 22:05:30 +0000
120+++ tests/CMakeLists.txt 2015-04-08 20:44:39 +0000
121@@ -82,3 +82,8 @@
122 target_link_libraries (cgroup-reap-test gtest ${GTEST_LIBS} ${DBUSTEST_LIBRARIES} ${GIO2_LIBRARIES})
123 add_test (cgroup-reap-test cgroup-reap-test)
124
125+# Desktop Hook Test
126+
127+configure_file ("click-desktop-hook-db/test.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/click-desktop-hook-db/test.conf" @ONLY)
128+configure_file ("desktop-hook-test.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/desktop-hook-test.sh" @ONLY)
129+add_test (desktop-hook-test desktop-hook-test.sh)
130
131=== added directory 'tests/click-desktop-hook-db'
132=== added file 'tests/click-desktop-hook-db/test.conf.in'
133--- tests/click-desktop-hook-db/test.conf.in 1970-01-01 00:00:00 +0000
134+++ tests/click-desktop-hook-db/test.conf.in 2015-04-08 20:44:39 +0000
135@@ -0,0 +1,2 @@
136+[Click Database]
137+root = @CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook
138
139=== added file 'tests/desktop-hook-test.sh.in'
140--- tests/desktop-hook-test.sh.in 1970-01-01 00:00:00 +0000
141+++ tests/desktop-hook-test.sh.in 2015-04-08 20:44:39 +0000
142@@ -0,0 +1,91 @@
143+#!/bin/bash -e
144+
145+TEST_DIR=@CMAKE_CURRENT_BINARY_DIR@
146+SRC_DIR=@CMAKE_CURRENT_SOURCE_DIR@
147+
148+CACHE_DIR=${TEST_DIR}/desktop-hook-test-click-dir
149+CLICK_DIR=${CACHE_DIR}/ubuntu-app-launch/desktop/
150+
151+DATA_DIR=${TEST_DIR}/desktop-hook-test-apps-dir
152+APPS_DIR=${DATA_DIR}/applications/
153+
154+# Remove the old directories
155+rm -rf ${CACHE_DIR}
156+rm -rf ${DATA_DIR}
157+rm -f @CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook
158+
159+# Copy our source applications
160+mkdir -p ${CLICK_DIR}
161+cp ${SRC_DIR}/link-farm/* ${CLICK_DIR}
162+
163+# Build our root dir
164+ln -s @CMAKE_CURRENT_SOURCE_DIR@/click-root-dir @CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook
165+
166+# Setup the environment
167+export XDG_CACHE_HOME=${CACHE_DIR}
168+export XDG_DATA_HOME=${DATA_DIR}
169+export TEST_CLICK_DB=@CMAKE_CURRENT_BINARY_DIR@/click-desktop-hook-db
170+export TEST_CLICK_USER=test-user
171+
172+# Run the tool
173+@CMAKE_BINARY_DIR@/desktop-hook
174+
175+# Check that the files exist
176+
177+if [ ! -e ${APPS_DIR}/com.test.good_application_1.2.3.desktop ] ; then
178+ echo "Desktop file not created for: com.test.good_application_1.2.3"
179+ exit 1
180+fi
181+
182+if [ ! -e ${APPS_DIR}/com.test.multiple_first_1.2.3.desktop ] ; then
183+ echo "Desktop file not created for: com.test.multiple_first_1.2.3"
184+ exit 1
185+fi
186+
187+# Verify we're adding containment to them
188+
189+grep "^Exec=aa-exec-click -p com.test.good_application_1.2.3 --" ${APPS_DIR}/com.test.good_application_1.2.3.desktop > /dev/null
190+grep "^Exec=aa-exec-click -p com.test.multiple_first_1.2.3 --" ${APPS_DIR}/com.test.multiple_first_1.2.3.desktop > /dev/null
191+
192+# Make sure they have the AppID (people started using it) :-/
193+
194+grep "^X-Ubuntu-Application-ID=com.test.good_application_1.2.3" ${APPS_DIR}/com.test.good_application_1.2.3.desktop > /dev/null
195+grep "^X-Ubuntu-Application-ID=com.test.multiple_first_1.2.3" ${APPS_DIR}/com.test.multiple_first_1.2.3.desktop > /dev/null
196+
197+# Remove a file and ensure it gets recreated
198+
199+rm -f ${APPS_DIR}/com.test.good_application_1.2.3.desktop
200+@CMAKE_BINARY_DIR@/desktop-hook
201+
202+if [ ! -e ${APPS_DIR}/com.test.good_application_1.2.3.desktop ] ; then
203+ echo "Desktop file not recreated for: com.test.good_application_1.2.3"
204+ exit 1
205+fi
206+
207+# Remove a source file and make sure it goes
208+
209+rm -f ${CLICK_DIR}/com.test.multiple_first_1.2.3.desktop
210+@CMAKE_BINARY_DIR@/desktop-hook
211+if [ -e ${APPS_DIR}/com.test.multiple_first_1.2.3.desktop ] ; then
212+ echo "Not cleaning up deleted files"
213+ exit 1
214+fi
215+
216+# Verify the good file is in the desktop hook root
217+grep "^X-Ubuntu-UAL-Source-Desktop=@CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook" ${APPS_DIR}/com.test.good_application_1.2.3.desktop > /dev/null
218+
219+# Remove our root
220+rm -f @CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook
221+
222+# Point to the new db and run
223+export TEST_CLICK_DB=@CMAKE_CURRENT_BINARY_DIR@/click-db-dir
224+@CMAKE_BINARY_DIR@/desktop-hook
225+
226+# Verify that we have the file and it's in the new root
227+if [ ! -e ${APPS_DIR}/com.test.good_application_1.2.3.desktop ] ; then
228+ echo "Desktop file not created for: com.test.good_application_1.2.3"
229+ exit 1
230+fi
231+
232+grep "^X-Ubuntu-UAL-Source-Desktop=@CMAKE_CURRENT_SOURCE_DIR@/click-root-dir" ${APPS_DIR}/com.test.good_application_1.2.3.desktop > /dev/null
233+

Subscribers

People subscribed via source and target branches