Description: Remove user cache files if user account no longer exists
Origin: https://launchpad.net/bugs/1259562
Forwarded: https://bugs.freedesktop.org/72596
Author: Gunnar Hjalmarsson <gunnarhj@ubuntu.com>
Last-Update: 2013-12-12

--- accountsservice-0.6.35.orig/src/daemon.c	2013-10-15 22:25:19.000000000 +0200
+++ accountsservice-0.6.35/src/daemon.c	2013-12-12 21:46:38.187947168 +0100
@@ -374,11 +374,22 @@
                 g_free (filename);
 
                 if (regular) {
+                        errno = 0;
                         pwent = getpwnam (name);
-                        if (pwent == NULL)
-                                g_debug ("user '%s' in cache dir but not present on system", name);
-                        else
+                        if (pwent != NULL)
                                 return pwent;
+                        else if (errno == 0) {
+                                g_debug ("user '%s' in cache dir but not present on system, removing", name);
+                                filename = g_build_filename (USERDIR, name, NULL);
+                                g_remove (filename);
+                                g_free (filename);
+                                filename = g_build_filename (ICONDIR, name, NULL);
+                                g_remove (filename);
+                                g_free (filename);
+                        }
+                        else
+                                g_warning ("failed to check if user '%s' in cache dir is present on system: %s",
+                                  name, g_strerror (errno));
                 }
         }
 
