Ubuntu Pastebin

Paste from laney at Wed, 24 Feb 2016 13:56:01 +0000

Download as text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
Description: Use execute a VACUUM operation on activity DB on startups every 10 days
Author: Marco Trevisan <marco.trevisan@canonical.com>
Bug-Ubuntu: https://launchpad.net/bugs/919801
Forwarded: http://irclogs.ubuntu.com/2016/02/24/#ubuntu-desktop.html#t10:44

Index: b/src/Makefile.am
===================================================================
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,7 @@
 NULL = 
 
 bin_PROGRAMS = zeitgeist-daemon
+pkglibexec_PROGRAMS = zeitgeist-vacuum
 noinst_LTLIBRARIES = libzeitgeist-engine.la
 
 AM_CPPFLAGS = \
@@ -33,6 +34,7 @@
 	libzeitgeist_engine_la_vala.stamp \
 	extensions_vala.stamp \
 	zeitgeist_daemon_vala.stamp \
+	zeitgeist_vacuum_vala.stamp \
 	$(NULL)
 
 # Make sure every extension has only one vala file!
@@ -72,6 +74,17 @@
 zeitgeist_daemon_LDADD = $(builddir)/libzeitgeist-engine.la $(top_builddir)/libzeitgeist/libzeitgeist-2.0.la $(ZEITGEIST_LIBS)
 zeitgeist_daemon_LDFLAGS = -export-dynamic -no-undefined
 
+zeitgeist_vacuum_VALASOURCES = \
+	zeitgeist-vacuum.vala \
+	$(NULL)
+
+nodist_zeitgeist_vacuum_SOURCES = \
+	$(zeitgeist_vacuum_VALASOURCES:.vala=.c) \
+	$(NULL)
+
+zeitgeist_vacuum_LDADD = $(top_builddir)/libzeitgeist/libzeitgeist-2.0.la $(ZEITGEIST_LIBS)
+zeitgeist_vacuum_LDFLAGS = -export-dynamic -no-undefined
+
 libzeitgeist_engine_la_LIBADD = $(ZEITGEIST_LIBS)
 libzeitgeist_engine_la_LDFLAGS = -avoid-version -non_shared -static
 
@@ -101,15 +114,23 @@
 		$(filter %.vala %.c,$^)
 	$(AM_V_at)touch $@
 
+zeitgeist_vacuum_vala.stamp: $(zeitgeist_vacuum_VALASOURCES) Makefile
+	$(AM_V_VALA)$(VALAC) \
+		$(AM_VALAFLAGS) \
+		$(filter %.vala %.c,$^)
+	$(AM_V_at)touch $@
+
 EXTRA_DIST = \
 	$(libzeitgeist_engine_la_VALASOURCES) \
 	$(zeitgeist_daemon_VALASOURCES) \
+	$(zeitgeist_vacuum_VALASOURCES) \
 	$(extensions_VALASOURCES) \
 	$(NULL)
 
 CLEANFILES = \
 	$(nodist_libzeitgeist_engine_la_SOURCES) \
 	$(nodist_zeitgeist_daemon_SOURCES) \
+	$(nodist_zeitgeist_vacuum_SOURCES) \
 	zeitgeist-engine.vapi \
 	zeitgeist-engine.h \
 	$(NULL)
Index: b/src/zeitgeist-vacuum.vala
===================================================================
--- /dev/null
+++ b/src/zeitgeist-vacuum.vala
@@ -0,0 +1,56 @@
+/* zeitgeist-vacuum.vala
+ *
+ * Copyright © 2015 Marco Trevisan <marco.trevisan@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+using Zeitgeist;
+
+int main (string[] args)
+{
+    Sqlite.Database database;
+
+    if (Utils.using_in_memory_database ())
+    {
+        warning ("Using in-memory database, no VACUUM needed");
+    }
+
+    var db_path = Utils.get_database_file_path ();
+    debug (@"Opening database file at $db_path");
+
+    int rc = Sqlite.Database.open_v2 (db_path, out database, Sqlite.OPEN_READWRITE);
+
+    if (rc != Sqlite.OK)
+    {
+        warning ("Impossible to open database `%s': %s".printf (db_path, database.errmsg ()));
+        return rc;
+    }
+
+    print ("Performing VACUUM operation... ");
+    rc = database.exec ("VACUUM");
+
+    if (rc != Sqlite.OK)
+    {
+        print ("FAIL");
+        warning (database.errmsg ());
+        return rc;
+    }
+
+    print("OK\n");
+    return 0;
+}
+
+// vim:expandtab:ts=4:sw=4
Index: b/data/Makefile.am
===================================================================
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -8,9 +8,15 @@
 service_DATA = org.gnome.zeitgeist.service
 
 org.gnome.zeitgeist.service: org.gnome.zeitgeist.service.in
-	$(AM_V_GEN)sed -e s!\@prefix\@!$(prefix)! < $< > $@
+	$(AM_V_GEN)sed -e "s!\@prefix\@!$(prefix)!; s!\@pkglibexecdir\@!$(pkglibexecdir)!" < $< > $@
 org.gnome.zeitgeist.service: Makefile
 
+pkglibexec_PROGRAMS = zeitgeist-maybe-vacuum
+
+zeitgeist-maybe-vacuum: zeitgeist-maybe-vacuum.in
+	$(AM_V_GEN)sed -e s!\@pkglibexecdir\@!$(pkglibexecdir)! < $< > $@
+zeitgeist-maybe-vacuum: Makefile
+
 bashcompletiondir = $(datadir)/bash-completion/completions
 dist_bashcompletion_DATA = completions/zeitgeist-daemon
 
@@ -27,15 +33,17 @@
 	org.gnome.zeitgeist.service \
 	PythonSerializer.pyc \
 	zeitgeist-datahub.desktop \
+	zeitgeist-vacuum.conf \
 	$(NULL)
 
 EXTRA_DIST = \
 	org.gnome.zeitgeist.service.in \
 	ontology2code \
+	zeitgeist-maybe-vacuum.in \
 	$(xdgautostart_in_files) \
 	$(NULL)
 
-all-local: org.gnome.zeitgeist.service
+all-local: org.gnome.zeitgeist.service zeitgeist-maybe-vacuum
 
 clean:
 	rm -rf *.pyc *.~[0-9]~
Index: b/data/zeitgeist-maybe-vacuum.in
===================================================================
--- /dev/null
+++ b/data/zeitgeist-maybe-vacuum.in
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+FREQUENCY=864000 # 10 days
+
+cache_dir="$HOME/.cache"
+
+if [ -n "$XDG_CACHE_HOME" ]; then
+  cache_dir="$XDG_CACHE_HOME"
+fi
+
+stamp_file="$cache_dir/zeitgeist-vacuum.stamp"
+timestamp=0
+
+if [ -f "$stamp_file" ]; then
+  timestamp="$(cat $stamp_file)"
+fi
+
+case $timestamp in
+  ''|*[!0-9]*) timestamp=0 ;;
+  *) ;;
+esac
+
+if [ $(($(date +%s) - $timestamp)) -lt $FREQUENCY ]; then
+  exit 0;
+fi
+
+if (@pkglibexecdir@/zeitgeist-vacuum); then
+  mkdir -p "$cache_dir"
+  date +%s > "$stamp_file"
+else
+  exit $?
+fi
Index: b/data/org.gnome.zeitgeist.service.in
===================================================================
--- a/data/org.gnome.zeitgeist.service.in
+++ b/data/org.gnome.zeitgeist.service.in
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=org.gnome.zeitgeist.Engine
-Exec=@prefix@/bin/zeitgeist-daemon
+Exec=/bin/sh -c "@pkglibexecdir@/zeitgeist-maybe-vacuum; @prefix@/bin/zeitgeist-daemon"
Download as text