forked from Mirrors/openclonk
Make CreateDirectory create directories recursively
parent
4d047ed20f
commit
18167243b2
|
@ -679,7 +679,7 @@ void C4ConfigGeneral::DeterminePaths(BOOL forceWorkingDirectory)
|
||||||
#ifdef C4ENGINE
|
#ifdef C4ENGINE
|
||||||
// Create user path if it doesn't already exist
|
// Create user path if it doesn't already exist
|
||||||
if (!DirectoryExists(UserDataPath))
|
if (!DirectoryExists(UserDataPath))
|
||||||
CreateDirectory(UserDataPath, NULL); // currently no error handling here; also: no recursive directory creation
|
CreateDirectory(UserDataPath, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -562,10 +562,23 @@ bool SetWorkingDirectory(const char *path)
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
// CreateDirectory: true on success
|
// CreateDirectory: true on success
|
||||||
bool CreateDirectory(const char * pathname, void*) {
|
bool CreateDirectory(const char * pathname, void*)
|
||||||
// mkdir: false on success
|
{
|
||||||
return !mkdir(pathname,S_IREAD | S_IWRITE | S_IEXEC);
|
int r = mkdir(pathname,S_IREAD | S_IWRITE | S_IEXEC);
|
||||||
}
|
if (r && errno == ENOENT)
|
||||||
|
{
|
||||||
|
StdCopyStrBuf parent(pathname);
|
||||||
|
char * slash = strrchr(parent.getMData(), '/');
|
||||||
|
if (slash)
|
||||||
|
{
|
||||||
|
*slash = 0;
|
||||||
|
CreateDirectory(parent.getData());
|
||||||
|
return !mkdir(pathname,S_IREAD | S_IWRITE | S_IEXEC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// mkdir: 0 on success
|
||||||
|
return !r;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool DirectoryExists(const char *szFilename)
|
bool DirectoryExists(const char *szFilename)
|
||||||
|
|
Loading…
Reference in New Issue