cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob efbf5743aa5398310bf08ece900006c2a218dcf8 749 bytes (raw)
$ git show HEAD:mkpath_for.c	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
/*
 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 */
#include "cmogstored.h"

/*
 * "path" is the pathname for a file (not a directory)
 * returns -1 on error, sets errno to EACCES on invalid paths
 */
int mog_mkpath_for(struct mog_svc *svc, char *path)
{
	char *tip = path + 1;
	char *c = strchr(tip, '/');
	int rc = 0;
	int i;

	/* refuse to create files at the top-level */
	if (c == NULL) {
		errno = EACCES;
		return -1;
	}

	for (i = 0; c != NULL; i++) {
		if (i > 0) {
			*c = 0;
			rc = mog_mkdir(svc, path, svc->mkcol_perms);
			*c = '/';
		}

		if (rc != 0 && errno != EEXIST)
			return rc;

		tip = c + 1;
		c = strchr(tip, '/');
	}

	return 0;
}

git clone https://yhbt.net/cmogstored.git