Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aura] -Cv: Cache clear vcs contents #693

Merged
merged 2 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Full usage information can be found in Aura's man page.
| `aura -C <package>` | Downgrade a package. |
| `aura -Cs <regex>` | Search the package cache for files that match a regex. |
| `aura -Cc <n>` | Delete all but the most recent `n` versions of each cached package. |
| `aura -Cv` | Delete all of the `/var/cache/aura/vcs` cache |

### Searching the Pacman Log

Expand Down
15 changes: 12 additions & 3 deletions aura/exec/Aura/Commands/C.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE BangPatterns #-}

-- |
-- Module : Aura.Commands.C
Expand All @@ -9,16 +10,16 @@
-- Maintainer: Colin Woodbury <colin@fosskers.ca>
--
-- Handle all @-C@ flags - those which involve the package cache.

module Aura.Commands.C
( downgradePackages
, searchCache
, backupCache
, cleanCache
, cleanNotSaved
) where
, cleanDir ) where

import Aura.Cache
import Aura.Build (vcsStore)
import Aura.Colour (red)
import Aura.Core
import Aura.IO
Expand All @@ -38,9 +39,9 @@ import qualified RIO.Map as M
import qualified RIO.NonEmpty as NEL
import qualified RIO.Set as S
import qualified RIO.Text as T
import RIO.FilePath

---

-- | Interactive. Gives the user a choice as to exactly what versions
-- they want to downgrade to.
downgradePackages :: NonEmpty PkgName -> RIO Env ()
Expand Down Expand Up @@ -193,3 +194,11 @@ groupByName :: [PackagePath] -> [[PackagePath]]
groupByName pkgs = L.groupBy sameBaseName $ L.sort pkgs
where sameBaseName a b = baseName a == baseName b
baseName p = spName <$> simplepkg p

-- | Delete all the files in the given path dir
cleanDir :: RIO Env ()
cleanDir = do
ss <- asks settings
let !vcsPath = fromMaybe vcsStore . vcsPathOf $ buildConfigOf ss
notify ss cleanCache_6
listDirectory vcsPath >>= traverse_ (removeDirectoryRecursive . (</>) vcsPath)
4 changes: 3 additions & 1 deletion aura/exec/Aura/Flags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ data CacheOp
| CacheClean !Word !CleanMode
| CacheCleanNotSaved
| CacheSearch !Text
| CacheCleanVCS
deriving (Show)

data LogOp
Expand Down Expand Up @@ -341,13 +342,14 @@ backups = bigB *> (Backup <$> optional mods)
cache :: Parser AuraOp
cache = bigC *> (Cache <$> (fmap Left mods <|> fmap Right somePkgs))
where bigC = flag' () (long "downgrade" <> short 'C' <> help "Interact with the package cache.")
mods = backup <|> clean <|> clean' <|> search
mods = backup <|> clean <|> clean' <|> search <|> cleanVCS
backup = CacheBackup <$> option (eitherReader absFilePath) (long "backup" <> short 'b' <> metavar "PATH" <> help "Backup the package cache to a given directory." <> hidden)
clean = CacheClean
<$> option auto (long "clean" <> short 'c' <> metavar "N" <> help "Save the most recent N versions of a package in the cache, deleting the rest." <> hidden)
<*> flag Quantity AndUninstalled (long "uninstalled" <> short 'u' <> help "Add to -c. Clears out any uninstalled packages from the cache.")
clean' = flag' CacheCleanNotSaved (long "notsaved" <> help "Clean out any cached package files which doesn't appear in any saved state." <> hidden)
search = CacheSearch <$> strOption (long "search" <> short 's' <> metavar "STRING" <> help "Search the package cache via a search string." <> hidden)
cleanVCS = flag' CacheCleanVCS (long "vcs" <> short 'v' <> help "Clears the vcs cache directory" <> hidden)

log :: Parser AuraOp
log = bigL *> (Log <$> optional mods)
Expand Down
1 change: 1 addition & 0 deletions aura/exec/aura.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ execOpts ops = do
Left (CacheClean n u) -> sudo $ C.cleanCache n u
Left CacheCleanNotSaved -> sudo C.cleanNotSaved
Left (CacheBackup pth) -> sudo $ C.backupCache pth
Left CacheCleanVCS -> sudo C.cleanDir
Right (Log o) -> case o of
Nothing -> L.viewLogFile
Just (LogInfo ps) -> L.logInfoOnPkg ps
Expand Down