From affa72c5d322e49f3d5b4b7ce3e892e172869120 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Sun, 26 Dec 2010 18:29:03 +0000 Subject: [PATCH] Check for the proper creation of a directory Check the return code of mkdir and display an error message if the directory could not be created. --- html.c | 7 ++++++- index.c | 14 ++++++++++++-- util.c | 17 ++++++++++------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/html.c b/html.c index 907f165..7570264 100644 --- 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 1f87792..9350422 100644 --- 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 bb7ef92..750017a 100644 --- 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); -- 2.39.5