[PATCH] Check error returns from creating output directories

View: New views
1 Messages — Rating Filter:   Alert me  

[PATCH] Check error returns from creating output directories

by Lawrence D'Oliveiro-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If dvdauthor cannot create any part of the output directory structure (for
instance because of protection failures), it doesn't notice. Instead, when
it later tries to create a VOB file in a missing output directory, it will
fail with a confusing message like

    Error opening out/VIDEO_TS/VTS_01_1.VOB: No such file or directory

To fix this, the initdir routine in src/dvdauthor.c needs to check the
returns from the mkdir calls. We want to ignore EEXIST (meaning the
directories already exist), but abort on other errors (e.g. "Permission
denied").

diff -ur dvdauthor-0.6.14-orig/src/dvdauthor.c dvdauthor-0.6.14-check-mkdir/src/dvdauthor.c
--- dvdauthor-0.6.14-orig/src/dvdauthor.c 2007-01-12 20:11:11.000000000 +1300
+++ dvdauthor-0.6.14-check-mkdir/src/dvdauthor.c 2008-07-30 21:00:11.000000000 +1200
@@ -873,11 +873,20 @@
     static char realfbase[1000];
 
     if( fbase ) {
-        mkdir(fbase,0777);
-        sprintf(realfbase,"%s/VIDEO_TS",fbase);
-        mkdir(realfbase,0777);
-        sprintf(realfbase,"%s/AUDIO_TS",fbase);
-        mkdir(realfbase,0777);
+        if (mkdir(fbase,0777) && errno != EEXIST) {
+            fprintf(stderr, "ERR:  cannot create dir %s: %s\n", fbase, strerror(errno));
+            exit(1);
+        }
+        snprintf(realfbase, sizeof realfbase, "%s/VIDEO_TS", fbase);
+        if (mkdir(realfbase,0777) && errno != EEXIST) {
+            fprintf(stderr, "ERR:  cannot create dir %s: %s\n", realfbase, strerror(errno));
+            exit(1);
+        }
+        snprintf(realfbase, sizeof realfbase, "%s/AUDIO_TS", fbase);
+        if (mkdir(realfbase,0777) && errno != EEXIST) {
+            fprintf(stderr, "ERR:  cannot create dir %s: %s\n", realfbase, strerror(errno));
+            exit(1);
+        }
     }
 }
 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Dvdauthor-developer mailing list
Dvdauthor-developer@...
https://lists.sourceforge.net/lists/listinfo/dvdauthor-developer
LightInTheBox - Buy quality products at wholesale price!