Skip to content

Commit 39dfcb6

Browse files
committed
Packages (Linux): optimise nix detection code
1 parent 882b178 commit 39dfcb6

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/detection/packages/packages_linux.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ static bool checkNixCache(FFstrbuf* cacheDir, FFstrbuf* hash, uint32_t* count)
171171
if (!ffPathExists(cacheDir->chars, FF_PATHTYPE_FILE))
172172
return false;
173173

174-
FF_STRBUF_AUTO_DESTROY cacheContent;
175-
ffStrbufInit(&cacheContent);
174+
FF_STRBUF_AUTO_DESTROY cacheContent = ffStrbufCreate();
176175
if (!ffReadFileBuffer(cacheDir->chars, &cacheContent))
177176
return false;
178177

@@ -189,11 +188,8 @@ static bool checkNixCache(FFstrbuf* cacheDir, FFstrbuf* hash, uint32_t* count)
189188

190189
static bool writeNixCache(FFstrbuf* cacheDir, FFstrbuf* hash, uint32_t count)
191190
{
192-
FF_STRBUF_AUTO_DESTROY cacheContent;
193-
ffStrbufInit(&cacheContent);
194-
ffStrbufAppend(&cacheContent, hash);
195-
ffStrbufAppendC(&cacheContent, '\n');
196-
ffStrbufAppendF(&cacheContent, "%u", count);
191+
FF_STRBUF_AUTO_DESTROY cacheContent = ffStrbufCreateCopy(hash);
192+
ffStrbufAppendF(&cacheContent, "\n%u", count);
197193
return ffWriteFileBuffer(cacheDir->chars, &cacheContent);
198194
}
199195

@@ -203,9 +199,7 @@ static uint32_t getNixPackagesImpl(char* path)
203199
if(!ffPathExists(path, FF_PATHTYPE_DIRECTORY))
204200
return 0;
205201

206-
FF_STRBUF_AUTO_DESTROY cacheDir;
207-
ffStrbufInit(&cacheDir);
208-
ffStrbufAppend(&cacheDir, &instance.state.platform.cacheDir);
202+
FF_STRBUF_AUTO_DESTROY cacheDir = ffStrbufCreateCopy(&instance.state.platform.cacheDir);
209203
ffStrbufEnsureEndsWithC(&cacheDir, '/');
210204
ffStrbufAppendS(&cacheDir, "fastfetch/packages/nix");
211205
ffStrbufAppendS(&cacheDir, path);
@@ -231,7 +225,7 @@ static uint32_t getNixPackagesImpl(char* path)
231225

232226
//Implementation based on bash script from here:
233227
//https://github.com/fastfetch-cli/fastfetch/issues/195#issuecomment-1191748222
234-
228+
235229
FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateA(1024);
236230

237231
ffProcessAppendStdOut(&output, (char* const[]) {
@@ -261,7 +255,7 @@ static uint32_t getNixPackagesImpl(char* path)
261255
count++;
262256
lineLength = 0;
263257
}
264-
258+
265259
writeNixCache(&cacheDir, &hash, count);
266260
return count;
267261
}

0 commit comments

Comments
 (0)