Skip to content

Commit

Permalink
[ compat ] adjust file paths to upstream changes (#310)
Browse files Browse the repository at this point in the history
* [ compat ] adjust file paths to upstream changes

* [ pack ] add pack.toml
  • Loading branch information
stefan-hoeck authored Sep 28, 2024
1 parent 31f9de1 commit fa686af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
20 changes: 20 additions & 0 deletions pack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[custom.all.pack]
type = "local"
path = "."
ipkg = "pack.ipkg"

[custom.all.pack-admin]
type = "local"
path = "."
ipkg = "pack-admin.ipkg"

[custom.all.micropack]
type = "local"
path = "."
ipkg = "micropack.ipkg"

[custom.all.filepath]
type = "git"
url = "https://github.com/stefan-hoeck/idris2-filepath"
commit = "latest:main"
ipkg = "filepath.ipkg"
12 changes: 6 additions & 6 deletions src/Pack/Core/IO.idr
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ fileMissing = map not . fileExists
||| Tries to create a director (including parent directories)
export
mkDir : HasIO io => (dir : Path Abs) -> EitherT PackErr io ()
mkDir (PAbs [<]) = pure ()
mkDir d = sys ["mkdir", "-p", d]
mkDir (PAbs _ [<]) = pure ()
mkDir d = sys ["mkdir", "-p", d]

||| Creates a parent directory of a (file) path
export
Expand All @@ -208,8 +208,8 @@ curDir : HasIO io => EitherT PackErr io (Path Abs)
curDir = do
Just s <- currentDir | Nothing => throwE NoCurDir
case the FilePath (fromString s) of
FP (PAbs sx) => pure (PAbs sx)
FP (PRel _) => throwE NoCurDir
FP (PAbs u sx) => pure (PAbs u sx)
FP (PRel _) => throwE NoCurDir

||| Changes the working directory
export
Expand Down Expand Up @@ -279,11 +279,11 @@ findInParentDirs : {auto _ : HasIO io}
-> (Body -> Bool)
-> Path Abs
-> EitherT PackErr io (Maybe (File Abs))
findInParentDirs p (PAbs sb) = go sb
findInParentDirs p (PAbs d sb) = go sb
where go : SnocList Body -> EitherT PackErr io (Maybe (File Abs))
go [<] = pure Nothing
go (sb :< b) =
let dir := PAbs (sb :< b)
let dir := PAbs d (sb :< b)
in do
(h :: _) <- filter p <$> entries dir | Nil => go sb
pure $ Just (MkF dir h)
Expand Down
4 changes: 2 additions & 2 deletions src/Pack/Core/TOML.idr
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ export
FromTOML FilePath where fromTOML = tmap fromString

toRelPath : FilePath -> Either TOMLErr (Path Rel)
toRelPath (FP $ PRel sx) = Right (PRel sx)
toRelPath (FP $ PAbs _) = Left (WrongType [] "Relative Path")
toRelPath (FP $ PRel sx) = Right (PRel sx)
toRelPath (FP $ PAbs _ _) = Left (WrongType [] "Relative Path")

toRelFile : FilePath -> Either TOMLErr (File Rel)
toRelFile (FP $ PRel (sx :< x)) = Right (MkF (PRel sx) x)
Expand Down
8 changes: 4 additions & 4 deletions src/Pack/Core/Types.idr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ quote v = "\"\{v}\""
||| `../../quux`.
export
relativeTo : (origin, target : Path Abs) -> Path Rel
relativeTo (PAbs sx) (PAbs sy) = PRel $ go (sx <>> []) (sy <>> [])
relativeTo (PAbs _ sx) (PAbs _ sy) = PRel $ go (sx <>> []) (sy <>> [])

where
go : (o,t : List Body) -> SnocList Body
Expand All @@ -60,15 +60,15 @@ isHtmlBody = (Just "html" ==) . extension

toRelPath : String -> Path Rel
toRelPath s = case the FilePath (fromString s) of
FP (PAbs sx) => PRel sx
FP (PRel sx) => PRel sx
FP (PAbs _ sx) => PRel sx
FP (PRel sx) => PRel sx

||| Converts a `FilePath` - which might hold a relative
||| or an absolute path - to an absolute path by interpreting
||| a relative path being relative to the given parent directory.
export
toAbsPath : (parent : Path Abs) -> FilePath -> Path Abs
toAbsPath parent (FP $ PAbs sx) = PAbs sx
toAbsPath parent (FP $ PAbs d sx) = PAbs d sx
toAbsPath parent (FP $ PRel sx) = parent </> PRel sx

||| Parses a string, converting it to either a relative
Expand Down

0 comments on commit fa686af

Please sign in to comment.