Просмотр исходного кода

d.mon: check for write permission if output is defined

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68983 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 8 лет назад
Родитель
Сommit
d63b1da655
1 измененных файлов с 12 добавлено и 0 удалено
  1. 12 0
      display/d.mon/start.c

+ 12 - 0
display/d.mon/start.c

@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <libgen.h>
 #include <grass/gis.h>
 #include <grass/spawn.h>
 #include <grass/display.h>
@@ -57,7 +58,18 @@ char *start(const char *name, const char *output, int width, int height, int upd
         putenv("GRASS_RENDER_IMMEDIATE=");
     }
     else {
+        char *dir_name;
+        
         output_name = output;
+        /* check write permission */
+        dir_name = G_store(output_name);
+        dirname(dir_name);
+        if (access(dir_name, W_OK) != 0)
+            G_fatal_error(_("Unable to start monitor, don't have "
+                            "write permission for <%s>"), output_name);
+        G_free(dir_name);
+        
+        /* check if file exists */
         if (!update && access(output_name, F_OK) == 0) {
             if (G_get_overwrite()) {
                 G_warning(_("File <%s> already exists and will be overwritten"), output_name);