Open srghma opened 1 month ago
or maybe this is ok, since I can write
sandboxOrThrow
:: forall a b m
. IsRelOrAbs a
=> IsDirOrFile b
=> MonadThrow Error m
=> Path Abs Dir
-> Path a b
-> m (SandboxedPath a b)
sandboxOrThrow root path = sandbox root path # maybe (throwError $ error $ "cannot sandbox path: root = " <> show root <> ", path = " <> show path) pure
(outerTmpDir :: SandboxedPath Rel Dir) <- sandboxOrThrow cwd (currentDir </> dir (Proxy :: _ "tmp") </> dir (Proxy :: _ "dir-entries-test"))
but on other hand - what is the use of currentDir
inside of a sandbox
method, maybe currentDir
makes everything harder to understand
well, someone could write getFirstFile
whose output form depends on the input
-- ./mydir/ -> ./mydir/myfile.txt
-- /myabspath/mydir/ -> /myabspath/mydir/myfile.txt
getFirstFile :: FilePath -> Aff FilePath
getFirstFile = ...
getFirstFileAff
:: forall relOrAbs
. IsRelOrAbs relOrAbs
=> SandboxedPath relOrAbs Dir
-> Aff (Maybe (Path relOrAbs File))
getFirstFileAff path = do
let printedPath = printPath currentPrinter path
(maybeFile :: Maybe FilePath) <- Node.FS.getFirstFile path
map (parse currentParser parseRelFile # ...) maybeFile
and this would be wrong - printPath
will always return Abs Path
it can only ever be
getFirstFileAff
:: forall relOrAbs
. IsRelOrAbs relOrAbs
=> SandboxedPath relOrAbs Dir
-> Aff (Maybe (Path Abs File))
Implemented, works ok, error is thrown now if I return Rel
also implemented a SafeAppend for Sandboxed (allows only adding new paths, disallows going up)
https://github.com/srghma/purescript-pathy/commit/5a747ea6a204ec332ce59966f4f94ff1ceb34dcd
Describe the bug
I write https://github.com/srghma/purescript-pathy-node/blob/56c0cbce481ac50b11f5b66690967701a5281d65/test/Test/Main.purs#L109-L110
and it gives
"/tmp/dir-entries-test/"
and I'm like "WHAAT, should be rel"
To Reproduce
add this to tests
Expected behavior
maybe
data SandboxedPath a b = SandboxedPath (Path Abs Dir) (Path a b)
should be
data SandboxedPath dirOrFile = SandboxedPath (Path Abs Dir) (Path Abs dirOrFile)