Itai-Nelken / aptpac

A simple wrapper for 'pacman' with a syntax similar to 'apt' to help people transitioning to Arch and Arch based distributions like Manjaro.
https://itai-nelken.github.io/aptpac/
MIT License
27 stars 5 forks source link

Fix the error on initial run on new installation #27

Closed saeziae closed 2 years ago

saeziae commented 2 years ago

On a new installation, the programme will attempt to read the config file which yet does not exisit, causing the error config_load: fopen: No such file or directory.

saeziae commented 2 years ago

Recently I thought of a new solution, as reading an empty config file does not affect the program to run, we can just remove the exit(-1) then give an empty string to config when the file pointer is NULL.

Itai-Nelken commented 2 years ago

Honestly the configuration system is really bad. I would rather keep it this way for now and rewrite it later on a better way. Also I iust thought of a bug with my suggestion: a new configuration file is created, but not initialized.

Itai-Nelken commented 2 years ago

Something like this:

file=fopen(conf_file, "r");
if(file==NULL) {
    fprintf(stderr, "config_load(): configuration file not found, attempting to create a new one.\n");
    // reset to default configuration.
    config->version = CONF_FILE_VERSION;
    config->learn = 0;
    config_save(config);
    return;
}
Itai-Nelken commented 2 years ago

Once this pr is merged I'll release v3.1 and then once I have time I'll rewrite the C version as I wrote it when I was learning C so the code is pretty bad.

saeziae commented 2 years ago

Honestly the configuration system is really bad. I would rather keep it this way for now and rewrite it later on a better way. Also I just thought of a bug with my suggestion: a new configuration file is created, but not initialized.

However reading an empty file does not affect the program. And I think it's okay to assume the learning mode is off if there is not a config file, like:

file=fopen(conf_file, "r");
if(file==NULL) {
    // fprintf(stderr, "config_load(): configuration file not found, attempting to create a new one.\n");
    config->version = CONF_FILE_VERSION;
    config->learn = 0;
    // config_save(config);
    return;
}
Itai-Nelken commented 2 years ago

Honestly the configuration system is really bad. I would rather keep it this way for now and rewrite it later on a better way. Also I just thought of a bug with my suggestion: a new configuration file is created, but not initialized.

However reading an empty file does not affect the program. And I think it's okay to assume the learning mode is off if there is not a config file, like:

file=fopen(conf_file, "r");
if(file==NULL) {
  // fprintf(stderr, "config_load(): configuration file not found, attempting to create a new one.\n");
  config->version = CONF_FILE_VERSION;
  config->learn = 0;
  // config_save(config);
  return;
}

You are right, that is a better idea.

Itai-Nelken commented 2 years ago

I improved the help message and the comment.

Thanks a lot for the fix!