Skip to content

Commit

Permalink
Tentative fix for FilePath regression
Browse files Browse the repository at this point in the history
  • Loading branch information
adinapoli committed Apr 1, 2022
1 parent 69fd6a5 commit 51aff5e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions shelly.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extra-source-files:
test/data/zshrc
test/data/nonascii.txt
test/data/symlinked_dir/hoge_file
test/data/hello.sh
test/testall
README.md
ChangeLog.md
Expand Down
32 changes: 26 additions & 6 deletions src/Shelly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -605,14 +605,34 @@ whichEith originalFp = whichFull
whichFull fp = do
(trace . mappend "which " . toTextIgnore) fp >> whichUntraced
where
whichUntraced | isAbsolute fp = checkFile
| dotSlash splitOnDirs = checkFile
| length splitOnDirs > 0 = lookupPath >>= leftPathError
| otherwise = lookupCache >>= leftPathError
whichUntraced | isAbsolute fp = checkFile
| startsWithDot splitOnDirs = checkFile
| length splitOnDirs > 0 = lookupPath >>= leftPathError
| otherwise = lookupCache >>= leftPathError

splitOnDirs = splitDirectories fp
dotSlash ("./":_) = True
dotSlash _ = False

-- 'startsWithDot' receives as input the result of 'splitDirectories',
-- which will include the dot (\".\") as its first element only if this
-- is a path of the form \"./foo/bar/baz.sh\". Check for example:
--
-- > import System.FilePath as FP
-- > FP.splitDirectories "./test/data/hello.sh"
-- [".","test","data","hello.sh"]
-- > FP.splitDirectories ".hello.sh"
-- [".hello.sh"]
-- > FP.splitDirectories ".test/hello.sh"
-- [".test","hello.sh"]
-- > FP.splitDirectories ".foo"
-- [".foo"]
--
-- Note that earlier versions of Shelly used
-- \"system-filepath\" which also has a 'splitDirectories'
-- function, but it returns \"./\" as its first argument,
-- so we pattern match on both for backward-compatibility.
startsWithDot (".":_) = True
startsWithDot ("./":_) = True
startsWithDot _ = False

checkFile :: Sh (Either String FilePath)
checkFile = do
Expand Down
Empty file modified test/data/hello.sh
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions test/src/FindSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ findSpec = do
[ "dir"
, "dir/symlinked_dir"
, "dir/symlinked_dir/hoge_file"
, "hello.sh"
, "nonascii.txt"
, "symlinked_dir"
, "symlinked_dir/hoge_file"
Expand All @@ -128,6 +129,7 @@ findSpec = do
sort res @?=
[ "dir"
, "dir/symlinked_dir"
, "hello.sh"
, "nonascii.txt"
, "symlinked_dir"
, "symlinked_dir/hoge_file"
Expand Down
9 changes: 6 additions & 3 deletions test/src/RunSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ runSpec = do
if isWindows
then res @?= "Selbstverst\228ndlich \252berraschend\r\n"
else res @?= "Selbstverst\228ndlich \252berraschend\n"
it "script at $PWD" $ do
res <- shelly $ run "./test/data/hello.sh" []
res @?= "Hello!"
unless isWindows $ do
it "script at $PWD" $ do
res <- shelly $ do
run_ "chmod" ["+x", "test/data/hello.sh"]
run "./test/data/hello.sh" []
res @?= "Hello!\n"

-- Bash-related commands
describe "bash" $ do
Expand Down

0 comments on commit 51aff5e

Please sign in to comment.