static void
update_md(gpointer data,
          gpointer user_data)
{
        pentry_t *pe = NULL;
        char *path = NULL;
        dpl_ftype_t type;
        dpl_ino_t ino;
        dpl_status_t rc;
        dpl_dict_t *metadata = NULL;
        struct list *dirent = NULL;

        (void)user_data;
        pe = data;
        path = pentry_get_path(pe);

        LOG(LOG_DEBUG, "path=%s", path);

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

        rc = dfs_namei_timeout(ctx, path, ctx->cur_bucket,
                               ino, NULL, NULL, &type);

        LOG(LOG_DEBUG, "path=%s, dpl_namei: %s, type=%s",
            path, dpl_status_str(rc), ftype_to_str(type));

        if (DPL_SUCCESS != rc) {
                LOG(LOG_NOTICE, "dfs_namei_timeout: %s", dpl_status_str(rc));
                goto end;
        }

        rc = dfs_getattr_timeout(ctx, path, &metadata);
        if (DPL_SUCCESS != rc && DPL_EISDIR != rc) {
                LOG(LOG_ERR, "dfs_getattr_timeout: %s", dpl_status_str(rc));
                goto end;
        }

        /* If this is a directory, update its entries' metadata */
        if (DPL_FTYPE_DIR == type) {
                dirent = pentry_get_dirents(pe);
                if (dirent)
                        list_map(dirent, cb_map_dirents, pe);
        }

        if (pentry_md_trylock(pe))
                goto end;

        if (metadata)
                pentry_set_metadata(pe, metadata);

        pentry_set_atime(pe);

        (void)pentry_md_unlock(pe);
  end:
        if (metadata)
                dpl_dict_free(metadata);
}
Beispiel #2
0
void
shell_do(struct cmd_def **defs)
{
  using_history();

  while (1)
    {
      char *line;
      char prompt[256];
      dpl_ino_t cur_ino;

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

      snprintf(prompt, sizeof (prompt), "%s:%s%s> ", ctx->cur_bucket, ctx->delim, cur_ino.key);

      if ((line = readline(prompt)))
        {
          enum shell_error shell_err;
          int ret;

          ret = shell_parse(defs, line, &shell_err);
          if (ret == SHELL_EPARSE)
            {
              fprintf(stderr,
                      "parsing: %s\n", shell_error_str(shell_err));
            }
          else if (ret == SHELL_RETURN)
            {
              return ;
            }
          if (strcmp(line, ""))
            add_history(line);
          free(line);
        }
      else
        {
          fprintf(stderr, "quit\n");
          return ;
        }
    }
}
Beispiel #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;
}
Beispiel #4
0
static dpl_status_t
dpl_mkgen(dpl_ctx_t *ctx,
          char *locator,
          dpl_status_t (*cb)(dpl_ctx_t *, char *, dpl_ino_t, const char *))
{
  char *dir_name = NULL;
  dpl_ino_t parent_ino;
  int ret, ret2;
  char *nlocator = NULL;
  int delim_len = strlen(ctx->delim);
  char *bucket, *path;
  dpl_ino_t cur_ino;

  DPL_TRACE(ctx, DPL_TRACE_VDIR, "mkdir locator=%s", locator);

  nlocator = strdup(locator);
  if (NULL == nlocator)
    {
      ret = DPL_ENOMEM;
      goto end;
    }

  path = index(nlocator, ':');
  if (NULL != path)
    {
      bucket = nlocator;
      *path++ = 0;
    }
  else
    {
      bucket = ctx->cur_bucket;
      path = nlocator;
    }

  cur_ino = dpl_cwd(ctx, bucket);

  ret2 = dpl_namei(ctx, path, bucket, cur_ino, &parent_ino, NULL, NULL);
  if (DPL_SUCCESS != ret2)
    {
      if (DPL_ENOENT == ret2)
        {
          dir_name = dpl_strrstr(path, ctx->delim);
          if (NULL != dir_name)
            {
              *dir_name = 0;
              dir_name += delim_len;

              //fetch parent directory
              ret2 = dpl_namei(ctx, !strcmp(path, "") ? ctx->delim : path, bucket, cur_ino, NULL, &parent_ino, NULL);
              if (DPL_SUCCESS != ret2)
                {
                  DPLERR(0, "dst parent dir resolve failed %s: %s\n", path, dpl_status_str(ret2));
                  ret = ret2;
                  goto end;
                }
            }
          else
            {
              parent_ino = cur_ino;
              dir_name = path;
            }
        }
      else
        {
          DPLERR(0, "path resolve failed %s: %s (%d)\n", path, dpl_status_str(ret2), ret2);
          ret = ret2;
          goto end;
        }
    }
  else
    {
      ret = DPL_EEXIST;
      goto end;
    }

  ret2 = cb(ctx, bucket, parent_ino, dir_name);
  if (0 != ret2)
    {
      DPLERR(0, "mkdir failed");
      ret = ret2;
      goto end;
    }

  ret = DPL_SUCCESS;

 end:

  if (NULL != nlocator)
    free(nlocator);

  return ret;
}
Beispiel #5
0
dpl_status_t
dpl_chdir(dpl_ctx_t *ctx,
          char *locator)
{
  int ret, ret2;
  dpl_ino_t obj_ino;
  dpl_ftype_t obj_type;
  char *nlocator = NULL;
  dpl_ino_t cur_ino;
  char *nbucket;
  char *path, *bucket;

  DPL_TRACE(ctx, DPL_TRACE_VDIR, "chdir locator=%s", locator);

  nlocator = strdup(locator);
  if (NULL == nlocator)
    {
      ret = DPL_ENOMEM;
      goto end;
    }

  path = index(nlocator, ':');
  if (NULL != path)
    {
      bucket = nlocator;
      *path++ = 0;
    }
  else
    {
      bucket = ctx->cur_bucket;
      path = nlocator;
    }

  cur_ino = dpl_cwd(ctx, bucket);

  ret2 = dpl_namei(ctx, path, bucket, cur_ino, NULL, &obj_ino, &obj_type);
  if (0 != ret2)
    {
      DPLERR(0, "path resolve failed %s: %s (%d)", path, dpl_status_str(ret2), ret2);
      ret = ret2;
      goto end;
    }

  if (DPL_FTYPE_DIR != obj_type)
    {
      DPLERR(0, "not a directory");
      ret = DPL_EINVAL;
      goto end;
    }

  if (strcmp(bucket, ctx->cur_bucket))
    {
      nbucket = strdup(bucket);
      if (NULL == nbucket)
        {
          ret = DPL_ENOMEM;
          goto end;
        }
      free(ctx->cur_bucket);
      ctx->cur_bucket = nbucket;
    }

  ret2 = dpl_dict_add(ctx->cwds, ctx->cur_bucket, obj_ino.key, 0);
  if (DPL_SUCCESS != ret2)
    {
      ret = ret2;
      goto end;
    }

  ret = DPL_SUCCESS;

 end:

  if (NULL != nlocator)
    free(nlocator);

  return ret;
}
Beispiel #6
0
/**
 * open a directory
 *
 * @param ctx
 * @param locator [bucket:]path
 * @param dir_hdlp
 *
 * @return
 */
dpl_status_t
dpl_opendir(dpl_ctx_t *ctx,
            char *locator,
            void **dir_hdlp)
{
  int ret, ret2;
  dpl_ino_t obj_ino;
  dpl_ftype_t obj_type;
  char *nlocator = NULL;
  char *bucket, *path;
  dpl_ino_t cur_ino;

  DPL_TRACE(ctx, DPL_TRACE_VDIR, "opendir locator=%s", locator);

  nlocator = strdup(locator);
  if (NULL == nlocator)
    {
      ret = DPL_ENOMEM;
      goto end;
    }

  path = index(nlocator, ':');
  if (NULL != path)
    {
      bucket = nlocator;
      *path++ = 0;
    }
  else
    {
      bucket = ctx->cur_bucket;
      path = nlocator;
    }

  cur_ino = dpl_cwd(ctx, bucket);

  ret2 = dpl_namei(ctx, path, bucket, cur_ino, NULL, &obj_ino, &obj_type);
  if (0 != ret2)
    {
      DPLERR(0, "path resolve failed %s", path);
      ret = ret2;
      goto end;
    }

  if (DPL_FTYPE_REG == obj_type)
    {
      DPLERR(0, "cannot list a file");
      ret = DPL_EINVAL;
      goto end;
    }

  ret2 = dpl_vdir_opendir(ctx, bucket, obj_ino, dir_hdlp);
  if (DPL_SUCCESS != ret2)
    {
      DPLERR(0, "unable to open %s:%s", bucket, obj_ino.key);
      ret = ret2;
      goto end;
    }

  ret = DPL_SUCCESS;

 end:

  if (NULL != nlocator)
    free(nlocator);

  return ret;
}
Beispiel #7
0
dpl_status_t
dpl_rmdir(dpl_ctx_t *ctx,
          char *locator)
{
  int ret, ret2;
  char *dir_name = NULL;
  dpl_ino_t parent_ino;
  int delim_len = strlen(ctx->delim);
  char *nlocator = NULL;
  char *bucket, *path;
  dpl_ino_t cur_ino;

  DPL_TRACE(ctx, DPL_TRACE_VDIR, "rmdir locator=%s", locator);

  nlocator = strdup(locator);
  if (NULL == nlocator)
    {
      ret = DPL_ENOMEM;
      goto end;
    }

  path = index(nlocator, ':');
  if (NULL != path)
    {
      bucket = nlocator;
      *path++ = 0;
    }
  else
    {
      bucket = ctx->cur_bucket;
      path = nlocator;
    }

  cur_ino = dpl_cwd(ctx, bucket);

  dir_name = dpl_strrstr(path, ctx->delim);
  if (NULL != dir_name)
    dir_name += delim_len;
  else
    dir_name = path;

  ret2 = dpl_namei(ctx, path, bucket, cur_ino, &parent_ino, NULL, NULL);
  if (DPL_SUCCESS != ret2)
    {
      DPLERR(0, "path resolved failed");
      ret = ret2;
      goto end;
    }

  ret2 = dpl_vdir_rmdir(ctx, bucket, parent_ino, dir_name);
  if (DPL_SUCCESS != ret2)
    {
      DPLERR(0, "rmdir failed");
      ret = ret2;
      goto end;
    }

  ret = DPL_SUCCESS;

 end:

  if (NULL != nlocator)
    free(nlocator);

  return ret;
}