Exemplo n.º 1
0
void
EnsureDirectory(const Path& pth)
{
    string upath;

    for(const auto& name : pth)
    {
        upath += MakeMBCS(name.c_str()) + YCL_PATH_DELIMITER;
        if(!VerifyDirectory(upath) && !umkdir(upath.c_str()) && errno != EEXIST)
        {
            YTraceDe(Err, "Failed making directory path '%s'", upath.c_str());
            ystdex::throw_error(errno);
        }
    }
}
Exemplo n.º 2
0
void BLI_dir_create_recursive(const char *dirname)
{
	char *lslash;
	char tmp[MAXPATHLEN];

	/* First remove possible slash at the end of the dirname.
	 * This routine otherwise tries to create
	 * blah1/blah2/ (with slash) after creating
	 * blah1/blah2 (without slash) */

	BLI_strncpy(tmp, dirname, sizeof(tmp));
	lslash = (char *)BLI_last_slash(tmp);

	if (lslash && (*(lslash + 1) == '\0')) {
		*lslash = '\0';
	}

	/* check special case "c:\foo", don't try create "c:", harmless but prints an error below */
	if (isalpha(tmp[0]) && (tmp[1] == ':') && tmp[2] == '\0') return;

	if (BLI_exists(tmp)) return;

	lslash = (char *)BLI_last_slash(tmp);

	if (lslash) {
		/* Split about the last slash and recurse */
		*lslash = 0;
		BLI_dir_create_recursive(tmp);
	}

	if (dirname[0]) {  /* patch, this recursive loop tries to create a nameless directory */
		if (umkdir(dirname) == -1) {
			printf("Unable to create directory %s\n", dirname);
		}
	}
}