Merge pull request #8153 from Robyt3/Base-Makedir-Rec-Windows-Fix

Fix recursive folder creation with mixed slashes and drive letters
This commit is contained in:
archimede67 2024-03-24 12:22:42 +00:00 committed by GitHub
commit e26ccdd921
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View file

@ -2293,17 +2293,20 @@ int fs_storage_path(const char *appname, char *path, int max)
int fs_makedir_rec_for(const char *path)
{
char buffer[1024 * 2];
char *p;
char buffer[IO_MAX_PATH_LENGTH];
str_copy(buffer, path);
for(p = buffer + 1; *p != '\0'; p++)
for(int index = 1; buffer[index] != '\0'; ++index)
{
if(*p == '/' && *(p + 1) != '\0')
// Do not try to create folder for drive letters on Windows,
// as this is not necessary and may fail for system drives.
if((buffer[index] == '/' || buffer[index] == '\\') && buffer[index + 1] != '\0' && buffer[index - 1] != ':')
{
*p = '\0';
buffer[index] = '\0';
if(fs_makedir(buffer) < 0)
{
return -1;
*p = '/';
}
buffer[index] = '/';
}
}
return 0;

View file

@ -1839,11 +1839,11 @@ int fs_makedir(const char *path);
int fs_removedir(const char *path);
/**
* Recursively create directories for a file.
* Recursively creates parent directories for a file or directory.
*
* @ingroup Filesystem
*
* @param path - File for which to create directories.
* @param path File or directory for which to create parent directories.
*
* @return 0 on success. Negative value on failure.
*