示例#1
0
/*
 * Open a directory on the object store and find out size information for a file.
 */
static inline size_t object_store_get_file_size(dpl_ctx_t *ctx, const char *filename)
{
   void *dir_hdl;
   dpl_status_t status;
   dpl_dirent_t dirent;
   size_t filesize = -1;

   status = dpl_opendir(ctx, ".", &dir_hdl);
   switch (status) {
   case DPL_SUCCESS:
      break;
   default:
      return -1;
   }

   while (!dpl_eof(dir_hdl)) {
      if (bstrcasecmp(dirent.name, filename)) {
         filesize = dirent.size;
         break;
      }
   }

   dpl_closedir(dir_hdl);

   return filesize;
}
示例#2
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;
}
示例#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;
}