diff options
author | Nick White <git@njw.me.uk> | 2008-07-05 13:42:56 +0100 |
---|---|---|
committer | Nick White <git@njw.me.uk> | 2008-07-05 13:42:56 +0100 |
commit | 426b90eb144b92048edef8d77b8894b70ee40c72 (patch) | |
tree | 6efa75512580b3eebaca773e95cca9f82341bcff /src/download.c | |
parent | e19a189c4019b52f5a9c70b22941b3450a911591 (diff) |
Don't create save directory until needed
Diffstat (limited to 'src/download.c')
-rw-r--r-- | src/download.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/download.c b/src/download.c index 41ec44b..a6dcc49 100644 --- a/src/download.c +++ b/src/download.c @@ -175,22 +175,51 @@ double getremotefilesize(char *uri, struct config * options) return filesize; } +char * checkdir(char * dir) +/* Checks that dir is writable. If necessary prompt + * the user for a new directory and return it. */ +{ + int dirchanged = 0; + + if(!opendir(dir)) + while(mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) + { + fprintf(stderr,"Cannot create directory %s\n", dir); + printf("Please enter the path of a save directory: "); + scanf("%s", dir); + dirchanged = 1; + } + + if(dirchanged) + return dir; + else + return 0; +} + char * getissuedir(struct config * options, iss * issue) /* Returns and prepares download directory */ { + char * newsavedir; char * newdir; + newsavedir = malloc(STR_MAX); newdir = malloc(STR_MAX); + /* Check that main save path is ok */ + newsavedir = checkdir(options->save_path); + /* Save the new save path if it changed */ + if(newsavedir) + { + char getht_path[STR_MAX]; + snprintf(getht_path,STR_MAX,"%s/.getht",getenv("HOME")); + updateconfig(getht_path, &options); + } + snprintf(newdir,STR_MAX,"%s/%i_%i-%i",options->save_path, issue->date.year,issue->date.firstmonth,issue->date.lastmonth); - if(!opendir(newdir)) - if(mkdir(newdir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) - { - printf("Please enter the path of a directory to save issues in: "); - scanf("%s", newdir); - } + /* Check that specific issue path is ok */ + checkdir(newdir); return newdir; } |