mirror of
https://gitlab.com/spectre.app/cli.git
synced 2024-11-01 10:51:44 +01:00
Test chdir.
This commit is contained in:
parent
e4c82969ee
commit
e4ceafd0d2
1 changed files with 6 additions and 5 deletions
|
@ -220,17 +220,18 @@ bool mpw_mkdirs(const char *filePath) {
|
|||
if (!filePath)
|
||||
return false;
|
||||
|
||||
// Save the cwd and for absolute paths, start at the root.
|
||||
char *cwd = getcwd( NULL, 0 );
|
||||
if (*filePath == '/')
|
||||
if (!chdir( "/" ))
|
||||
return false;
|
||||
|
||||
// The path to mkdir is the filePath without the last path component.
|
||||
char *pathEnd = strrchr( filePath, '/' );
|
||||
char *path = pathEnd? mpw_strndup( filePath, (size_t)(pathEnd - filePath) ): NULL;
|
||||
if (!path)
|
||||
return false;
|
||||
|
||||
// Save the cwd and for absolute paths, start at the root.
|
||||
char *cwd = getcwd( NULL, 0 );
|
||||
if (*filePath == '/')
|
||||
chdir( "/" );
|
||||
|
||||
// Walk the path.
|
||||
bool success = true;
|
||||
for (char *dirName = strtok( path, "/" ); success && dirName; dirName = strtok( NULL, "/" )) {
|
||||
|
|
Loading…
Reference in a new issue