mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Packages: use the official RPM public API
instead of diving into its implementation detail to count installed rpm packages, which support CentOS
This commit is contained in:
+7
-7
@@ -110,12 +110,12 @@ else(XFCONF_FOUND)
|
||||
message(WARNING "Package libxfconf-0 not found. Building without support.")
|
||||
endif(XFCONF_FOUND)
|
||||
|
||||
pkg_check_modules (SQLITE3 sqlite3)
|
||||
if(SQLITE3_FOUND)
|
||||
add_compile_definitions(FF_HAVE_SQLITE3=1)
|
||||
else(SQLITE3_FOUND)
|
||||
message(WARNING "Package sqlite3 not found. Building without support.")
|
||||
endif(SQLITE3_FOUND)
|
||||
pkg_check_modules (RPM rpm)
|
||||
if(RPM_FOUND)
|
||||
add_compile_definitions(FF_HAVE_RPM=1)
|
||||
else(RPM_FOUND)
|
||||
message(WARNING "Package librpm not found. Building without support.")
|
||||
endif(RPM_FOUND)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_BINARY_DIR}
|
||||
@@ -127,7 +127,7 @@ include_directories(
|
||||
${GIO_INCLUDE_DIRS}
|
||||
${DCONF_INCLUDE_DIRS}
|
||||
${XFCONF_INCLUDE_DIRS}
|
||||
${SQLITE3_INCLUDE_DIRS}
|
||||
${RPM_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
link_libraries(
|
||||
|
||||
@@ -21,11 +21,11 @@ The following libraries are used if present:
|
||||
* [`libpci`](https://github.com/pciutils/pciutils): Needed for GPU output. _Should_ be available on every linux system.
|
||||
* [`libX11`](https://gitlab.freedesktop.org/xorg/lib/libx11): Needed for resolution output
|
||||
* [`libXrandr`](https://gitlab.freedesktop.org/xorg/lib/libxrandr): Needed for appending refresh rate to resolution output.
|
||||
* [`libwayland-client`](https://wayland.freedesktop.org/): Better resolution performance in wayland sessions.
|
||||
* [`libwayland-client`](https://wayland.freedesktop.org/): Better resolution performance in wayland sessions.
|
||||
* [`libGIO`](https://developer.gnome.org/gio/unstable/): Needed for values that are only stored GSettings.
|
||||
* [`libDConf`](https://developer.gnome.org/dconf/unstable/): Needed for values that are only stored in DConf + Fallback for GSettings.
|
||||
* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font.
|
||||
* [`libSQLite3`](https://www.sqlite.org/index.html): Needed for rpm package count.
|
||||
* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font.
|
||||
* [`librpm`](http://rpm.org/): Needed for rpm package count.
|
||||
|
||||
## Support status
|
||||
All categories not listed here should work without needing a specific implementation.
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ __fastfetch_completion()
|
||||
"--lib-DConf"
|
||||
"--lib-wayland"
|
||||
"--lib-XFConf"
|
||||
"--lib-SQLite"
|
||||
"--lib-RPM"
|
||||
"--battery-dir"
|
||||
"--load-config"
|
||||
)
|
||||
|
||||
+1
-1
@@ -179,7 +179,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffStrbufInitA(&instance->config.libDConf, 1);
|
||||
ffStrbufInitA(&instance->config.libWayland, 1);
|
||||
ffStrbufInitA(&instance->config.libXFConf, 1);
|
||||
ffStrbufInitA(&instance->config.libSQLite, 1);
|
||||
ffStrbufInitA(&instance->config.librpm, 1);
|
||||
|
||||
ffStrbufInitA(&instance->config.diskFolders, 1);
|
||||
|
||||
|
||||
+42
-72
@@ -290,107 +290,77 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con
|
||||
}
|
||||
#endif //FF_HAVE_XFCONF
|
||||
|
||||
#ifdef FF_HAVE_SQLITE3
|
||||
#include <sqlite3.h>
|
||||
#ifdef FF_HAVE_RPM
|
||||
#include <rpm/rpmlib.h>
|
||||
#include <rpm/rpmts.h>
|
||||
#include <rpm/rpmdb.h>
|
||||
|
||||
typedef struct SQLiteData
|
||||
typedef struct LibrpmData
|
||||
{
|
||||
int(*ffsqlite3_open_v2)(const char* filename, sqlite3** ppDb, int flags, const char* zVfs);
|
||||
int(*ffsqlite3_prepare_v2)(sqlite3* db, const char* zSql, int nByte, sqlite3_stmt** ppStmt, const char** pzTail);
|
||||
int(*ffsqlite3_step)(sqlite3_stmt* pStmt);
|
||||
int(*ffsqlite3_data_count)(sqlite3_stmt* pStmt);
|
||||
int(*ffsqlite3_column_int)(sqlite3_stmt* pStmt, int iCol);
|
||||
int(*ffsqlite3_finalize)(sqlite3_stmt* pStmt);
|
||||
int(*ffsqlite3_close)(sqlite3* db);
|
||||
} SQLiteData;
|
||||
__typeof__(&rpmReadConfigFiles) ffrpmReadConfigFiles;
|
||||
__typeof__(&rpmtsCreate) ffrpmtsCreate;
|
||||
__typeof__(&rpmtsInitIterator) ffrpmtsInitIterator;
|
||||
__typeof__(&rpmdbGetIteratorCount) ffrpmdbGetIteratorCount;
|
||||
__typeof__(&rpmdbFreeIterator) ffrpmdbFreeIterator;
|
||||
__typeof__(&rpmtsFree) ffrpmtsFree;
|
||||
} LibrpmData;
|
||||
|
||||
static inline void closeSQLiteHandles(const SQLiteData* data, sqlite3* db, sqlite3_stmt* stmt)
|
||||
{
|
||||
if(data->ffsqlite3_finalize != NULL && stmt != NULL)
|
||||
data->ffsqlite3_finalize(stmt);
|
||||
uint32_t getRpmPackageCount(LibrpmData* data) {
|
||||
uint32_t count = 0;
|
||||
rpmts ts = NULL;
|
||||
rpmdbMatchIterator mi = NULL;
|
||||
|
||||
if(data->ffsqlite3_close != NULL && db != NULL)
|
||||
data->ffsqlite3_close(db);
|
||||
}
|
||||
if (data->ffrpmReadConfigFiles(NULL, NULL)) goto exit;
|
||||
if (!(ts = data->ffrpmtsCreate())) goto exit;
|
||||
if (!(mi = data->ffrpmtsInitIterator(ts, RPMDBI_LABEL, NULL, 0))) goto exit;
|
||||
count = data->ffrpmdbGetIteratorCount(mi);
|
||||
|
||||
uint32_t getSQLiteColumnCount(const SQLiteData* data, const char* fileName, const char* tableName)
|
||||
{
|
||||
if(data->ffsqlite3_open_v2 == NULL)
|
||||
return 0;
|
||||
|
||||
sqlite3* db;
|
||||
if(data->ffsqlite3_open_v2(fileName, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
|
||||
FFstrbuf sql;
|
||||
ffStrbufInit(&sql);
|
||||
ffStrbufAppendS(&sql, "SELECT COUNT(*) FROM ");
|
||||
ffStrbufAppendS(&sql, tableName);
|
||||
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
int ret = data->ffsqlite3_prepare_v2(db, sql.chars, sql.length + 1, &stmt, NULL);
|
||||
ffStrbufDestroy(&sql);
|
||||
if(ret != SQLITE_OK)
|
||||
{
|
||||
closeSQLiteHandles(data, db, stmt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(data->ffsqlite3_step(stmt) != SQLITE_ROW)
|
||||
{
|
||||
closeSQLiteHandles(data, db, stmt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(data->ffsqlite3_data_count(stmt) < 1)
|
||||
{
|
||||
closeSQLiteHandles(data, db, stmt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = data->ffsqlite3_column_int(stmt, 0);
|
||||
closeSQLiteHandles(data, db, stmt);
|
||||
exit:
|
||||
if (mi) data->ffrpmdbFreeIterator(mi);
|
||||
if (ts) data->ffrpmtsFree(ts);
|
||||
return count;
|
||||
}
|
||||
|
||||
uint32_t ffSettingsGetSQLiteColumnCount(FFinstance* instance, const char* fileName, const char* tableName)
|
||||
uint32_t ffSettingsGetRpmPackageCount(FFinstance* instance)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static bool init = false;
|
||||
|
||||
static SQLiteData data;
|
||||
static LibrpmData data;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
if(init)
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return getSQLiteColumnCount(&data, fileName, tableName);
|
||||
return getRpmPackageCount(&data);
|
||||
}
|
||||
init = true;
|
||||
|
||||
data.ffsqlite3_open_v2 = NULL; //error indicator
|
||||
// As `data` is a static variable, it's already zero inited.
|
||||
// data.ffrpmtsCreate = NULL;
|
||||
|
||||
DynamicLibrary library = FF_LIBRARY_LOAD(instance->config.libSQLite, "libsqlite3.so", mutex, 0);
|
||||
DynamicLibrary library = FF_LIBRARY_LOAD(instance->config.librpm, "librpm.so", mutex, 0);
|
||||
|
||||
data.ffsqlite3_open_v2 = FF_LIBRARY_LOAD_SYMBOL(library, "sqlite3_open_v2", mutex, 0);
|
||||
data.ffsqlite3_prepare_v2 = FF_LIBRARY_LOAD_SYMBOL(library, "sqlite3_prepare_v2", mutex, 0);
|
||||
data.ffsqlite3_step = FF_LIBRARY_LOAD_SYMBOL(library, "sqlite3_step", mutex, 0);
|
||||
data.ffsqlite3_data_count = FF_LIBRARY_LOAD_SYMBOL(library, "sqlite3_data_count", mutex, 0);
|
||||
data.ffsqlite3_column_int = FF_LIBRARY_LOAD_SYMBOL(library, "sqlite3_column_int", mutex, 0);
|
||||
data.ffsqlite3_finalize = FF_LIBRARY_LOAD_SYMBOL(library, "sqlite3_finalize", mutex, 0);
|
||||
data.ffsqlite3_close = FF_LIBRARY_LOAD_SYMBOL(library, "sqlite3_close", mutex, 0);
|
||||
#define FF_LOAD_LIB_SYMBOL(fnName) data.ff ## fnName = FF_LIBRARY_LOAD_SYMBOL(library, #fnName, mutex, 0);
|
||||
FF_LOAD_LIB_SYMBOL(rpmReadConfigFiles);
|
||||
FF_LOAD_LIB_SYMBOL(rpmtsCreate);
|
||||
FF_LOAD_LIB_SYMBOL(rpmtsInitIterator);
|
||||
FF_LOAD_LIB_SYMBOL(rpmdbGetIteratorCount);
|
||||
FF_LOAD_LIB_SYMBOL(rpmdbFreeIterator);
|
||||
FF_LOAD_LIB_SYMBOL(rpmtsFree);
|
||||
#undef FF_LOAD_LIB_SYMBOL
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return getSQLiteColumnCount(&data, fileName, tableName);
|
||||
return getRpmPackageCount(&data);
|
||||
}
|
||||
#else //FF_HAVE_SQLITE3
|
||||
uint32_t ffSettingsGetSQLiteColumnCount(FFinstance* instance, const char* fileName, const char* tableName)
|
||||
#else //FF_HAVE_RPM
|
||||
uint32_t ffSettingsGetRpmPackageCount(FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance, fileName, tableName);
|
||||
FF_UNUSED(instance);
|
||||
return 0;
|
||||
}
|
||||
#endif //FF_HAVE_SQLITE3
|
||||
#endif //FF_HAVE_RPM
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <sys/system_properties.h>
|
||||
|
||||
+1
-1
@@ -165,4 +165,4 @@
|
||||
#--lib-DConf /usr/lib/libdconf.so
|
||||
#--lib-wayland /usr/lib/libwayland-client.so
|
||||
#--lib-XFConf /usr/lib/libxfconf-0.so
|
||||
#--lib-SQLite /usr/lib/libsqlite3.so
|
||||
#--lib-rpm /usr/lib/librpm.so
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ Library options: Set the path of a library to load
|
||||
--lib-DConf <path>
|
||||
--lib-wayland <path>
|
||||
--lib-XFConf <path>
|
||||
--lib-SQLite <path>
|
||||
--lib-RPM <path>
|
||||
|
||||
Module specific options:
|
||||
--disk-folders <folders>: A colon separated list of folder paths for the disk output. Default is "/:/home"
|
||||
|
||||
+4
-4
@@ -364,8 +364,8 @@ static inline void listSupportedFeatures()
|
||||
#ifdef FF_HAVE_XFCONF
|
||||
"xfconf\n"
|
||||
#endif
|
||||
#ifdef FF_HAVE_SQLITE3
|
||||
"sqlite3\n"
|
||||
#ifdef FF_HAVE_RPM
|
||||
"librpm\n"
|
||||
#endif
|
||||
""
|
||||
, stdout);
|
||||
@@ -745,8 +745,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
optionParseString(key, value, &instance->config.libWayland);
|
||||
else if(strcasecmp(key, "--lib-XFConf") == 0)
|
||||
optionParseString(key, value, &instance->config.libXFConf);
|
||||
else if(strcasecmp(key, "--lib-SQLite") == 0)
|
||||
optionParseString(key, value, &instance->config.libSQLite);
|
||||
else if(strcasecmp(key, "--lib-rpm") == 0)
|
||||
optionParseString(key, value, &instance->config.librpm);
|
||||
else if(strcasecmp(key, "--disk-folders") == 0)
|
||||
optionParseString(key, value, &instance->config.diskFolders);
|
||||
else if(strcasecmp(key, "--battery-dir") == 0)
|
||||
|
||||
+2
-2
@@ -104,7 +104,7 @@ typedef struct FFconfig
|
||||
FFstrbuf libGIO;
|
||||
FFstrbuf libDConf;
|
||||
FFstrbuf libXFConf;
|
||||
FFstrbuf libSQLite;
|
||||
FFstrbuf librpm;
|
||||
|
||||
FFstrbuf diskFolders;
|
||||
|
||||
@@ -337,7 +337,7 @@ FFvariant ffSettingsGetGSettings(FFinstance* instance, const char* schemaName, c
|
||||
FFvariant ffSettingsGet(FFinstance* instance, const char* dconfKey, const char* gsettingsSchemaName, const char* gsettingsPath, const char* gsettingsKey, FFvarianttype type);
|
||||
FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, const char* propertyName, FFvarianttype type);
|
||||
|
||||
uint32_t ffSettingsGetSQLiteColumnCount(FFinstance* instance, const char* fileName, const char* tableName);
|
||||
uint32_t ffSettingsGetRpmPackageCount(FFinstance* instance);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
void ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result);
|
||||
|
||||
@@ -62,7 +62,7 @@ void ffPrintPackages(FFinstance* instance)
|
||||
dpkg += getNumStrings("/data/data/com.termux/files/usr/var/lib/dpkg/status", "Status: ");
|
||||
#endif
|
||||
|
||||
uint32_t rpm = ffSettingsGetSQLiteColumnCount(instance, "/var/lib/rpm/rpmdb.sqlite", "Packages");
|
||||
uint32_t rpm = ffSettingsGetRpmPackageCount(instance);
|
||||
uint32_t xbps = getNumElements("/var/db/xbps", DT_REG);
|
||||
uint32_t flatpak = getNumElements("/var/lib/flatpak/app", DT_DIR);
|
||||
uint32_t snap = getNumElements("/snap", DT_DIR);
|
||||
|
||||
Reference in New Issue
Block a user