Skip to content

Commit

Permalink
Migrate LinkTarget to PosixPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Dec 19, 2023
1 parent dfc8fc4 commit c2c70ce
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Codec/Archive/Tar/LongNames.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ encodeLinkPath
encodeLinkPath lnk = case toTarPath' lnk of
FileNameEmpty -> (Nothing, LinkTarget mempty)
FileNameOK (TarPath name prefix)
| PS.null prefix -> (Nothing, LinkTarget $ posixToByteString name)
| otherwise -> (Just $ longSymLinkEntry lnk, LinkTarget $ posixToByteString name)
| PS.null prefix -> (Nothing, LinkTarget name)
| otherwise -> (Just $ longSymLinkEntry lnk, LinkTarget name)
FileNameTooLong (TarPath name _) ->
(Just $ longSymLinkEntry lnk, LinkTarget $ posixToByteString name)
(Just $ longSymLinkEntry lnk, LinkTarget name)

-- | Translate low-level entries (usually freshly deserialized) into
-- high-level entries with POSIX 'FilePath's for files and symlinks
Expand Down
4 changes: 2 additions & 2 deletions Codec/Archive/Tar/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ getEntryStreaming getN getAll = do
entryContent = case typecode of
'\0' -> NormalFile content size
'0' -> NormalFile content size
'1' -> HardLink (LinkTarget linkname)
'2' -> SymbolicLink (LinkTarget linkname)
'1' -> HardLink (LinkTarget $ byteToPosixString linkname)
'2' -> SymbolicLink (LinkTarget $ byteToPosixString linkname)
_ | format == V7Format
-> OtherEntryType typecode content size
'3' -> CharacterDevice devmajor devminor
Expand Down
10 changes: 5 additions & 5 deletions Codec/Archive/Tar/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ splitLongPath path = case reverse (FilePath.Posix.splitPath path) of
-- | The tar format allows just 100 ASCII characters for the 'SymbolicLink' and
-- 'HardLink' entry types.
--
newtype LinkTarget = LinkTarget BS.ByteString
newtype LinkTarget = LinkTarget PosixString
deriving (Eq, Ord, Show)

instance NFData LinkTarget where
Expand All @@ -508,7 +508,7 @@ toLinkTarget :: FilePath -> Maybe LinkTarget
toLinkTarget path
| length path <= 100 = do
target <- toLinkTarget' path
Just $! LinkTarget (packAscii target)
Just $! LinkTarget (toPosixString target)
| otherwise = Nothing

data LinkTargetException = IsAbsolute FilePath
Expand All @@ -532,16 +532,16 @@ toLinkTarget' path

-- | Convert a tar 'LinkTarget' to a native 'FilePath'.
fromLinkTarget :: LinkTarget -> FilePath
fromLinkTarget (LinkTarget pathbs) = fromFilePathToNative $ BS.Char8.unpack pathbs
fromLinkTarget (LinkTarget pathbs) = fromFilePathToNative $ fromPosixString pathbs

-- | Convert a tar 'LinkTarget' to a Unix\/POSIX 'FilePath' (@\'/\'@ path separators).
fromLinkTargetToPosixPath :: LinkTarget -> FilePath
fromLinkTargetToPosixPath (LinkTarget pathbs) = BS.Char8.unpack pathbs
fromLinkTargetToPosixPath (LinkTarget pathbs) = fromPosixString pathbs

-- | Convert a tar 'LinkTarget' to a Windows 'FilePath' (@\'\\\\\'@ path separators).
fromLinkTargetToWindowsPath :: LinkTarget -> FilePath
fromLinkTargetToWindowsPath (LinkTarget pathbs) =
fromFilePathToWindowsPath $ BS.Char8.unpack pathbs
fromFilePathToWindowsPath $ fromPosixString pathbs

-- | Convert a unix FilePath to a native 'FilePath'.
fromFilePathToNative :: FilePath -> FilePath
Expand Down
2 changes: 1 addition & 1 deletion Codec/Archive/Tar/Write.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ putHeaderNoChkSum Entry {
, putOct 12 modTime
, replicate 8 ' ' -- dummy checksum
, putChar8 typeCode
, putBString 100 linkTarget
, putPosixString 100 linkTarget
] ++
case format of
V7Format ->
Expand Down

0 comments on commit c2c70ce

Please sign in to comment.