From 426b90eb144b92048edef8d77b8894b70ee40c72 Mon Sep 17 00:00:00 2001 From: Nick White Date: Sat, 5 Jul 2008 13:42:56 +0100 Subject: Don't create save directory until needed --- src/download.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'src/download.c') 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; } -- cgit v1.2.3