Skip to content

Commit c4824b2

Browse files
authored
Merge pull request #654 from fastfetch-cli/dev
Release v2.3.4
2 parents 923997f + dcbda6c commit c4824b2

File tree

4 files changed

+48
-33
lines changed

4 files changed

+48
-33
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 2.3.4
2+
3+
Bugfixes:
4+
* Fix `--help` doesn't work when built without python
5+
6+
Features:
7+
* Use `MemAvailable` if available (Memory, Linux)
8+
* Improve performance of detecting dpkg package count (Packages, Linux)
9+
110
# 2.3.3
211

312
Bugfixes:

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
22

33
project(fastfetch
4-
VERSION 2.3.3
4+
VERSION 2.3.4
55
LANGUAGES C
66
DESCRIPTION "Fast neofetch-like system information tool"
77
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
@@ -221,12 +221,15 @@ endfunction(fastfetch_load_text)
221221

222222
find_package(Python)
223223
if(Python_FOUND)
224-
# Minify JSON string. `io.open(0,encoding='utf-8')` is needed to avoid encoding issues on Windows
225224
execute_process(COMMAND ${Python_EXECUTABLE} -c "import json,sys;json.dump(json.load(sys.stdin),sys.stdout,separators=(',',':'))"
226225
INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/src/data/help.json"
227226
OUTPUT_VARIABLE DATATEXT_JSON_HELP)
227+
if(DATATEXT_JSON_HELP STREQUAL "")
228+
message(ERROR "DATATEXT_JSON_HELP is empty, which should not happen!")
229+
endif()
228230
else()
229-
file(READ "src/data/help.json" TEMP)
231+
message(STATUS "Python3 is not found, 'help.json' will not be minified")
232+
file(READ "src/data/help.json" DATATEXT_JSON_HELP)
230233
endif()
231234

232235
fastfetch_encode_c_string("${DATATEXT_JSON_HELP}" DATATEXT_JSON_HELP)

src/detection/memory/memory_linux.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,43 @@ const char* ffDetectMemory(FFMemoryResult* ram)
1313
buf[nRead] = '\0';
1414

1515
uint64_t memTotal = 0,
16+
memAvailable = 0,
1617
shmem = 0,
1718
memFree = 0,
1819
buffers = 0,
1920
cached = 0,
2021
sReclaimable = 0;
21-
22+
2223
char *token = NULL;
2324
if((token = strstr(buf, "MemTotal:")) != NULL)
2425
memTotal = strtoul(token + strlen("MemTotal:"), NULL, 10);
26+
else
27+
return "MemTotal not found in /proc/meminfo";
28+
29+
if((token = strstr(buf, "MemAvailable:")) != NULL)
30+
memAvailable = strtoul(token + strlen("MemAvailable:"), NULL, 10);
31+
else
32+
{
33+
if((token = strstr(buf, "MemFree:")) != NULL)
34+
memFree = strtoul(token + strlen("MemFree:"), NULL, 10);
35+
36+
if((token = strstr(buf, "Buffers:")) != NULL)
37+
buffers = strtoul(token + strlen("Buffers:"), NULL, 10);
38+
39+
if((token = strstr(buf, "Cached:")) != NULL)
40+
cached = strtoul(token + strlen("Cached:"), NULL, 10);
41+
42+
if((token = strstr(buf, "Shmem:")) != NULL)
43+
shmem = strtoul(token + strlen("Shmem:"), NULL, 10);
44+
45+
if((token = strstr(buf, "SReclaimable:")) != NULL)
46+
sReclaimable = strtoul(token + strlen("SReclaimable:"), NULL, 10);
2547

26-
if((token = strstr(buf, "MemFree:")) != NULL)
27-
memFree = strtoul(token + strlen("MemFree:"), NULL, 10);
28-
29-
if((token = strstr(buf, "Buffers:")) != NULL)
30-
buffers = strtoul(token + strlen("Buffers:"), NULL, 10);
31-
32-
if((token = strstr(buf, "Cached:")) != NULL)
33-
cached = strtoul(token + strlen("Cached:"), NULL, 10);
34-
35-
if((token = strstr(buf, "Shmem:")) != NULL)
36-
shmem = strtoul(token + strlen("Shmem:"), NULL, 10);
37-
38-
if((token = strstr(buf, "SReclaimable:")) != NULL)
39-
sReclaimable = strtoul(token + strlen("SReclaimable:"), NULL, 10);
48+
memAvailable = memFree + buffers + cached + sReclaimable - shmem;
49+
}
4050

4151
ram->bytesTotal = memTotal * 1024lu;
42-
ram->bytesUsed = (memTotal + shmem - memFree - buffers - cached - sReclaimable) * 1024lu;
52+
ram->bytesUsed = (memTotal - memAvailable) * 1024lu;
4353

4454
return NULL;
4555
}

src/detection/packages/packages_linux.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,19 @@ static uint32_t getNumElements(FFstrbuf* baseDir, const char* dirname, unsigned
4242

4343
static uint32_t getNumStringsImpl(const char* filename, const char* needle)
4444
{
45-
FILE* file = fopen(filename, "r");
46-
if(file == NULL)
45+
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
46+
if (!ffReadFileBuffer(filename, &content))
4747
return 0;
4848

4949
uint32_t count = 0;
50-
51-
char* line = NULL;
52-
size_t len = 0;
53-
54-
while(getline(&line, &len, file) != EOF)
50+
char *iter = content.chars;
51+
size_t needleLength = strlen(needle);
52+
while ((iter = memmem(iter, content.length - (size_t)(iter - content.chars), needle, needleLength)) != NULL)
5553
{
56-
if(strstr(line, needle) != NULL)
57-
++count;
54+
++count;
55+
iter += needleLength;
5856
}
5957

60-
if(line != NULL)
61-
free(line);
62-
63-
fclose(file);
64-
6558
return count;
6659
}
6760

0 commit comments

Comments
 (0)