Пример #1
0
dpl_status_t
recurse(dpl_ctx_t *ctx,
        char *dir,
        int level)
{
  void *dir_hdl;
  dpl_dirent_t dirent;
  int ret;

  ret = dpl_chdir(ctx, dir);
  if (DPL_SUCCESS != ret)
    return ret;

  ret = dpl_opendir(ctx, ".", &dir_hdl);
  if (DPL_SUCCESS != ret)
    return ret;

  while (!dpl_eof(dir_hdl))
    {
      ret = dpl_readdir(dir_hdl, &dirent);
      if (DPL_SUCCESS != ret)
        return ret;

      if (strcmp(dirent.name, "."))
        {
          int i;

          for (i = 0;i < level;i++)
            printf(" ");
          printf("%s\n", dirent.name);

          if (DPL_FTYPE_DIR == dirent.type)
            {
              ret = recurse(ctx, dirent.name, level + 1);
              if (DPL_SUCCESS != ret)
                return ret;
            }
        }
    }

  dpl_closedir(dir_hdl);

  if (level > 0)
    {
      ret = dpl_chdir(ctx, "..");
      if (DPL_SUCCESS != ret)
        return ret;
    }

  return DPL_SUCCESS;
}
Пример #2
0
int
dfs_readdir(const char *path,
            void *data,
            fuse_fill_dir_t fill,
            off_t offset,
            struct fuse_file_info *info)
{
        void *dir_hdl = NULL;
        tfs_ctx *ctx = fuse_get_context()->private_data;
        dpl_dirent_t dirent;
        dpl_status_t rc = DPL_FAILURE;
        int ret;

        LOG(LOG_DEBUG, "path=%s, data=%p, fill=%p, offset=%lld, info=%p",
            path, data, (void *) fill, (long long) offset, (void *) info);

        if (info)
                dir_hdl = (void *) info->fh;

        LOG(LOG_DEBUG, "dir_hdl=%p", dir_hdl);

        if (! dir_hdl) {

                rc = dfs_opendir_timeout(ctx, path, &dir_hdl);
                if (DPL_SUCCESS != rc) {
                        LOG(LOG_ERR, "dfs_opendir_timeout: %s", dpl_status_str(rc));
                        ret = rc;
                        goto err;
                }
        }

        while (DPL_SUCCESS == dpl_readdir(dir_hdl, &dirent)) {
                if (! strcmp("", dirent.name))
                        continue;

                LOG(LOG_DEBUG, "dirent.name=%s", dirent.name);

                if (0 != fill(data, dirent.name, NULL, 0))
                        break;
        }

        ret = 0;
  err:
        LOG(LOG_DEBUG, "path=%s ret=%s", path, dpl_status_str(ret));
        return ret;
}
Пример #3
0
dpl_status_t
ls_recurse(struct ls_data *ls_data,
           char *dir,
           int level)
{
  int ret;

  if (1 == ls_data->aflag)
    {
      dpl_vec_t *objects = NULL;
      int i;

      //raw listing
      ret = dpl_list_bucket(ctx, ctx->cur_bucket, NULL, NULL, &objects, NULL);
      if (DPL_SUCCESS != ret)
        {
          fprintf(stderr, "listbucket failure %s (%d)\n", dpl_status_str(ret), ret);
          return ret;
        }

      for (i = 0;i < objects->n_items;i++)
        {
          dpl_object_t *obj = (dpl_object_t *) objects->array[i];

          if (0 == ls_data->pflag)
            {
              if (ls_data->lflag)
                {
                  struct tm *stm;

                  stm = localtime(&obj->last_modified);
                  printf("%12llu %04d-%02d-%02d %02d:%02d %s\n", (unsigned long long) obj->size, 1900 + stm->tm_year, 1 + stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, obj->key);
                }
              else
                {
                  printf("%s\n", obj->key);
                }
            }

          ls_data->total_size += obj->size;
        }

      if (NULL != objects)
        dpl_vec_objects_free(objects);
    }
  else
    {
      void *dir_hdl;
      dpl_dirent_t entry;
      dpl_ino_t cur_ino;

      if (1 == ls_data->Rflag)
        {
          ret = dpl_chdir(ctx, dir);
          if (DPL_SUCCESS != ret)
            return ret;

          cur_ino = dpl_cwd(ctx, ctx->cur_bucket);

          printf("%s%s%s:\n", 0 == level ? "" : "\n", ctx->delim, cur_ino.key);

          ret = dpl_opendir(ctx, ".", &dir_hdl);
          if (DPL_SUCCESS != ret)
            return ret;
        }
      else
        {
          ret = dpl_opendir(ctx, dir, &dir_hdl);
          if (DPL_SUCCESS != ret)
            return ret;
        }

      while (!dpl_eof(dir_hdl))
        {
          ret = dpl_readdir(dir_hdl, &entry);
          if (DPL_SUCCESS != ret)
            return ret;

          if (0 == ls_data->pflag)
            {
              if (ls_data->lflag)
                {
                  struct tm *stm;

                  stm = localtime(&entry.last_modified);
                  printf("%12llu %04d-%02d-%02d %02d:%02d %s\n", (unsigned long long) entry.size, 1900 + stm->tm_year, 1 + stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, entry.name);
                }
              else
                {
                  printf("%s\n", entry.name);
                }
            }

          ls_data->total_size += entry.size;

          if (1 == ls_data->Rflag &&
              strcmp(entry.name, ".") &&
              (DPL_FTYPE_DIR == entry.type))
            {
              ret = ls_recurse(ls_data, entry.name, level + 1);
              if (DPL_SUCCESS != ret)
                return ret;
            }
        }

      dpl_closedir(dir_hdl);

      if (1 == ls_data->Rflag && level > 0)
        {
          ret = dpl_chdir(ctx, "..");
          if (DPL_SUCCESS != ret)
            return ret;
        }
    }

  return DPL_SUCCESS;
}