1
0
forked from drath/libratbag

Get the libratbag data dir from the environment variable

And set it for the tests, so we can test with in-tree files.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2017-08-31 14:40:21 +10:00
committed by Benjamin Tissoires
parent 94daeb1444
commit 4037587f74
3 changed files with 16 additions and 5 deletions

View File

@@ -324,11 +324,16 @@ ratbag_device_data_new_for_id(struct ratbag *ratbag, const struct input_id *id)
struct ratbag_device_data *data = NULL;
struct dirent **files;
int n, nfiles;
const char *datadir;
n = scandir(LIBRATBAG_DATA_DIR, &files, filter_device_files, alphasort);
datadir = getenv("LIBRATBAG_DATA_DIR");
if (!datadir)
datadir = LIBRATBAG_DATA_DIR;
n = scandir(datadir, &files, filter_device_files, alphasort);
if (n <= 0) {
log_error(ratbag, "Unable to locate device files in %s: %s\n",
LIBRATBAG_DATA_DIR, n == 0 ? "No files found" : strerror(errno));
datadir, n == 0 ? "No files found" : strerror(errno));
return NULL;
}
@@ -337,7 +342,7 @@ ratbag_device_data_new_for_id(struct ratbag *ratbag, const struct input_id *id)
_cleanup_(freep) char *file = NULL;
int rc;
rc = xasprintf(&file, "%s/%s", LIBRATBAG_DATA_DIR, files[n]->d_name);
rc = xasprintf(&file, "%s/%s", datadir, files[n]->d_name);
if (rc == -1)
goto out;
if (file_data_matches(ratbag, file, id, &data))