/**
 * backend_initialize:
 * This should only be run once per backend load, i.e. not every transaction
 */
static void
backend_initialize (PkBackend *backend)
{
	_config = slapt_read_rc_config(_config_file);
	if (_config == NULL)
	    _config = slapt_init_config();

	_backend = backend;
	if (_backend != NULL)
	    _config->progress_cb = &backend_progress_callback;

	chdir(_config->working_dir);
}
Example #2
0
/**
 * backend_initialize:
 * This should only be run once per backend load, i.e. not every transaction
 */
static void
backend_initialize (PkBackend *backend)
{
	struct category_map *catgroup;

	_config = slapt_read_rc_config(_config_file);
	if (_config == NULL)
	    _config = slapt_init_config();

	_cathash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
	for (catgroup = CATGROUP; catgroup->category != NULL; catgroup++) {
	     g_hash_table_insert(_cathash,
	         (gpointer) catgroup->category, (gpointer) catgroup->group);
	}

	_backend = backend;
	if (_backend != NULL)
	    _config->progress_cb = &backend_progress_callback;

	chdir(_config->working_dir);
}
Example #3
0
slapt_rc_config *slapt_read_rc_config(const char *file_name)
{
  FILE *rc = NULL;
  char *getline_buffer = NULL;
  size_t gb_length = 0;
  ssize_t g_size;
  slapt_rc_config *global_config = NULL;

  rc = slapt_open_file(file_name,"r");
  if ( rc == NULL )
    return NULL;

  global_config = slapt_init_config();

  while ( (g_size = getline(&getline_buffer,&gb_length,rc) ) != EOF ) {
    char *token_ptr = NULL;
    getline_buffer[g_size - 1] = '\0';

    /* check to see if it has our key and value separated by our token */
    /* and extract them */
    if ( (strchr(getline_buffer,'#') != NULL) && (strstr(getline_buffer, SLAPT_DISABLED_SOURCE_TOKEN) == NULL) )
      continue;


    if ( (token_ptr = strstr(getline_buffer,SLAPT_SOURCE_TOKEN)) != NULL ) {
      /* SOURCE URL */

      if ( strlen(token_ptr) > strlen(SLAPT_SOURCE_TOKEN) ) {
        slapt_source_t *s = slapt_init_source(token_ptr + strlen(SLAPT_SOURCE_TOKEN));
        if (s != NULL) {
          slapt_add_source(global_config->sources,s);
          if (s->priority != SLAPT_PRIORITY_DEFAULT) {
            global_config->use_priority = SLAPT_TRUE;
          }
        }
      }

    } else if ( (token_ptr = strstr(getline_buffer,SLAPT_DISABLED_SOURCE_TOKEN)) != NULL ) {
      /* DISABLED SOURCE */

      if (strlen(token_ptr) > strlen(SLAPT_DISABLED_SOURCE_TOKEN) ) {
        slapt_source_t *s = slapt_init_source(token_ptr + strlen(SLAPT_DISABLED_SOURCE_TOKEN));
        if (s != NULL) {
          s->disabled = SLAPT_TRUE;
          slapt_add_source(global_config->sources,s);
        }
      }

    } else if ( (token_ptr = strstr(getline_buffer,SLAPT_WORKINGDIR_TOKEN)) != NULL ) {
      /* WORKING DIR */

      if ( strlen(token_ptr) > strlen(SLAPT_WORKINGDIR_TOKEN) ) {
        strncpy(
          global_config->working_dir,
          token_ptr + strlen(SLAPT_WORKINGDIR_TOKEN),
          (strlen(token_ptr) - strlen(SLAPT_WORKINGDIR_TOKEN))
        );
        global_config->working_dir[
          (strlen(token_ptr) - strlen(SLAPT_WORKINGDIR_TOKEN))
        ] = '\0';
      }

    } else if ( (token_ptr = strstr(getline_buffer,SLAPT_EXCLUDE_TOKEN)) != NULL ) {
       /* exclude list */
      slapt_free_list(global_config->exclude_list);
      global_config->exclude_list = parse_exclude(token_ptr);
    }

  }

  fclose(rc);

  if ( getline_buffer )
    free(getline_buffer);

  if ( strcmp(global_config->working_dir,"") == 0 ) {
    fprintf(stderr,gettext("WORKINGDIR directive not set within %s.\n"),
            file_name);
    return NULL;
  }
  if ( global_config->sources->count == 0 ) {
    fprintf(stderr,gettext("SOURCE directive not set within %s.\n"),file_name);
    return NULL;
  }

  return global_config;
}