Q_MKDIR: use std::filesystem::create_directories
This commit is contained in:
parent
c217ad981a
commit
396fe81cd2
1
Makefile
1
Makefile
|
|
@ -1064,6 +1064,7 @@ $(INSTALLDIR)/modules/shaders.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) -Ilibs
|
||||||
$(INSTALLDIR)/modules/shaders.$(DLL): \
|
$(INSTALLDIR)/modules/shaders.$(DLL): \
|
||||||
plugins/shaders/plugin.o \
|
plugins/shaders/plugin.o \
|
||||||
plugins/shaders/shaders.o \
|
plugins/shaders/shaders.o \
|
||||||
|
libcommandlib.$(A) \
|
||||||
|
|
||||||
$(INSTALLDIR)/modules/vfspk3.$(DLL): LIBS_EXTRA := $(LIBS_GLIB)
|
$(INSTALLDIR)/modules/vfspk3.$(DLL): LIBS_EXTRA := $(LIBS_GLIB)
|
||||||
$(INSTALLDIR)/modules/vfspk3.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) -Ilibs -Iinclude
|
$(INSTALLDIR)/modules/vfspk3.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) -Ilibs -Iinclude
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,6 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include "string/string.h"
|
|
||||||
#include "os/path.h"
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( POSIX )
|
#if defined ( POSIX )
|
||||||
|
|
||||||
|
|
@ -134,3 +131,11 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
bool Q_mkdir( const char* path ){
|
||||||
|
std::error_code err;
|
||||||
|
std::filesystem::create_directories( path, err );
|
||||||
|
return !err;
|
||||||
|
}
|
||||||
|
|
@ -25,8 +25,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
|
|
||||||
// TTimo started adding portability code:
|
// TTimo started adding portability code:
|
||||||
// return true if spawning was successful, false otherwise
|
// return true if spawning was successful, false otherwise
|
||||||
|
|
@ -47,14 +45,4 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo
|
||||||
|
|
||||||
// Q_mkdir
|
// Q_mkdir
|
||||||
// returns true if succeeded in creating directory
|
// returns true if succeeded in creating directory
|
||||||
#ifdef WIN32
|
bool Q_mkdir( const char* path );
|
||||||
#include <direct.h>
|
|
||||||
inline bool Q_mkdir( const char* name ){
|
|
||||||
return _mkdir( name ) != -1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#include <sys/stat.h>
|
|
||||||
inline bool Q_mkdir( const char* name ){
|
|
||||||
return mkdir( name, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) != -1; // rwxrwxr-x
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
|
@ -124,36 +125,11 @@ void Q_getwd( char *out ){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Q_mkdir( const char *path ){
|
void Q_mkdir( const char* path ){
|
||||||
char parentbuf[256];
|
std::error_code err;
|
||||||
const char *p = NULL;
|
std::filesystem::create_directories( path, err );
|
||||||
int retry = 2;
|
if ( err ) {
|
||||||
while ( retry-- )
|
Error( "Q_mkdir %s: %s", path, err.message().c_str() );
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
if ( _mkdir( path ) != -1 ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if ( mkdir( path, 0777 ) != -1 ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if ( errno == ENOENT ) {
|
|
||||||
p = path_get_last_separator( path );
|
|
||||||
}
|
|
||||||
if ( !strEmptyOrNull( p ) ) {
|
|
||||||
strcpyQ( parentbuf, path, p - path + 1 );
|
|
||||||
if ( ( p - path ) < (ptrdiff_t) sizeof( parentbuf ) ) {
|
|
||||||
Sys_Printf( "mkdir: %s: creating parent %s first\n", path, parentbuf );
|
|
||||||
Q_mkdir( parentbuf );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ( errno != EEXIST ) {
|
|
||||||
Error( "mkdir %s: %s", path, strerror( errno ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user