summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2008-07-05 13:42:56 +0100
committerNick White <git@njw.me.uk>2008-07-05 13:42:56 +0100
commit426b90eb144b92048edef8d77b8894b70ee40c72 (patch)
tree6efa75512580b3eebaca773e95cca9f82341bcff
parente19a189c4019b52f5a9c70b22941b3450a911591 (diff)
Don't create save directory until needed
-rw-r--r--src/download.c41
-rw-r--r--src/getht.c10
2 files changed, 35 insertions, 16 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;
}
diff --git a/src/getht.c b/src/getht.c
index 6528652..63ba956 100644
--- a/src/getht.c
+++ b/src/getht.c
@@ -75,16 +75,6 @@ int main(int argc, char *argv[])
if(loadconfig(getht_path, &options) != 0)
writefreshconfig(getht_path, &options);
- if(!opendir(options.save_path))
- if(mkdir(options.save_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
- {
- fprintf(stderr,"Cannot open/create directory %s",options.save_path);
- printf("Please enter the path of a directory to save issues in: ");
- scanf("%s", options.save_path);
-
- updateconfig(getht_path, &options);
- }
-
/* Parse command line options */
char c;
static struct option long_opts[] =