From 7edb0cbc236244d996d1e2ae1d58d0e9f7d98062 Mon Sep 17 00:00:00 2001 From: Josh Bressers Date: Tue, 21 Aug 2007 21:19:39 +0000 Subject: [PATCH] * Red Hat Bug #253342: inc.c, utils.c, utils.h: When inc is run with the -silent flag, don't exit(1) for no apparent reason. --- ChangeLog | 5 +++++ h/utils.h | 1 + sbr/utils.c | 23 +++++++++++++++++++++++ uip/inc.c | 13 +++++++++---- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89de2f8..1412bf3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-08-21 Josh Bressers + + * Red Hat Bug #253342: inc.c, utils.c, utils.h: When inc is run with + the -silent flag, don't exit(1) for no apparent reason. + 2007-03-12 Peter Maydell * bug #18630, #18631, #18632, #18634: various patches from diff --git a/h/utils.h b/h/utils.h index 92fdaba..9c19e92 100644 --- a/h/utils.h +++ b/h/utils.h @@ -9,6 +9,7 @@ void *mh_xmalloc(size_t); void *mh_xrealloc(void *, size_t); char *pwd(void); char *add(char *, char *); +int folder_exists(char *); void create_folder(char *, int, void (*)()); int num_digits(int); diff --git a/sbr/utils.c b/sbr/utils.c index 64df443..87d368d 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -121,6 +121,29 @@ add (char *s2, char *s1) } /* + * folder_exists + * Check to see if a folder exists. + */ +int folder_exists(char *folder) +{ + struct stat st; + int exists = 0; + + if (stat (folder, &st) == -1) { + /* The folder either doesn't exist, or we hit an error. Either way + * return a failure. + */ + exists = 0; + } else { + /* We can see a folder with the right name */ + exists = 1; + } + + return exists; +} + + +/* * create_folder * Check to see if a folder exists, if not, prompt the user to create * it. diff --git a/uip/inc.c b/uip/inc.c index a2ecb44..45036f5 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -563,10 +563,15 @@ main (int argc, char **argv) if ((maildir_copy = strdup(maildir)) == (char *)0) adios (maildir, "error allocating memory to copy maildir"); - if (noisy) - create_folder(maildir, 0, done); - else - done (1); + if (!folder_exists(maildir)) { + /* If the folder doesn't exist, and we're given the -silent flag, + * just fail. + */ + if (noisy) + create_folder(maildir, 0, done); + else + done (1); + } if (chdir (maildir) == NOTOK) adios (maildir, "unable to change directory to"); -- 1.7.10.4