diff options
author | Thomas White <taw@physics.org> | 2013-02-22 11:40:56 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2013-02-22 11:41:22 +0100 |
commit | 9dd569008c6190b697d64c77a96e50a59e65fbf0 (patch) | |
tree | 4688b46c2f6e8c1ca088404f844876543d968256 | |
parent | e995d87d18a52ff2b18209459b33d2988dd7aab3 (diff) |
Create temporary folders only when necessary
They might already exist if a previous worker process died and was restarted.
-rw-r--r-- | src/im-sandbox.c | 19 |
1 files 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); |