mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-09 13:29:59 -05:00
database: pick old database file from any arch
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/425>
This commit is contained in:
parent
4ca8997aa0
commit
7115023c51
5 changed files with 42 additions and 54 deletions
|
|
@ -59,14 +59,6 @@ void pa_datum_free(pa_datum *d) {
|
||||||
pa_zero(d);
|
pa_zero(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* pa_database_get_arch_suffix(void) {
|
|
||||||
/* We include the host identifier in the file name because gdbm
|
|
||||||
* files are CPU dependent, and we don't want things to go wrong
|
|
||||||
* if we are on a multiarch system. */
|
|
||||||
|
|
||||||
return CANONICAL_HOST;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* pa_database_get_filename_suffix(void) {
|
const char* pa_database_get_filename_suffix(void) {
|
||||||
return ".gdbm";
|
return ".gdbm";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -222,11 +222,6 @@ static int fill_data(simple_data *db, FILE *f) {
|
||||||
return pa_hashmap_size(db->map);
|
return pa_hashmap_size(db->map);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* pa_database_get_arch_suffix(void) {
|
|
||||||
/* Simple database binary file format is CPU dependent. */
|
|
||||||
return CANONICAL_HOST;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* pa_database_get_filename_suffix(void) {
|
const char* pa_database_get_filename_suffix(void) {
|
||||||
return ".simple";
|
return ".simple";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,11 +97,6 @@ finish:
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* pa_database_get_arch_suffix(void) {
|
|
||||||
/* TDB binary file format is not dependent on system architecture */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* pa_database_get_filename_suffix(void) {
|
const char* pa_database_get_filename_suffix(void) {
|
||||||
return ".tdb";
|
return ".tdb";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@
|
||||||
|
|
||||||
pa_database* pa_database_open(const char *path, const char *fn, bool prependmid, bool for_write) {
|
pa_database* pa_database_open(const char *path, const char *fn, bool prependmid, bool for_write) {
|
||||||
|
|
||||||
const char *arch_suffix = pa_database_get_arch_suffix();
|
|
||||||
const char *filename_suffix = pa_database_get_filename_suffix();
|
const char *filename_suffix = pa_database_get_filename_suffix();
|
||||||
|
|
||||||
char *machine_id = NULL, *filename_prefix, *full_path;
|
char *machine_id = NULL, *filename_prefix, *full_path;
|
||||||
|
|
@ -43,7 +42,6 @@ pa_database* pa_database_open(const char *path, const char *fn, bool prependmid,
|
||||||
|
|
||||||
pa_database *f;
|
pa_database *f;
|
||||||
|
|
||||||
pa_assert(!arch_suffix || arch_suffix[0]);
|
|
||||||
pa_assert(filename_suffix && filename_suffix[0]);
|
pa_assert(filename_suffix && filename_suffix[0]);
|
||||||
|
|
||||||
if (prependmid && !(machine_id = pa_machine_id())) {
|
if (prependmid && !(machine_id = pa_machine_id())) {
|
||||||
|
|
@ -56,41 +54,38 @@ pa_database* pa_database_open(const char *path, const char *fn, bool prependmid,
|
||||||
else
|
else
|
||||||
filename_prefix = pa_xstrdup(fn);
|
filename_prefix = pa_xstrdup(fn);
|
||||||
|
|
||||||
if (arch_suffix) {
|
/* Search for existing database directory entry name matching architecture suffix and filename suffix. */
|
||||||
/* Search for existing database directory entry name matching architecture suffix and filename suffix. */
|
database_dir = opendir(path);
|
||||||
database_dir = opendir(path);
|
|
||||||
|
|
||||||
if (database_dir) {
|
if (database_dir) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
de = readdir(database_dir);
|
de = readdir(database_dir);
|
||||||
if (!de) {
|
if (!de) {
|
||||||
if (errno) {
|
if (errno) {
|
||||||
pa_log_warn("Unable to search for compatible database file, readdir() failed: %s", pa_cstrerror(errno));
|
pa_log_warn("Unable to search for existing database file, readdir() failed: %s", pa_cstrerror(errno));
|
||||||
/* can continue as if there is no matching database file candidate */
|
/* can continue as if there is no matching database file candidate */
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_startswith(de->d_name, filename_prefix)
|
break;
|
||||||
&& de->d_name[strlen(filename_prefix)] == '.'
|
|
||||||
&& pa_startswith(de->d_name + strlen(filename_prefix) + 1, arch_suffix)
|
|
||||||
&& pa_endswith(de->d_name + strlen(filename_prefix) + 1 + strlen(arch_suffix), filename_suffix)) {
|
|
||||||
|
|
||||||
/* candidate filename found, replace filename_prefix with this one */
|
|
||||||
|
|
||||||
pa_log_debug("Found compatible database file '%s/%s', using it", path, de->d_name);
|
|
||||||
pa_xfree(filename_prefix);
|
|
||||||
filename_prefix = pa_xstrndup(de->d_name, strlen(de->d_name) - strlen(filename_suffix));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(database_dir);
|
if (pa_startswith(de->d_name, filename_prefix)
|
||||||
} else {
|
&& de->d_name[strlen(filename_prefix)] == '.'
|
||||||
pa_log_warn("Unable to search for compatible database file, failed to open directory %s: %s", path, pa_cstrerror(errno));
|
&& pa_endswith(de->d_name + strlen(filename_prefix) + 1, filename_suffix)) {
|
||||||
|
|
||||||
|
/* candidate filename found, replace filename_prefix with this one */
|
||||||
|
|
||||||
|
pa_log_debug("Found existing database file '%s/%s', using it", path, de->d_name);
|
||||||
|
pa_xfree(filename_prefix);
|
||||||
|
filename_prefix = pa_xstrndup(de->d_name, strlen(de->d_name) - strlen(filename_suffix));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closedir(database_dir);
|
||||||
|
} else {
|
||||||
|
pa_log_warn("Unable to search for existing database file, failed to open directory %s: %s", path, pa_cstrerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
full_path = pa_sprintf_malloc("%s" PA_PATH_SEP "%s%s", path, filename_prefix, filename_suffix);
|
full_path = pa_sprintf_malloc("%s" PA_PATH_SEP "%s%s", path, filename_prefix, filename_suffix);
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,25 @@ typedef struct pa_datum {
|
||||||
|
|
||||||
void pa_datum_free(pa_datum *d);
|
void pa_datum_free(pa_datum *d);
|
||||||
|
|
||||||
/* Database implementation; returns non-empty system architecture name string if database file format depends on system architecture, or NULL otherwise. */
|
|
||||||
const char* pa_database_get_arch_suffix(void);
|
|
||||||
/* Database implementation; returns non-empty database filename extension string */
|
/* Database implementation; returns non-empty database filename extension string */
|
||||||
const char* pa_database_get_filename_suffix(void);
|
const char* pa_database_get_filename_suffix(void);
|
||||||
|
|
||||||
/* This will attempt opening database file matching compiled CANONICAL_HOST implementation architecture name prefix,
|
/* Opens a database file. The file is loaded from the directory indicated by
|
||||||
* or new database file will be created and opened with implementation architecture name suffix if required.
|
* path. The file name is constructed by using fn as the base and then adding
|
||||||
* If prependmid is true, file name is augmented with machine id prefix. */
|
* several parts:
|
||||||
|
* 1) If prependmid is true, the machine id is prepended to the file name.
|
||||||
|
* 2) The database implementation specific suffix is added.
|
||||||
|
* 3) Older versions of PulseAudio in some cases added the CPU architecture
|
||||||
|
* to the file name, which was later deemed unnecessary, but for
|
||||||
|
* compatibility reasons we still need to look for those files, so we scan
|
||||||
|
* the directory for files that match the prefix (possible machine id plus
|
||||||
|
* fn) and the suffix, and if any matches are found, we use the first one.
|
||||||
|
*
|
||||||
|
* When no existing file is found, we create a new file for the database
|
||||||
|
* (without the CPU architecture part in the name).
|
||||||
|
*
|
||||||
|
* For a read-only database, set for_write to false. */
|
||||||
|
|
||||||
pa_database* pa_database_open(const char *path, const char *fn, bool prependmid, bool for_write);
|
pa_database* pa_database_open(const char *path, const char *fn, bool prependmid, bool for_write);
|
||||||
|
|
||||||
/* Database implementation; opens specified database file using provided path. */
|
/* Database implementation; opens specified database file using provided path. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue