e_utils: add support for monitoring file creation in the given directory 50/185650/2
authorSung-Jin Park <sj76.park@samsung.com>
Wed, 1 Aug 2018 09:39:29 +0000 (18:39 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Wed, 1 Aug 2018 10:32:04 +0000 (10:32 +0000)
Change-Id: Ie8b73efdb1f5971710ad43cc984d35619b72e498
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/bin/e_utils.c
src/bin/e_utils.h

index 9f7d6c67083a9d2054371a768d45b8bb47fa49f8..a77263eca70b0a0b555028944b9c631d62497dee 100644 (file)
@@ -1247,12 +1247,23 @@ static void
 _e_util_file_monitor_cb(void *data, Ecore_File_Monitor *em,
                 Ecore_File_Event event, const char *path)
 {
+   int cmp = 0;
    E_Util_File_Monitor *mon = (E_Util_File_Monitor *)data;
 
    if (event != ECORE_FILE_EVENT_CREATED_FILE) return;
-   if (strcmp(path, mon->path)) return;
+   if ((mon->is_dir && !strncmp(mon->path, path, strlen(mon->path)))
+        || (!mon->is_dir && strcmp(mon->path, path)))
+     {
+        _e_util_file_monitor_send_event(path, mon, mon->user_data, E_EVENT_FILE_MONITOR_CREATED);
+     }
 
-   _e_util_file_monitor_send_event(path, mon, mon->user_data, E_EVENT_FILE_MONITOR_CREATED);
+   if (mon->is_dir)
+     cmp = strncmp(mon->path, path, strlen(mon->path));
+   else
+     cmp = strcmp(mon->path, path);
+
+   if (!cmp)
+     _e_util_file_monitor_send_event(path, mon, mon->user_data, E_EVENT_FILE_MONITOR_CREATED);
 }
 
 static void
@@ -1293,11 +1304,12 @@ E_API int
 e_util_file_monitor_add(const char *path, void *data)
 {
    char *dir_path = NULL;
+   Eina_Bool is_dir = EINA_FALSE;
    E_Util_File_Monitor *mon;
 
    if (!path) return 0;
 
-   if (ecore_file_exists(path))
+   if (ecore_file_exists(path) && !(is_dir = ecore_file_is_dir(path)))
      {
         _e_util_file_monitor_send_event(path, NULL, data, E_EVENT_FILE_MONITOR_CREATED);
         return 1;
@@ -1306,7 +1318,9 @@ e_util_file_monitor_add(const char *path, void *data)
    if (eina_hash_find(_e_file_monitor_hash, path))
      return 1;
 
-   dir_path = ecore_file_dir_get(path);
+   dir_path = strdup(path);
+   if (!ecore_file_is_dir(path))
+     dir_path = ecore_file_dir_get(path);
 
    if (!ecore_file_exists(dir_path))
      {
@@ -1325,10 +1339,13 @@ e_util_file_monitor_add(const char *path, void *data)
 
    Ecore_File_Monitor *em = ecore_file_monitor_add(dir_path, _e_util_file_monitor_cb, mon);
 
+   free(dir_path);
+
    if (em)
      {
         mon->em = em;
         mon->path = eina_stringshare_add(path);
+        mon->is_dir = is_dir;
         mon->user_data = data;
         eina_hash_add(_e_file_monitor_hash, path, mon);
         return 1;
index e654d60dba081e08d9516bd831b887dc196b7519..29e36f62af46b0176250762c9b197d9210dbd38c 100644 (file)
@@ -18,6 +18,7 @@ struct _E_Util_File_Monitor
 {
    const char *path;
    Ecore_File_Monitor *em;
+   Eina_Bool is_dir;
    void *user_data;
 };