STAILQ_HEAD(mountpoints, mountpoint) mountpoints;
int destroy_on_free;
+
+ struct pakfire_distro {
+ char pretty_name[256];
+ char name[64];
+ char id[32];
+ char version[32];
+ char version_id[32];
+ } distro;
};
static const struct pakfire_mountpoint {
return 0;
}
+static int pakfire_read_os_release(Pakfire pakfire) {
+ int r = 0;
+
+ char* path = pakfire_make_path(pakfire, "/etc/os-release");
+ if (!path)
+ return ENOMEM;
+
+ FILE* f = fopen(path, "r");
+ if (!f) {
+ ERROR(pakfire, "Could not open %s: %s\n", path, strerror(errno));
+ r = -1;
+ goto ERROR;
+ }
+
+ char* line = NULL;
+ size_t l = 0;
+
+ while (1) {
+ ssize_t bytes_read = getline(&line, &l, f);
+ if (bytes_read < 0)
+ break;
+
+ // Remove trailing newline
+ pakfire_remove_trailing_newline(line);
+
+ // Find =
+ char* delim = strchr(line, '=');
+ if (!delim)
+ continue;
+
+ // Replace = by NULL
+ *delim = '\0';
+
+ // Set key and val to the start of the strings
+ char* key = line;
+ char* val = delim + 1;
+
+ // Unquote val
+ val = pakfire_unquote_in_place(val);
+
+ if (strcmp(key, "PRETTY_NAME") == 0)
+ r = pakfire_string_set(pakfire->distro.pretty_name, val);
+ else if (strcmp(key, "NAME") == 0)
+ r = pakfire_string_set(pakfire->distro.name, val);
+ else if (strcmp(key, "ID") == 0)
+ r = pakfire_string_set(pakfire->distro.id, val);
+ else if (strcmp(key, "VERSION") == 0)
+ r = pakfire_string_set(pakfire->distro.version, val);
+ else if (strcmp(key, "VERSION_ID") == 0)
+ r = pakfire_string_set(pakfire->distro.version_id, val);
+ else
+ continue;
+
+ // Catch any errors
+ if (r < 0)
+ goto ERROR;
+ }
+
+ // Success
+ r = 0;
+
+ERROR:
+ if (f)
+ fclose(f);
+ if (line)
+ free(line);
+ free(path);
+
+ return r;
+}
+
PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char* arch) {
char tempdir[PATH_MAX] = PAKFIRE_PRIVATE_DIR "/tmp/XXXXXX";
int r = 1;
if (env)
pakfire_log_set_priority(p, log_priority(env));
+ // Read /etc/os-release
+ r = pakfire_read_os_release(p);
+ if (r)
+ goto ERROR;
+
DEBUG(p, "Pakfire initialized at %p\n", p);
- DEBUG(p, " arch = %s\n", pakfire_get_arch(p));
- DEBUG(p, " path = %s\n", pakfire_get_path(p));
+ DEBUG(p, " arch = %s\n", pakfire_get_arch(p));
+ DEBUG(p, " path = %s\n", pakfire_get_path(p));
+ DEBUG(p, " distro = %s\n", p->distro.pretty_name);
// Perform some safety checks
r = pakfire_safety_checks(p);
return !strcmp(s + strlen(s) - strlen(suffix), suffix);
}
+char* pakfire_unquote_in_place(char* s) {
+ if (!s || !*s)
+ return s;
+
+ // Is the first character a quote?
+ if (*s != '"')
+ return s;
+
+ // Find the end of value
+ size_t l = strlen(s);
+ if (!l)
+ return s;
+
+ // Is the last character a quote?
+ if (s[l - 1] != '"')
+ return s;
+
+ // The string seems to be in quotes; remove them
+ s[l - 1] = '\0';
+ s++;
+
+ return s;
+}
+
PAKFIRE_EXPORT int pakfire_string_partition(
const char* s, const char* delim, char** s1, char** s2) {
char* p = strstr(s, delim);