Skip to content

Commit

Permalink
fix issue with cfcache location being wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
froehlichA committed Apr 19, 2022
1 parent bcbb2dc commit 722dd8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/api/cfcache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import std/[json, options, os, times]
import cfcore

const
cacheDir* = getCacheDir("pax") ## the cache folder
addonCacheTime = 30.minutes ## how long an addon is cached
addonFileCacheTime = 1.days ## how long an addon file is cached

proc getAddonFilename*(projectId: int): string {.inline.} =
## get the filename of an addon in the cache.
return cacheDir / ("addon:" & $projectId)
return getCacheDir("pax") / ("addon:" & $projectId)

proc getAddonFileFilename*(fileId: int): string {.inline.} =
## get the filename of an addon file in the cache.
return cacheDir / ("file:" & $fileId)
return getCacheDir("pax") / ("file:" & $fileId)

proc putAddon*(addon: CfAddon): void =
## put an addon in the cache.
Expand Down Expand Up @@ -79,15 +78,15 @@ proc clean*(): int =
## remove old files from the cache.
## returns the number of files cleared.
result = 0
for filename in walkFiles(cacheDir / "addon:*"):
for filename in walkFiles(getCacheDir("pax") / "addon:*"):
let info = getFileInfo(filename)
if info.lastWriteTime + addonCacheTime < getTime():
try:
removeFile(filename)
inc(result)
except IOError:
discard
for filename in walkFiles(cacheDir / "file:*"):
for filename in walkFiles(getCacheDir("pax") / "file:*"):
let info = getFileInfo(filename)
if info.lastWriteTime + addonFileCacheTime < getTime():
try:
Expand All @@ -99,8 +98,8 @@ proc clean*(): int =
proc purge*(): void =
## remove all files from the cache.
try:
removeDir(cacheDir)
createDir(cacheDir)
removeDir(getCacheDir("pax"))
createDir(getCacheDir("pax"))
except IOError:
discard

Expand Down
3 changes: 1 addition & 2 deletions src/pax.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import std/os
import therapist
import api/cfcache
import cmd/[add, cache, expo, impo, init, list, pin, remove, update, upgrade, version]
import term/[color, prompt]
import util/paxVersion
Expand Down Expand Up @@ -212,7 +211,7 @@ let spec = (
)

spec.parseOrHelp()
createDir(cfcache.cacheDir)
createDir(getCacheDir("pax"))

# GLOBAL OPTIONS
if commonArgs.yes.seen:
Expand Down

0 comments on commit 722dd8f

Please sign in to comment.