Exemple #1
0
int main(int ac, char* av[])
{
  gc_error_free GError *local_err = NULL;

  tool_init(&ac, &av, "- create directories at mega.nz", entries);

  if (ac < 2)
  {
    g_printerr("ERROR: No directories specified!\n");
    tool_fini(NULL);
    return 1;
  }

  s = tool_start_session();
  if (!s)
  {
    tool_fini(NULL);
    return 1;
  }

  gint i;
  for (i = 1; i < ac; i++)
  {
    gc_free gchar* path = tool_convert_filename(av[i], FALSE);

    if (!mega_session_mkdir(s, path, &local_err))
    {
      g_printerr("ERROR: Can't create directory %s: %s\n", path, local_err->message);
      g_clear_error(&local_err);
    }
  }

  mega_session_save(s, NULL);

  tool_fini(s);
  return 0;
}
Exemple #2
0
static gboolean up_sync_dir(GFile* root, GFile* file, const gchar* remote_path)
{
  GError *local_err = NULL;
  GFileInfo* i;

  if (root != file)
  {
    mega_node* node = mega_session_stat(s, remote_path);
    if (node && node->type == MEGA_NODE_FILE)
    {
      g_printerr("ERROR: File already exists at %s\n", remote_path);
      return FALSE;
    }

    if (!node)
    {
      g_print("D %s\n", remote_path);

      if (!opt_dryrun)
      {
        if (!mega_session_mkdir(s, remote_path, &local_err))
        {
          g_printerr("ERROR: Can't create remote directory %s: %s\n", remote_path, local_err->message);
          g_clear_error(&local_err);
          return FALSE;
        }
      }
    }
  }

  // sync children
  GFileEnumerator* e = g_file_enumerate_children(file, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, &local_err);
  if (!e)
  {
    g_printerr("ERROR: Can't read local directory %s: %s\n", g_file_get_relative_path(root, file), local_err->message);
    g_clear_error(&local_err);
    return FALSE;
  }

  while ((i = g_file_enumerator_next_file(e, NULL, NULL)))
  {
    const gchar* name = g_file_info_get_name(i);
    GFile* child = g_file_get_child(file, name);
    GFileType type = g_file_query_file_type(child, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL);
    gchar* child_remote_path = g_strconcat(remote_path, "/", name, NULL);

    if (type == G_FILE_TYPE_DIRECTORY)
    {
      up_sync_dir(root, child, child_remote_path);
    }
    else if (type == G_FILE_TYPE_REGULAR)
    {
      up_sync_file(root, child, child_remote_path);
    }
    else
    {
      g_printerr("ERROR: Skipping file %s\n", g_file_get_relative_path(root, file));
    }

    g_free(child_remote_path);
    g_object_unref(child);
    g_object_unref(i);
  }

  g_object_unref(e);
  return TRUE;
}