ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=95958caa310c1d223f0d0fb5e23bee39cbab0307

commit 95958caa310c1d223f0d0fb5e23bee39cbab0307
Author: Andy Williams <a...@andywilliams.me>
Date:   Wed Oct 22 22:41:23 2014 +0100

    Warn if the passed parameter is not a valid project location.
    Currently EDI can only open existing directories or create them - no single 
file mode
---
 src/bin/edi_main.c |  8 ++++++--
 src/lib/Edi.h      |  6 +++++-
 src/lib/edi.c      | 29 ++++++++++++++++++++++++++++-
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c
index cc2d59f..1912797 100644
--- a/src/bin/edi_main.c
+++ b/src/bin/edi_main.c
@@ -386,7 +386,11 @@ edi_open(const char *path)
    Evas_Object *win, *vbx, *content, *tb;
    const char *winname;
 
-   edi_project_set(path);
+   if (!edi_project_set(path))
+     {
+        fprintf(stderr, "Project path must be a directory\n");
+        return NULL;
+     }
 
    elm_need_ethumb();
    elm_need_efreet();
@@ -481,7 +485,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
 
    if (args < argc)
      {
-        project_path = realpath(argv[args], NULL);
+        project_path = argv[args];
      }
 
    elm_app_info_set(elm_main, "edi", "images/edi.png");
diff --git a/src/lib/Edi.h b/src/lib/Edi.h
index c533995..aff9918 100644
--- a/src/lib/Edi.h
+++ b/src/lib/Edi.h
@@ -2,6 +2,7 @@
 # define EDI_H_
 
 #include <Elementary.h>
+#include <Eina.h>
 
 #ifdef EAPI
 # undef EAPI
@@ -98,12 +99,15 @@ EAPI int edi_shutdown(void);
  * @{
  *
  * Set the current edi project that is loaded.
+ * Any directory is deemed a valid project.
  *
  * @param path The path to the current project being loaded.
+ * @return EINA_TRUE if the path represented a valid project,
+ *   EINA_FALSE otherwise
  *
  * @ingroup Main
  */
-EAPI void edi_project_set(const char *path);
+EAPI Eina_Bool edi_project_set(const char *path);
 
 /**
  * Get the current edi project that is loaded.
diff --git a/src/lib/edi.c b/src/lib/edi.c
index 7d667ed..8950a49 100644
--- a/src/lib/edi.c
+++ b/src/lib/edi.c
@@ -2,6 +2,10 @@
 # include "config.h"
 #endif
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 #include "Edi.h"
 
 #include "edi_private.h"
@@ -58,13 +62,36 @@ edi_shutdown(void)
    return _edi_init;
 }
 
-EAPI void
+static Eina_Bool
+_edi_path_isdir(const char *path)
+{
+    struct stat buf;
+
+    if (!path)
+      return EINA_FALSE;
+
+    stat(path, &buf);
+    return S_ISDIR(buf.st_mode);
+}
+
+EAPI Eina_Bool
 edi_project_set(const char *path)
 {
+   char *real = NULL;
+
+   real = realpath(real, NULL);
+   if (!_edi_path_isdir(path))
+     {
+        free(real);
+        return EINA_FALSE;
+     }
+
    if (_edi_project_path)
      eina_stringshare_del(_edi_project_path);
 
    _edi_project_path = eina_stringshare_add(path);
+   free(real);
+   return EINA_TRUE;
 }
 
 EAPI const char *

-- 


Reply via email to