From 8e7d465333be58dfafb3e04cce0fbbd06393f445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 19 Jan 2024 20:59:52 +0800 Subject: [PATCH] Fastfetch: create sub folders when writing config file Fix #690 --- CHANGELOG.md | 1 + src/fastfetch.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eafb2f57f5..ebd82da00d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Bugfixes: * Fix segfault in CPU module when running in aarch64 machine without `lscpu` installed (CPU, Linux) * Don't use `login` as terminal process (Terminal, Linux) * Silence warnings when building in 32bit machines. +* Create sub folders when writing config file (#690) # 2.6.0 diff --git a/src/fastfetch.c b/src/fastfetch.c index f60ae9ad35..68bcea67f3 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -7,6 +7,7 @@ #include "common/jsonconfig.h" #include "detection/version/version.h" #include "util/stringUtils.h" +#include "util/mallocHelper.h" #include "logo/logo.h" #include "fastfetch_datatext.h" @@ -831,7 +832,14 @@ static void writeConfigFile(FFdata* data, const FFstrbuf* filename) yyjson_mut_write_fp(stdout, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); else { - if (yyjson_mut_write_file(filename->chars, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL)) + size_t len; + FF_AUTO_FREE const char* str = yyjson_mut_write(doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, &len); + if (!str) + { + printf("Error: failed to generate config file\n"); + exit(1); + } + if (ffWriteFileData(filename->chars, len, str)) printf("The generated config file has been written in `%s`\n", filename->chars); else {