-
-/*
- * traverse_dir() is the callback functiion for File Tree Walk (nftw).
- * it receives the path of the current entry (file, dir, link..etc) with
- * a flag to indicate the type of the entry.
- * if the entry being visited is a directory and contains a metadata file,
- * then open it for reading and save a trace_descriptor to that directory
- * in the read trace collection.
- */
-static int traverse_dir(const char *fpath, const struct stat *sb,
- int tflag, struct FTW *ftwbuf)
-{
- int dirfd;
- int fd;
- struct trace_descriptor *td_read;
- int ret;
-
- if (tflag != FTW_D)
- return 0;
- dirfd = open(fpath, 0);
- if (dirfd < 0) {
- fprintf(stderr, "[error] unable to open trace "
- "directory file descriptor.\n");
- return -1;
- }
- fd = openat(dirfd, "metadata", O_RDONLY);
- if (fd < 0) {
- close(dirfd);
- } else {
- close(fd);
- close(dirfd);
- td_read = fmt_read->open_trace(opt_input_path,
- fpath, O_RDONLY, ctf_move_pos_slow,
- NULL);
- if (!td_read) {
- fprintf(stderr, "Error opening trace \"%s\" "
- "for reading.\n\n", fpath);
- return -1; /* error */
- }
- ret = trace_collection_add(&trace_collection_read, td_read);
- if (ret) {
- return -1;
- }
- }
- return 0; /* success */
-}
-