Sophie

Sophie

distrib > Mageia > 6 > armv5tl > by-pkgid > 5afce8467336335da566edb09cd201f8 > files > 3

libuser-0.62-8.2.mga6.src.rpm

Index: libuser-0.62/lib/fs.c
===================================================================
--- libuser-0.62/lib/fs.c
+++ libuser-0.62/lib/fs.c	2018-01-06 16:15:37.343188906 -0500
@@ -30,6 +30,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <time.h>
 #include <unistd.h>
 #include <utime.h>
 #include "error.h"
@@ -608,6 +609,24 @@
 	access_options.uid = owner;
 	access_options.gid = group;
 	access_options.umask = current_umask();
+
+	DIR* dir = opendir(directory);
+	// Directory already exists
+	if (dir) {
+		/* If the directory already exists we need to deal with it
+		   before adding the new one. */
+		char buf[1000];
+		char datetime[32];
+		time_t t;
+		struct tm ts;
+		time(&t);
+		ts = *localtime(&t);
+		strftime(datetime, sizeof(datetime), "%F-%T", &ts);
+		sprintf(buf, "%s.renamed_duplicate_%s", directory, datetime);
+		rename(directory, buf);
+		chown(buf, 0, 0);
+	}
+
 	if (!lu_homedir_copy(skeleton, directory, &access_options, error))
 		return FALSE;