From 6dd1a8d471adccbebef5283df698590e42496323 Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Sun, 10 Dec 2023 21:58:44 +0000 Subject: [PATCH] Restore return type of toLinkTarget to Maybe LinkTarget for the sake of backward compatibility --- Codec/Archive/Tar/Check/Internal.hs | 1 - Codec/Archive/Tar/Types.hs | 19 +++++++++---------- tar.cabal | 7 +++---- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Codec/Archive/Tar/Check/Internal.hs b/Codec/Archive/Tar/Check/Internal.hs index 47dec72..c6dd30e 100644 --- a/Codec/Archive/Tar/Check/Internal.hs +++ b/Codec/Archive/Tar/Check/Internal.hs @@ -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) diff --git a/Codec/Archive/Tar/Types.hs b/Codec/Archive/Tar/Types.hs index d6825e5..48355fc 100644 --- a/Codec/Archive/Tar/Types.hs +++ b/Codec/Archive/Tar/Types.hs @@ -53,7 +53,6 @@ module Codec.Archive.Tar.Types ( LinkTarget(..), toLinkTarget, - toLinkTarget', fromLinkTarget, fromLinkTargetToPosixPath, fromLinkTargetToWindowsPath, @@ -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 ) @@ -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 @@ -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 diff --git a/tar.cabal b/tar.cabal index 7d83a53..483ad8e 100644 --- a/tar.cabal +++ b/tar.cabal @@ -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 @@ -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, @@ -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,