Esempio n. 1
0
gboolean
ot_enable_tombstone_commits (OstreeRepo *repo, GError **error)
{
  gboolean tombstone_commits = FALSE;
  GKeyFile *config = ostree_repo_get_config (repo);

  tombstone_commits = g_key_file_get_boolean (config, "core", "tombstone-commits", NULL);
  /* tombstone_commits is FALSE either if it is not found or it is really set to FALSE in the config file.  */
  if (!tombstone_commits)
    {
      g_key_file_set_boolean (config, "core", "tombstone-commits", TRUE);
      if (!ostree_repo_write_config (repo, config, error))
        return FALSE;
    }

  return TRUE;
}
Esempio n. 2
0
gboolean
ostree_builtin_config (int argc, char **argv, GCancellable *cancellable, GError **error)
{
  g_autoptr(GOptionContext) context = NULL;
  glnx_unref_object OstreeRepo *repo = NULL;
  gboolean ret = FALSE;
  const char *op;
  const char *section_key;
  const char *value;
  g_autofree char *section = NULL;
  g_autofree char *key = NULL;
  GKeyFile *config = NULL;

  context = g_option_context_new ("- Change configuration settings");

  if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
    goto out;

  if (argc < 2)
    {
      ot_util_usage_error (context, "OPERATION must be specified", error);
      goto out;
    }

  op = argv[1];

  if (!strcmp (op, "set"))
    {
      if (argc < 4)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "KEY and VALUE must be specified");
          goto out;
        }

      section_key = argv[2];
      value = argv[3];

      if (!split_key_string (section_key, &section, &key, error))
        goto out;

      config = ostree_repo_copy_config (repo);
      g_key_file_set_string (config, section, key, value);

      if (!ostree_repo_write_config (repo, config, error))
        goto out;
    }
  else if (!strcmp (op, "get"))
    {
      GKeyFile *readonly_config = NULL;
      g_autofree char *value = NULL;
      if (argc < 3)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "KEY must be specified");
          goto out;
        }

      section_key = argv[2];

      if (!split_key_string (section_key, &section, &key, error))
        goto out;

      readonly_config = ostree_repo_get_config (repo);
      value = g_key_file_get_string (readonly_config, section, key, error);
      if (value == NULL)
        goto out;

      g_print ("%s\n", value);
    }
  else
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Unknown operation %s", op);
      goto out;
    }
  
  ret = TRUE;
 out:
  if (config)
    g_key_file_free (config);
  return ret;
}
Esempio n. 3
0
gboolean
ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
{
  GOptionContext *context;
  gboolean ret = FALSE;
  const char *op;
  gs_free char *key = NULL;
  guint i;
  GKeyFile *config = NULL;
  const char *remote_name;

  context = g_option_context_new ("OPERATION NAME [args] - Control remote repository configuration");
  g_option_context_add_main_entries (context, options, NULL);

  if (!g_option_context_parse (context, &argc, &argv, error))
    goto out;

  if (argc < 3)
    {
      if (argc == 1)
        usage_error (context, "OPERATION must be specified", error);
      else
        usage_error (context, "NAME must be specified", error);

      goto out;
    }

  op = argv[1];
  remote_name = argv[2];
  key = g_strdup_printf ("remote \"%s\"", remote_name);

  config = ostree_repo_copy_config (repo);

  if (!strcmp (op, "add"))
    {
      const char *url = argv[3];
      gs_unref_object GFile *etc_ostree_remotes_d = g_file_new_for_path (SYSCONFDIR "/ostree/remotes.d");
      gs_free char *target_name = NULL;
      gs_unref_object GFile *target_conf = NULL;
      local_cleanup_keyfile GKeyFile *new_keyfile = NULL;
      GKeyFile *target_keyfile = NULL;
      gs_unref_ptrarray GPtrArray *branches = NULL;

      if (strchr (remote_name, '/') != NULL)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Invalid character '/' in remote name: %s",
                       remote_name);
          goto out;
        }
      
      if (argc < 4)
        {
          usage_error (context, "URL must be specified", error);
          goto out;
        }

      branches = g_ptr_array_new ();
      for (i = 4; i < argc; i++)
        g_ptr_array_add (branches, argv[i]);

      if (ostree_repo_is_system (repo))
        {
          new_keyfile = g_key_file_new ();

          target_keyfile = new_keyfile;

          target_name = g_strconcat (remote_name, ".conf", NULL);
          target_conf = g_file_get_child (etc_ostree_remotes_d, target_name);
          
          if (g_file_query_exists (target_conf, NULL))
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Remote configuration already exists: %s",
                           gs_file_get_path_cached (target_conf));
              goto out;
            }
        }
      else
        {
          target_keyfile = config;
        }

      if (!add_remote_to_keyfile (target_keyfile, key, url, branches, error))
        goto out;

      /* For the system repository, write to /etc/ostree/remotes.d */
      if (ostree_repo_is_system (repo))
        {
          gsize len;
          gs_free char *data = g_key_file_to_data (target_keyfile, &len, error);
          if (!g_file_replace_contents (target_conf, data, len,
                                        NULL, FALSE, 0, NULL,
                                        cancellable, error))
            goto out;
        }
      else
        {
          if (!ostree_repo_write_config (repo, config, error))
            goto out;
        }
    }
  else if (!strcmp (op, "show-url"))
    {
      gs_free char *url = NULL;

      url = g_key_file_get_string (config, key, "url", error);
      if (url == NULL)
        goto out;

      g_print ("%s\n", url);
    }
  else
    {
      usage_error (context, "Unknown operation", error);
      goto out;
    }
 
  ret = TRUE;
 out:
  if (context)
    g_option_context_free (context);
  if (config)
    g_key_file_free (config);
  return ret;
}
Esempio n. 4
0
gboolean
ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{
  g_autoptr(GOptionContext) context = NULL;
  g_autoptr(OstreeRepo) repo = NULL;
  gboolean ret = FALSE;
  const char *op;
  const char *section_key;
  const char *value;
  g_autofree char *section = NULL;
  g_autofree char *key = NULL;
  GKeyFile *config = NULL;

  context = g_option_context_new ("(get KEY|set KEY VALUE)");

  if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error))
    goto out;

  if (argc < 2)
    {
      ot_util_usage_error (context, "OPERATION must be specified", error);
      goto out;
    }

  op = argv[1];

  if (!strcmp (op, "set"))
    {
      if (opt_group)
        {
          if (argc < 4)
            {
                g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                             "GROUP name, KEY and VALUE must be specified");
                goto out;
            }
          section = g_strdup(opt_group);
          key = g_strdup(argv[2]);
          value = argv[3];
        }
      else
        {
          if (argc < 4)
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "KEY and VALUE must be specified");
              goto out;
            }
          section_key = argv[2];
          value = argv[3];
          if(!split_key_string (section_key, &section, &key, error))
            goto out;
        }

      config = ostree_repo_copy_config (repo);
      g_key_file_set_string (config, section, key, value);

      if (!ostree_repo_write_config (repo, config, error))
        goto out;
    }
  else if (!strcmp (op, "get"))
    {
      GKeyFile *readonly_config = NULL;
      g_autofree char *value = NULL;
      if (opt_group)
        {
          if (argc < 3)
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Group name and key must be specified");
              goto out;
            }
          section = g_strdup(opt_group);
          key = g_strdup(argv[2]);
        }
      else
        {
          if(argc < 3)
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "KEY must be specified");
              goto out;
            }
          section_key = argv[2];
          if (!split_key_string (section_key, &section, &key, error))
            goto out;
        }

      readonly_config = ostree_repo_get_config (repo);
      value = g_key_file_get_string (readonly_config, section, key, error);
      if (value == NULL)
        goto out;

      g_print ("%s\n", value);
    }
  else
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Unknown operation %s", op);
      goto out;
    }

  ret = TRUE;
 out:
  if (config)
    g_key_file_free (config);
  return ret;
}
Esempio n. 5
0
gboolean
ostree_builtin_remote (int argc, char **argv, GFile *repo_path, GError **error)
{
  GOptionContext *context;
  gboolean ret = FALSE;
  const char *op;
  guint i;
  ot_lobj OstreeRepo *repo = NULL;
  ot_lptrarray GPtrArray *branches = NULL;
  GKeyFile *config = NULL;

  context = g_option_context_new ("OPERATION [args] - Control remote repository configuration");
  g_option_context_add_main_entries (context, options, NULL);

  if (!g_option_context_parse (context, &argc, &argv, error))
    goto out;

  repo = ostree_repo_new (repo_path);
  if (!ostree_repo_check (repo, error))
    goto out;

  if (argc < 2)
    {
      usage_error (context, "OPERATION must be specified", error);
      goto out;
    }

  op = argv[1];

  config = ostree_repo_copy_config (repo);

  if (!strcmp (op, "add"))
    {
      char *key;
      if (argc < 4)
        {
          usage_error (context, "NAME and URL must be specified", error);
          goto out;
        }

      branches = g_ptr_array_new ();
      for (i = 4; i < argc; i++)
        g_ptr_array_add (branches, argv[i]);

      key = g_strdup_printf ("remote \"%s\"", argv[2]);
      g_key_file_set_string (config, key, "url", argv[3]);
      if (branches->len > 0)
        g_key_file_set_string_list (config, key, "branches",
                                    (const char *const *)branches->pdata,
                                    branches->len);
      g_free (key);
    }
  else
    {
      usage_error (context, "Unknown operation", error);
      goto out;
    }

  if (!ostree_repo_write_config (repo, config, error))
    goto out;
 
  ret = TRUE;
 out:
  if (context)
    g_option_context_free (context);
  if (config)
    g_key_file_free (config);
  return ret;
}