Skip to content

Commit

Permalink
feat: use Nim code instead of find
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 142c424e07121a29fc8c9ae3227a567d56e42ec464b8c005be98e418437c670d
  • Loading branch information
thindil committed Dec 27, 2024
1 parent eda2f99 commit 603bb80
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/beastcleaner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ proc main() {.raises: [], tags: [ReadIOEffect, WriteIOEffect, ExecIOEffect,
# Get the list of all files installed by all packages
try:
stdout.write(s = "Generating the list of all files installed by all packages ... ")
stdout.flushFile
except IOError:
quit "Can't show message."
var (output, exitCode) = try:
execCmdEx(command = "pkg info --list-files -a")
except OSError, IOError:
quit "Can't execute pkg command"
output.stripLineEnd
let filesListFile: File = try:
let pkgListFile: File = try:
open(filename = pkgList, mode = fmWrite)
except IOError:
quit "Can't create file with list of all installed files"
Expand All @@ -131,23 +132,39 @@ proc main() {.raises: [], tags: [ReadIOEffect, WriteIOEffect, ExecIOEffect,
if line.endsWith(suffix = ':'):
continue
try:
filesListFile.writeLine(x = line.strip)
pkgListFile.writeLine(x = line.strip)
except IOError:
quit "Can't save data to file with list of all installed files."
filesListFile.close()
pkgListFile.close()
if exitCode != 0:
quit "Can't get the list of all files installed by packages."
echo "done."

# Get the list of all files
try:
write(f = stdout, s = "Generating the list of all files in /usr/local ... ")
if execCmd(command = "find -x /usr/local -type f -or -type l 2>/dev/null | sort > " &
filesList) != 0:
quit QuitFailure
echo "done."
stdout.flushFile
except IOError:
quit "Can't generate the list of all installed files. Reason: " &
getCurrentExceptionMsg()
quit "Can't show message."
let filesListFile: File = try:
open(filename = filesList, mode = fmWrite)
except IOError:
quit "Can't create file with list of all installed files"
var entries: seq[string]
try:
for entry in walkDirRec(dir = "/usr/local", yieldFilter = {pcFile, pcLinkToFile}):
entries.add(y = entry)
except OSError:
quit "Can't create the list of all local files."
entries.sort(cmp = system.cmp)
for entry in entries:
try:
filesListFile.writeLine(x = entry)
except:
quit "Can't save data to file with list of all local files."
filesListFile.close()
echo "done."

# Save the difference to the file
try:
write(f = stdout, s = "Creating the list of files not managed by packages ... ")
Expand Down

0 comments on commit 603bb80

Please sign in to comment.