From a31c9d1e88a99f60ee94a37b326f0c89f4acb553 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 5 Jun 2016 21:59:31 +0200 Subject: [PATCH] Improve documentation and tests for file creation --- src/HPath/IO.hs | 6 ++++++ test/HPath/IO/CreateDirSpec.hs | 5 +++++ test/HPath/IO/CreateRegularFileSpec.hs | 5 +++++ test/HPath/IO/CreateSymlinkSpec.hs | 5 +++++ 4 files changed, 21 insertions(+) diff --git a/src/HPath/IO.hs b/src/HPath/IO.hs index d0a42ba..6c90152 100644 --- a/src/HPath/IO.hs +++ b/src/HPath/IO.hs @@ -661,6 +661,8 @@ executeFile fp args -- -- - `PermissionDenied` if output directory cannot be written to -- - `AlreadyExists` if destination file already exists +-- - `NoSuchThing` if any of the parent components of the path +-- do not exist createRegularFile :: FileMode -> Path Abs -> IO () createRegularFile fm dest = bracket (SPI.openFd (fromAbs dest) SPI.WriteOnly (Just fm) @@ -675,6 +677,8 @@ createRegularFile fm dest = -- -- - `PermissionDenied` if output directory cannot be written to -- - `AlreadyExists` if destination directory already exists +-- - `NoSuchThing` if any of the parent components of the path +-- do not exist createDir :: FileMode -> Path Abs -> IO () createDir fm dest = createDirectory (fromAbs dest) fm @@ -685,6 +689,8 @@ createDir fm dest = createDirectory (fromAbs dest) fm -- -- - `PermissionDenied` if output directory cannot be written to -- - `AlreadyExists` if destination file already exists +-- - `NoSuchThing` if any of the parent components of the path +-- do not exist -- -- Note: calls `symlink` createSymlink :: Path Abs -- ^ destination file diff --git a/test/HPath/IO/CreateDirSpec.hs b/test/HPath/IO/CreateDirSpec.hs index bcd3cbe..e1c7165 100644 --- a/test/HPath/IO/CreateDirSpec.hs +++ b/test/HPath/IO/CreateDirSpec.hs @@ -50,6 +50,11 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $ removeDirIfExists "newDir" -- posix failures -- + it "createDir, parent directories do not exist" $ + createDir' "some/thing/dada" + `shouldThrow` + (\e -> ioeGetErrorType e == NoSuchThing) + it "createDir, can't write to output directory" $ createDir' "noWritePerms/newDir" `shouldThrow` diff --git a/test/HPath/IO/CreateRegularFileSpec.hs b/test/HPath/IO/CreateRegularFileSpec.hs index 8f775c5..2efe64e 100644 --- a/test/HPath/IO/CreateRegularFileSpec.hs +++ b/test/HPath/IO/CreateRegularFileSpec.hs @@ -48,6 +48,11 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $ removeFileIfExists "newDir" -- posix failures -- + it "createRegularFile, parent directories do not exist" $ + createRegularFile' "some/thing/dada" + `shouldThrow` + (\e -> ioeGetErrorType e == NoSuchThing) + it "createRegularFile, can't write to destination directory" $ createRegularFile' "noWritePerms/newDir" `shouldThrow` diff --git a/test/HPath/IO/CreateSymlinkSpec.hs b/test/HPath/IO/CreateSymlinkSpec.hs index 9769a87..d3b5097 100644 --- a/test/HPath/IO/CreateSymlinkSpec.hs +++ b/test/HPath/IO/CreateSymlinkSpec.hs @@ -49,6 +49,11 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $ removeFileIfExists "newSymL" -- posix failures -- + it "createSymlink, parent directories do not exist" $ + createSymlink' "some/thing/dada" "lala" + `shouldThrow` + (\e -> ioeGetErrorType e == NoSuchThing) + it "createSymlink, can't write to destination directory" $ createSymlink' "noWritePerms/newDir" "lala" `shouldThrow`