Esempio n. 1
0
gboolean
_ip_start_watching (inotify_sub *sub)
{
  gint32 wd;
  int err;
  ip_watched_dir_t *dir;
  
  g_assert (sub);
  g_assert (!sub->cancelled);
  g_assert (sub->dirname);
  
  IP_W ("Starting to watch %s\n", sub->dirname);
  dir = g_hash_table_lookup (path_dir_hash, sub->dirname);

  if (dir == NULL)
    {
      IP_W ("Trying to add inotify watch ");
      wd = _ik_watch (sub->dirname, IP_INOTIFY_DIR_MASK|IN_ONLYDIR, &err);
      if (wd < 0)
        {
          IP_W ("Failed\n");
          return FALSE;
        }
      else
        {
          /* Create new watched directory and associate it with the
           * wd hash and path hash
           */
          IP_W ("Success\n");
          dir = ip_watched_dir_new (sub->dirname, wd);
          ip_map_wd_dir (wd, dir);
          ip_map_path_dir (sub->dirname, dir);
        }
    }
  else
    IP_W ("Already watching\n");

  if (sub->hardlinks)
    {
      ip_watched_file_t *file;

      file = g_hash_table_lookup (dir->files_hash, sub->filename);

      if (file == NULL)
        {
          file = ip_watched_file_new (sub->dirname, sub->filename);
          g_hash_table_insert (dir->files_hash, file->filename, file);
        }

      ip_watched_file_add_sub (file, sub);
      ip_watched_file_start (file);
    }

  ip_map_sub_dir (sub, dir);
  
  return TRUE;
}
gboolean ip_start_watching (ih_sub_t *sub)
{
	gint32 wd;
	int err;
	ip_watched_dir_t *dir;

	g_assert (sub);
	g_assert (!sub->cancelled);
	g_assert (sub->dirname);

	IP_W("Starting to watch %s\n", sub->dirname);
	dir = g_hash_table_lookup (path_dir_hash, sub->dirname);
	if (dir)
	{
		IP_W("Already watching\n");
		goto out;
	}
	
	IP_W("Trying to add inotify watch ");
	wd = ik_watch (sub->dirname, IP_INOTIFY_MASK|IN_ONLYDIR|sub->extra_flags, &err);
	if (wd < 0) 
	{
		IP_W("Failed\n");
		return FALSE;
	} else {
		/* Create new watched directory and associate it with the 
		 * wd hash and path hash
		 */
		IP_W("Success\n");
		dir = ip_watched_dir_new (sub->dirname, wd);
		ip_map_wd_dir (wd, dir);
		ip_map_path_dir (sub->dirname, dir);
	}

out:
	ip_map_sub_dir (sub, dir);

	return TRUE;
}