]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Check for the proper creation of a directory
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Dec 2010 18:29:03 +0000 (18:29 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Dec 2010 18:29:03 +0000 (18:29 +0000)
Check the return code of mkdir and display an error message if the
directory could not be created.

html.c
index.c
util.c

diff --git a/html.c b/html.c
index 907f1652ef191be488a941ddfb293e46a7355cb8..75702648c521f516c2aa0cea0362d32359f55892 100644 (file)
--- a/html.c
+++ b/html.c
@@ -121,7 +121,12 @@ void htmlrel(void)
                        debuga(_("Destination directory too long: %s/%s\n"),outdirname,user);
                        exit(EXIT_FAILURE);
                }
-               mkdir(warea,0755);
+               if (access(warea, R_OK) != 0) {
+                       if (mkdir(warea,0755)) {
+                               debuga(_("Cannot create directory %s - %s\n"),warea,strerror(errno));
+                               exit(EXIT_FAILURE);
+                       }
+               }
 
                report_day(uinfo);
                greport_day(uinfo);
diff --git a/index.c b/index.c
index 1f8779285c677c89b2ca598ab4aa0833e7d57496..9350422a81141945de3ceda53262788cadaedea0 100644 (file)
--- a/index.c
+++ b/index.c
@@ -530,10 +530,20 @@ static void file_index_to_date_index(const char *entry)
        m1=conv_month(sm1);
        m2=conv_month(sm2);
        ndirlen=sprintf(newdir,"%s%04d",outdir,y1);
-       if(access(newdir, R_OK) != 0) mkdir(newdir,0755);
+       if (access(newdir, R_OK) != 0) {
+               if (mkdir(newdir,0755)) {
+                       debuga(_("Cannot create directory %s - %s\n"),newdir,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
+       }
        if(m1 != m2) ndirlen+=sprintf(newdir+ndirlen,"/%02d-%02d",m1,m2);
        else ndirlen+=sprintf(newdir+ndirlen,"/%02d",m1);
-       if(access(newdir, R_OK) != 0) mkdir(newdir,0755);
+       if (access(newdir, R_OK) != 0) {
+               if (mkdir(newdir,0755)) {
+                       debuga(_("Cannot create directory %s - %s\n"),newdir,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
+       }
        monthlen=ndirlen;
        if(d1!=d2) ndirlen+=sprintf(newdir+ndirlen,"/%02d-%02d",d1,d2);
        else ndirlen+=sprintf(newdir+ndirlen,"/%02d",d1);
diff --git a/util.c b/util.c
index bb7ef92930fedb6273458054fb46e4c4ac03d9f3..750017a4fbdb604771ba79c44a8ce4650c838c89 100644 (file)
--- a/util.c
+++ b/util.c
@@ -282,9 +282,9 @@ void my_mkdir(const char *name)
                }
                if (chars>0 && name[i] == '/') {
                        w0[i] = '\0';
-                       if(access(w0, R_OK) != 0) {
-                               if(mkdir(w0,0755)) {
-                                       debuga(_("mkdir %s %s\n"),w0,strerror(errno));
+                       if (access(w0, R_OK) != 0) {
+                               if (mkdir(w0,0755)) {
+                                       debuga(_("Cannot create directory %s - %s\n"),w0,strerror(errno));
                                        debuga(_("process aborted.\n"));
                                        exit(EXIT_FAILURE);
                                }
@@ -294,9 +294,9 @@ void my_mkdir(const char *name)
                w0[i] = name[i];
        }
 
-       if(access(name, R_OK) != 0) {
-               if(mkdir(name,0755)) {
-                       debuga(_("mkdir %s %s\n"),name,strerror(errno));
+       if (access(name, R_OK) != 0) {
+               if (mkdir(name,0755)) {
+                       debuga(_("Cannot create directory %s - %s\n"),name,strerror(errno));
                        debuga(_("process aborted.\n"));
                        exit(EXIT_FAILURE);
                }
@@ -862,7 +862,10 @@ static void copy_images(void)
                exit(EXIT_FAILURE);
        }
        if (access(images,R_OK)!=0) {
-               mkdir(images,0755);
+               if (mkdir(images,0755)) {
+                       debuga(_("Cannot create directory %s - %s\n"),images,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
        }
 
        strcpy(imgdir,IMAGEDIR);