Skip to content

Commit

Permalink
Restore return type of toLinkTarget to Maybe LinkTarget for the sake …
Browse files Browse the repository at this point in the history
…of backward compatibility
  • Loading branch information
Bodigrim committed Dec 10, 2023
1 parent 0926e16 commit 6dd1a8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion Codec/Archive/Tar/Check/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ module Codec.Archive.Tar.Check.Internal (
import Codec.Archive.Tar.LongNames
import Codec.Archive.Tar.Types
import Control.Applicative ((<|>))
import Control.Monad.Catch (MonadThrow(throwM))
import qualified Data.ByteString.Lazy.Char8 as Char8
import Data.Maybe (fromMaybe)
import Data.Typeable (Typeable)
Expand Down
19 changes: 9 additions & 10 deletions Codec/Archive/Tar/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ module Codec.Archive.Tar.Types (

LinkTarget(..),
toLinkTarget,
toLinkTarget',
fromLinkTarget,
fromLinkTargetToPosixPath,
fromLinkTargetToWindowsPath,
Expand All @@ -78,7 +77,6 @@ import qualified Data.ByteString.Char8 as BS.Char8
import qualified Data.ByteString.Lazy as LBS
import Control.DeepSeq
import Control.Exception (Exception, displayException)
import Control.Monad.Catch (MonadThrow, throwM)

import qualified System.FilePath as FilePath.Native
( joinPath, splitDirectories, addTrailingPathSeparator, hasTrailingPathSeparator, pathSeparator, isAbsolute, hasTrailingPathSeparator )
Expand Down Expand Up @@ -489,11 +487,12 @@ instance NFData LinkTarget where
-- | Convert a native 'FilePath' to a tar 'LinkTarget'.
-- string is longer than 100 characters or if it contains non-portable
-- characters.
toLinkTarget :: MonadThrow m => FilePath -> m LinkTarget
toLinkTarget path | length path <= 100 = do
target <- toLinkTarget' path
pure $! LinkTarget (packAscii target)
| otherwise = throwM (TooLong path)
toLinkTarget :: FilePath -> Maybe LinkTarget
toLinkTarget path
| length path <= 100 = do
target <- toLinkTarget' path
Just $! LinkTarget (packAscii target)
| otherwise = Nothing

data LinkTargetException = IsAbsolute FilePath
| TooLong FilePath
Expand All @@ -505,10 +504,10 @@ instance Exception LinkTargetException where

-- | Convert a native 'FilePath' to a unix filepath suitable for
-- using as 'LinkTarget'. Does not error if longer than 100 characters.
toLinkTarget' :: MonadThrow m => FilePath -> m FilePath
toLinkTarget' :: FilePath -> Maybe FilePath
toLinkTarget' path
| FilePath.Native.isAbsolute path = throwM (IsAbsolute path)
| otherwise = pure $ adjustDirectory $ FilePath.Posix.joinPath $ FilePath.Native.splitDirectories path
| FilePath.Native.isAbsolute path = Nothing
| otherwise = Just $ adjustDirectory $ FilePath.Posix.joinPath $ FilePath.Native.splitDirectories path
where
adjustDirectory | FilePath.Native.hasTrailingPathSeparator path
= FilePath.Posix.addTrailingPathSeparator
Expand Down
7 changes: 3 additions & 4 deletions tar.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ library

library tar-internal
default-language: Haskell2010
build-depends: base >= 4.11.0.0 && < 5,
build-depends: base >= 4.11 && < 5,
array < 0.6,
bytestring >= 0.10 && < 0.13,
containers >= 0.2 && < 0.8,
deepseq >= 1.1 && < 1.6,
directory >= 1.3.1 && < 1.4,
exceptions,
filepath < 1.5,
time < 1.13

Expand Down Expand Up @@ -88,7 +87,7 @@ library tar-internal
test-suite properties
type: exitcode-stdio-1.0
default-language: Haskell2010
build-depends: base,
build-depends: base < 5,
array,
bytestring >= 0.10,
containers,
Expand Down Expand Up @@ -131,7 +130,7 @@ benchmark bench
default-language: Haskell2010
hs-source-dirs: bench
main-is: Main.hs
build-depends: base,
build-depends: base < 5,
tar,
bytestring >= 0.10,
filepath,
Expand Down

0 comments on commit 6dd1a8d

Please sign in to comment.