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

Add RealPath module #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions src/Streamly/Coreutils/RealPath.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- |
-- Module : Streamly.Coreutils.RealPath
-- Copyright : (c) 2022 Composewell Technologies
-- License : BSD-3-Clause
-- Maintainer : [email protected]
-- Stability : experimental
-- Portability : GHC
--
-- Returns resolved symbolic link target.

module Streamly.Coreutils.RealPath
(realPath)
where

import System.Directory (canonicalizePath )

-- | Make a path absolute, normalize the path,
-- and remove as many indirections from it as possible.

realPath :: FilePath -> IO FilePath
realPath = canonicalizePath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the same. Did you test and compare the realpath coreutil and this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes:
*Streamly.Coreutils.RealPath> realPath "./test2.txt"
"/home/ranjeetr/composewell/CoreUtils/streamly-coreutils/test2.txt"
*Streamly.Coreutils.RealPath> realPath "../test2.txt"
"/home/ranjeetr/composewell/CoreUtils/test2.txt"
*Streamly.Coreutils.RealPath>

kaveri:/composewell/CoreUtils/streamly-coreutils  (monadic-predicates)$ (nix) realpath ./test2.txt
/home/ranjeetr/composewell/CoreUtils/streamly-coreutils/test2.txt
kaveri:
/composewell/CoreUtils/streamly-coreutils  (monadic-predicates)$ (nix) realpath ../test2.txt
/home/ranjeetr/composewell/CoreUtils/test2.txt
kaveri:~/composewell/CoreUtils/streamly-coreutils  (RealPath_module)$ (nix)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same behaviors for symlink and nonexistent files.
*Streamly.Coreutils.RealPath> realPath "./ls.txt"
"/home/ranjeetr/composewell/CoreUtils/streamly-coreutils/test2.txt"
*Streamly.Coreutils.RealPath> realPath "../lsssss.txt"
"/home/ranjeetr/composewell/CoreUtils/lsssss.txt

1 change: 1 addition & 0 deletions streamly-coreutils.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ library
, Streamly.Coreutils.FileTest
, Streamly.Coreutils.Ls
, Streamly.Coreutils.String
, Streamly.Coreutils.RealPath
, Streamly.Coreutils.ShellWords
, Streamly.Coreutils.Sleep
, Streamly.Coreutils.Uniq
Expand Down