|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "tool_setup.h" |
|
|
|
|
|
#include <sys/stat.h> |
|
|
|
|
|
#ifdef _WIN32 |
|
|
# include <direct.h> |
|
|
#endif |
|
|
|
|
|
#include "curlx.h" |
|
|
|
|
|
#include "tool_dirhie.h" |
|
|
#include "tool_msgs.h" |
|
|
|
|
|
#include "memdebug.h" |
|
|
|
|
|
#if defined(_WIN32) || (defined(MSDOS) && !defined(__DJGPP__)) |
|
|
# define mkdir(x,y) (mkdir)((x)) |
|
|
# ifndef F_OK |
|
|
# define F_OK 0 |
|
|
# endif |
|
|
#endif |
|
|
|
|
|
static void show_dir_errno(struct GlobalConfig *global, const char *name) |
|
|
{ |
|
|
switch(errno) { |
|
|
#ifdef EACCES |
|
|
case EACCES: |
|
|
errorf(global, "You do not have permission to create %s", name); |
|
|
break; |
|
|
#endif |
|
|
#ifdef ENAMETOOLONG |
|
|
case ENAMETOOLONG: |
|
|
errorf(global, "The directory name %s is too long", name); |
|
|
break; |
|
|
#endif |
|
|
#ifdef EROFS |
|
|
case EROFS: |
|
|
errorf(global, "%s resides on a read-only file system", name); |
|
|
break; |
|
|
#endif |
|
|
#ifdef ENOSPC |
|
|
case ENOSPC: |
|
|
errorf(global, "No space left on the file system that will " |
|
|
"contain the directory %s", name); |
|
|
break; |
|
|
#endif |
|
|
#ifdef EDQUOT |
|
|
case EDQUOT: |
|
|
errorf(global, "Cannot create directory %s because you " |
|
|
"exceeded your quota", name); |
|
|
break; |
|
|
#endif |
|
|
default: |
|
|
errorf(global, "Error creating directory %s", name); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(__DJGPP__) |
|
|
|
|
|
#define PATH_DELIMITERS "\\/" |
|
|
#else |
|
|
#define PATH_DELIMITERS DIR_CHAR |
|
|
#endif |
|
|
|
|
|
|
|
|
CURLcode create_dir_hierarchy(const char *outfile, struct GlobalConfig *global) |
|
|
{ |
|
|
char *tempdir; |
|
|
char *tempdir2; |
|
|
char *outdup; |
|
|
char *dirbuildup; |
|
|
CURLcode result = CURLE_OK; |
|
|
size_t outlen; |
|
|
|
|
|
outlen = strlen(outfile); |
|
|
outdup = strdup(outfile); |
|
|
if(!outdup) |
|
|
return CURLE_OUT_OF_MEMORY; |
|
|
|
|
|
dirbuildup = malloc(outlen + 1); |
|
|
if(!dirbuildup) { |
|
|
Curl_safefree(outdup); |
|
|
return CURLE_OUT_OF_MEMORY; |
|
|
} |
|
|
dirbuildup[0] = '\0'; |
|
|
|
|
|
|
|
|
|
|
|
tempdir = strtok(outdup, PATH_DELIMITERS); |
|
|
|
|
|
while(tempdir) { |
|
|
bool skip = false; |
|
|
tempdir2 = strtok(NULL, PATH_DELIMITERS); |
|
|
|
|
|
|
|
|
if(tempdir2) { |
|
|
size_t dlen = strlen(dirbuildup); |
|
|
if(dlen) |
|
|
msnprintf(&dirbuildup[dlen], outlen - dlen, "%s%s", DIR_CHAR, tempdir); |
|
|
else { |
|
|
if(outdup == tempdir) { |
|
|
#if defined(_WIN32) || defined(MSDOS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *p = strchr(tempdir, ':'); |
|
|
if(p && !p[1]) |
|
|
skip = true; |
|
|
#endif |
|
|
|
|
|
strcpy(dirbuildup, tempdir); |
|
|
} |
|
|
else |
|
|
msnprintf(dirbuildup, outlen, "%s%s", DIR_CHAR, tempdir); |
|
|
} |
|
|
|
|
|
if(!skip && (-1 == mkdir(dirbuildup, (mode_t)0000750)) && |
|
|
(errno != EACCES) && (errno != EEXIST)) { |
|
|
show_dir_errno(global, dirbuildup); |
|
|
result = CURLE_WRITE_ERROR; |
|
|
break; |
|
|
} |
|
|
} |
|
|
tempdir = tempdir2; |
|
|
} |
|
|
|
|
|
Curl_safefree(dirbuildup); |
|
|
Curl_safefree(outdup); |
|
|
|
|
|
return result; |
|
|
} |
|
|
|