forked from haskell/directory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
133 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{-# LANGUAGE CPP #-} | ||
module RemovePathForcibly where | ||
#include "util.inl" | ||
import System.Directory | ||
import Data.List (sort) | ||
import System.FilePath ((</>), normalise) | ||
import System.IO.Error (catchIOError) | ||
import TestUtils | ||
|
||
main :: TestEnv -> IO () | ||
main _t = do | ||
|
||
------------------------------------------------------------ | ||
-- clean up junk from previous invocations | ||
|
||
modifyPermissions (tmp "c") (\ p -> p { writable = True }) | ||
`catchIOError` \ _ -> return () | ||
removePathForcibly tmpD | ||
`catchIOError` \ _ -> return () | ||
|
||
------------------------------------------------------------ | ||
-- set up | ||
|
||
createDirectoryIfMissing True (tmp "a/x/w") | ||
createDirectoryIfMissing True (tmp "a/y") | ||
createDirectoryIfMissing True (tmp "a/z") | ||
createDirectoryIfMissing True (tmp "b") | ||
createDirectoryIfMissing True (tmp "c") | ||
createDirectoryIfMissing True (tmp "f") | ||
writeFile (tmp "a/x/w/u") "foo" | ||
writeFile (tmp "a/t") "bar" | ||
writeFile (tmp "f/s") "qux" | ||
tryCreateSymbolicLink (normalise "../a") (tmp "b/g") | ||
tryCreateSymbolicLink (normalise "../b") (tmp "c/h") | ||
tryCreateSymbolicLink (normalise "a") (tmp "d") | ||
tryCreateSymbolicLink (normalise "f") (tmp "e") | ||
setPermissions (tmp "f/s") emptyPermissions | ||
setPermissions (tmp "f") emptyPermissions | ||
|
||
------------------------------------------------------------ | ||
-- tests | ||
|
||
removePathForcibly (tmp "f") | ||
removePathForcibly (tmp "e") | ||
|
||
T(expectEq) () [".", "..", "a", "b", "c", "d"] . sort =<< | ||
getDirectoryContents tmpD | ||
T(expectEq) () [".", "..", "t", "x", "y", "z"] . sort =<< | ||
getDirectoryContents (tmp "a") | ||
T(expectEq) () [".", "..", "g"] . sort =<< | ||
getDirectoryContents (tmp "b") | ||
T(expectEq) () [".", "..", "h"] . sort =<< | ||
getDirectoryContents (tmp "c") | ||
T(expectEq) () [".", "..", "t", "x", "y", "z"] . sort =<< | ||
getDirectoryContents (tmp "d") | ||
|
||
removePathForcibly (tmp "d") | ||
|
||
T(expectEq) () [".", "..", "a", "b", "c"] . sort =<< | ||
getDirectoryContents tmpD | ||
T(expectEq) () [".", "..", "t", "x", "y", "z"] . sort =<< | ||
getDirectoryContents (tmp "a") | ||
T(expectEq) () [".", "..", "g"] . sort =<< | ||
getDirectoryContents (tmp "b") | ||
T(expectEq) () [".", "..", "h"] . sort =<< | ||
getDirectoryContents (tmp "c") | ||
|
||
removePathForcibly (tmp "c") | ||
|
||
T(expectEq) () [".", "..", "a", "b"] . sort =<< | ||
getDirectoryContents tmpD | ||
T(expectEq) () [".", "..", "t", "x", "y", "z"] . sort =<< | ||
getDirectoryContents (tmp "a") | ||
T(expectEq) () [".", "..", "g"] . sort =<< | ||
getDirectoryContents (tmp "b") | ||
|
||
removePathForcibly (tmp "b") | ||
|
||
T(expectEq) () [".", "..", "a"] . sort =<< | ||
getDirectoryContents tmpD | ||
T(expectEq) () [".", "..", "t", "x", "y", "z"] . sort =<< | ||
getDirectoryContents (tmp "a") | ||
|
||
removePathForcibly (tmp "a") | ||
|
||
T(expectEq) () [".", ".."] . sort =<< | ||
getDirectoryContents tmpD | ||
|
||
where testName = "removePathForcibly" | ||
tmpD = testName ++ ".tmp" | ||
tmp s = tmpD </> normalise s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters