Skip to content

Commit

Permalink
Merge pull request #12 from PRESFIL/support-STACK_ROOT-env
Browse files Browse the repository at this point in the history
Support `$STACK_ROOT` environment variable
  • Loading branch information
juhp authored Aug 26, 2023
2 parents f291740 + 0e9633f commit 93814e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release history for stack-clean-old

## Unreleased
- add support for `${STACK_ROOT}` environment variable to override the Stack
Root location

## 0.4.7 (2023-08-22)
- add --tarballs for programs/ ghc tarballs too (#9)
- bug fix to match both ghc-*.* and ghc-variant-*.* (#14)
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ snapshot builds and ghc versions to recover diskspace.
## Usage
`stack-clean-old [size|list|remove|keep-minor|purge-older|delete-work] [(-P|--project)|(-G|--global)|(-C|--compilers)|(-T|--tarballs)] [(-s|--subdirs)|(-r|--recursive)] [-d|--delete] [GHCVER]`

In a project directory it acts on `.stack-work/install/` by default,
otherwise on `~/.stack/{snapshots,programs}/`.
In a project directory it acts on `.stack-work/install/` by default, otherwise
on the *Stack Root location* `${STACK_ROOT}/{snapshots,programs}/`. If
`${STACK_ROOT}` is unset, the *Stack Root location* is `~/.stack/`. See
[official documentation][stack_root].

[stack_root]: https://docs.haskellstack.org/en/stable/environment_variables/#stack_root

Subcommands:

`size`:
prints the total size of `.stack-work/` or `~/.stack/`
prints the total size of `.stack-work/` of project(s) or the *Stack Root location*.
(`size` does not take a GHCVER argument).

`list`:
Expand Down
13 changes: 11 additions & 2 deletions src/Directories.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@ where
import Data.List.Extra
import SimpleCmd (error')
import System.Directory
import System.Environment
import System.FilePath
import System.FilePath.Glob

globDirs :: String -> IO [FilePath]
globDirs pat = do
map (dropPrefix "./") <$> namesMatching (pat ++ "/")

getStackRootDir :: IO FilePath
getStackRootDir = do
home <- getHomeDirectory
env <- lookupEnv "STACK_ROOT"
case env of
Just path | isAbsolute path -> return path
_ -> return $ home </> ".stack"

getStackSubdir :: FilePath -> IO FilePath
getStackSubdir subdir = do
home <- getHomeDirectory
return $ home </> ".stack" </> subdir
stackRoot <- getStackRootDir
return $ stackRoot </> subdir

switchToSystemDirUnder :: Maybe String -> FilePath -> IO ()
switchToSystemDirUnder msystem dir = do
Expand Down

0 comments on commit 93814e1

Please sign in to comment.