From 9dd569008c6190b697d64c77a96e50a59e65fbf0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 22 Feb 2013 11:40:56 +0100 Subject: Create temporary folders only when necessary They might already exist if a previous worker process died and was restarted. --- src/im-sandbox.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/im-sandbox.c b/src/im-sandbox.c index b8f45247..504c52c4 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -647,6 +647,7 @@ static int create_temporary_folder(signed int n) { int r; char tmp[64]; + struct stat s; if ( n < 0 ) { snprintf(tmp, 63, "indexamajig.%i", getpid()); @@ -654,11 +655,19 @@ static int create_temporary_folder(signed int n) snprintf(tmp, 63, "worker.%i", n); } - r = mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - if ( r ) { - ERROR("Failed to create temporary folder: %s\n", - strerror(errno)); - return 1; + if ( stat(tmp, &s) == -1 ) { + if ( errno != ENOENT ) { + ERROR("Failed to stat temporary folder.\n"); + return 1; + } + + r = mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if ( r ) { + ERROR("Failed to create temporary folder: %s\n", + strerror(errno)); + return 1; + } + } r = chdir(tmp); -- cgit v1.2.3