コード例 #1
0
static void
rm_rf (const char * killme)
{
  tr_sys_path_info info;

  if (tr_sys_path_get_info (killme, 0, &info, NULL))
    {
      tr_sys_dir_t odir;

      if (info.type == TR_SYS_PATH_IS_DIRECTORY &&
          (odir = tr_sys_dir_open (killme, NULL)) != TR_BAD_SYS_DIR)
        {
          const char * name;
          while ((name = tr_sys_dir_read_name (odir, NULL)) != NULL)
            {
              if (strcmp (name, ".") != 0 && strcmp (name, "..") != 0)
                {
                  char * tmp = tr_buildPath (killme, name, NULL);
                  rm_rf (tmp);
                  tr_free (tmp);
                }
            }
          tr_sys_dir_close (odir, NULL);
        }

      if (verbose)
        fprintf (stderr, "cleanup: removing %s\n", killme);

      tr_sys_path_remove (killme, NULL);
    }
}
コード例 #2
0
ファイル: watch.c プロジェクト: keefo/transmission
static void
watchdir_new_impl (dtr_watchdir * w)
{
    int i;
    tr_sys_dir_t odir;
    w->inotify_fd = inotify_init ();

    if (w->inotify_fd < 0)
    {
        i = -1;
    }
    else
    {
        tr_logAddInfo ("Using inotify to watch directory \"%s\"", w->dir);
        i = inotify_add_watch (w->inotify_fd, w->dir, DTR_INOTIFY_MASK);
    }

    if (i < 0)
    {
        tr_logAddError ("Unable to watch \"%s\": %s", w->dir, tr_strerror (errno));
    }
    else if ((odir = tr_sys_dir_open (w->dir, NULL)) != TR_BAD_SYS_DIR)
    {
        const char * name;
        while ((name = tr_sys_dir_read_name (odir, NULL)) != NULL)
        {
            if (!tr_str_has_suffix (name, ".torrent")) /* skip non-torrents */
                continue;

            tr_logAddInfo ("Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir);
            w->callback (w->session, w->dir, name);
        }

        tr_sys_dir_close (odir, NULL);
    }

}