Logo Search packages:      
Sourcecode: rapple version File versions  Download package

void rpl_fs_recurse ( rpl_c_str_t  filename,
rpl_mod_process_fp  process 
)

Recurses a directory tree invoking the callback on each file (not directory) found therein. Similar to ftw (Linux) or fts (BSD).

Parameters:
filename absolute filename of the asset to be processed.
fn callback to be invoked on each file found.

Definition at line 411 of file fsutil.c.

References rpl_log_error(), rpl_log_fatal(), rpl_me_free(), rpl_me_malloc(), rpl_message_get(), and rpl_str_concat().

Referenced by rpl_fs_delete_ds().

{
    struct dirent *dirp;
    DIR *dp;
    struct stat statbuf;
      rpl_str_t sub_dir, msg;

      assert(filename != NULL);

    /* check that the file exists */
    errno = 0;
    if(stat(filename,&statbuf)==-1) {
        msg = rpl_message_get("FS_PROCESS_FAILED", filename, " (", strerror(errno), ")", RPL_EOM);
        rpl_log_error(msg);
            rpl_me_free(msg);
        return;
    }

    /* recursively process the directory tree */
    if(S_ISREG(statbuf.st_mode)) {
        process(filename, statbuf);
    } else if(S_ISDIR(statbuf.st_mode)) {
        dp=opendir(filename);
        while ((dirp = readdir (dp)) != NULL) {
            if (strcmp (dirp->d_name, ".") == 0 || strcmp (dirp->d_name, "..") == 0)
                continue;
            sub_dir = (rpl_str_t) rpl_me_malloc(strlen(filename) + strlen(dirp->d_name) + 2);
            sprintf(sub_dir, "%s/%s", filename, dirp->d_name);
            rpl_fs_recurse(sub_dir, process);
            rpl_me_free(sub_dir);
        }
        if (closedir (dp) < 0) {
            msg = rpl_message_get("FS_DIR_CLOSE_FAILED", filename, RPL_EOM);
            fprintf(stderr, rpl_str_concat("Fatal: ", msg, RPL_STR_EOC));
            rpl_log_fatal(msg);
        }
            process(filename, statbuf);
      }
}


Generated by  Doxygen 1.6.0   Back to index