Browse code

cfgt: don't try to create dir if it already exists

Victor Seva authored on 28/11/2019 13:28:14
Showing 1 changed files
... ...
@@ -320,13 +320,16 @@ void cfgt_save_node(cfgt_node_p node)
320 320
 	FILE *fp;
321 321
 	str dest = STR_NULL;
322 322
 	int dir = 0;
323
+	struct stat sb;
323 324
 	if(_cfgt_get_filename(node->msgid, node->uuid, &dest, &dir) < 0) {
324 325
 		LM_ERR("can't build filename\n");
325 326
 		return;
326 327
 	}
327 328
 	dest.s[dir] = '\0';
328 329
 	LM_DBG("dir [%s]\n", dest.s);
329
-	if(mkdir(dest.s, S_IRWXO | S_IXGRP | S_IRWXU) < 0) {
330
+	if (stat(dest.s, &sb) == 0 && S_ISDIR(sb.st_mode)) {
331
+		LM_DBG("dir [%s] already existing\n", dest.s);
332
+	} else if(mkdir(dest.s, S_IRWXO | S_IXGRP | S_IRWXU) < 0) {
330 333
 		LM_ERR("failed to make directory: %s\n", strerror(errno));
331 334
 		return;
332 335
 	}