[dovecot-cvs] dovecot/src/lib mkdir-parents.c,NONE,1.1 mkdir-parents.h,NONE,1.1 Makefile.am,1.30,1.31 compat.h,1.18,1.19

cras at procontrol.fi cras at procontrol.fi
Sun May 18 20:02:48 EEST 2003


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv19784/lib

Modified Files:
	Makefile.am compat.h 
Added Files:
	mkdir-parents.c mkdir-parents.h 
Log Message:
More robust error handling for mbox.



--- NEW FILE: mkdir-parents.c ---
/* Copyright (c) 2003 Timo Sirainen */

#include "lib.h"
#include "mkdir-parents.h"

#include <sys/stat.h>

int mkdir_parents(const char *path, mode_t mode)
{
	const char *p;

	if (mkdir(path, mode) < 0 && errno != EEXIST) {
		if (errno != ENOENT)
			return -1;

		p = strrchr(path, '/');
		if (p == NULL || p == path)
			return -1; /* shouldn't happen */

		t_push();
		if (mkdir_parents(t_strdup_until(path, p), mode) < 0) {
			t_pop();
			return -1;
		}
		t_pop();

		/* should work now */
		if (mkdir(path, mode) < 0 && errno != EEXIST)
			return -1;
	}

	return 0;
}

--- NEW FILE: mkdir-parents.h ---
#ifndef __MKDIR_PARENTS_H
#define __MKDIR_PARENTS_H

/* Create path and all the directories under it if needed.
   Returns 0 if ok, or if path already exists (not necessarily as directory). */
int mkdir_parents(const char *path, mode_t mode);

#endif

Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- Makefile.am	14 May 2003 18:23:05 -0000	1.30
+++ Makefile.am	18 May 2003 16:02:46 -0000	1.31
@@ -32,6 +32,7 @@
 	mempool-alloconly.c \
 	mempool-datastack.c \
 	mempool-system.c \
+	mkdir-parents.c \
 	mmap-anon.c \
 	mmap-util.c \
 	module-dir.c \
@@ -85,6 +86,7 @@
 	macros.h \
 	md5.h \
 	mempool.h \
+	mkdir-parents.h \
 	mmap-util.h \
 	module-dir.h \
 	network.h \

Index: compat.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/compat.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- compat.h	30 Mar 2003 12:48:36 -0000	1.18
+++ compat.h	18 May 2003 16:02:46 -0000	1.19
@@ -122,4 +122,15 @@
 #  define ENOSPACE(errno) ((errno) == ENOSPC)
 #endif
 
+/* EPERM is returned sometimes if device doesn't support such modification */
+#ifdef EROFS
+#  define ENOACCESS(errno) \
+	((errno) == EACCES || (errno) == EROFS || (errno) == EPERM)
+#else
+#  define ENOACCESS(errno) ((errno) == EACCES || (errno) == EPERM)
+#endif
+
+#define ENOTFOUND(errno) \
+	((errno) == ENOENT || (errno) == ENOTDIR || (errno) == ELOOP)
+
 #endif



More information about the dovecot-cvs mailing list