Skip to content

Commit 0d26f10

Browse files
committed
htar: support listing long file names
1 parent 75f6d6a commit 0d26f10

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Codec/Archive/Tar.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ module Codec.Archive.Tar (
131131
foldlEntries,
132132
unfoldEntries,
133133

134+
-- ** Long file names
135+
encodeLongNames,
136+
decodeLongNames,
137+
DecodeLongNamesError(..),
138+
134139
-- * Error handling
135140
-- | Reading tar files can fail if the data does not match the tar file
136141
-- format correctly.
@@ -146,6 +151,7 @@ module Codec.Archive.Tar (
146151
FormatError(..),
147152
) where
148153

154+
import Codec.Archive.Tar.LongNames
149155
import Codec.Archive.Tar.Types
150156

151157
import Codec.Archive.Tar.Read

Codec/Archive/Tar/LongNames.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Codec.Archive.Tar.LongNames
44
( encodeLongNames
55
, decodeLongNames
6-
, DecodeLongNamesError
6+
, DecodeLongNamesError(..)
77
) where
88

99
import Codec.Archive.Tar.Types

htar/htar.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ main' (Options { optFile = file,
4848
input = if file == "-" then BS.getContents else BS.readFile file
4949
output = if file == "-" then BS.putStr else BS.writeFile file
5050

51+
printEntries :: Tar.Entries Tar.FormatError -> IO ()
5152
printEntries = Tar.foldEntries (\entry rest -> printEntry entry >> rest)
52-
(return ()) throwIO
53+
(return ()) (either throwIO throwIO)
54+
. Tar.decodeLongNames
55+
5356
printEntry = putStrLn . entryInfo verbosity
5457

5558
data Compression = None | GZip | BZip
@@ -70,11 +73,11 @@ data Verbosity = Verbose | Concise
7073
------------------------
7174
-- List archive contents
7275

73-
entryInfo :: Verbosity -> Tar.Entry -> String
76+
entryInfo :: Verbosity -> Tar.GenEntry FilePath FilePath -> String
7477
entryInfo Verbose = detailedInfo
75-
entryInfo Concise = Tar.entryPath
78+
entryInfo Concise = Tar.entryTarPath
7679

77-
detailedInfo :: Tar.Entry -> String
80+
detailedInfo :: Tar.GenEntry FilePath FilePath -> String
7881
detailedInfo entry =
7982
unwords [ typeCode : permissions
8083
, justify 19 (owner ++ '/' : group) size
@@ -111,10 +114,10 @@ detailedInfo entry =
111114
_ -> "0"
112115

113116
time = formatEpochTime "%Y-%m-%d %H:%M" (Tar.entryTime entry)
114-
name = Tar.entryPath entry
117+
name = Tar.entryTarPath entry
115118
link = case Tar.entryContent entry of
116-
Tar.HardLink l -> " link to " ++ Tar.fromLinkTarget l
117-
Tar.SymbolicLink l -> " -> " ++ Tar.fromLinkTarget l
119+
Tar.HardLink l -> " link to " ++ l
120+
Tar.SymbolicLink l -> " -> " ++ l
118121
_ -> ""
119122

120123
justify :: Int -> String -> String -> String

0 commit comments

Comments
 (0)