úÎvåk±r      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopq Safe+NrCA list of key value pairs. The keys must be distinct and non-empty.s7A compact mapping from sequences of small nats to nats.t Build an sC from a bunch of (key, value) pairs, where the keys are sequences.$uvwrxyz{|}~€s‚ƒ„…†‡tˆ‰Š‹ŒŽ‘’“”•€s‚t‰uvwrxyz{|}~€s‚ƒ„…†‡tˆ‰Š‹ŒŽ‘’“”•Safe+–=An effecient mapping from strings to a dense set of integers.—_Look up a string in the token table. If the string is present, return its corresponding index.˜<Given the index of a string in the table, return the string.™%Given a list of strings, construct a –3 mapping those strings to a dense set of integers.–š—›˜™–š—˜™–š—›˜™–(c) 2007 Bjorn Bringert, 2008 Andrea Vezzosi, 2008-2009 Duncan Coutts 2011 Max BolingbrokeBSD3duncan@community.haskell.orgportableSafe('A tar archive is a sequence of entries.ÃThe point of this type as opposed to just using a list is that it makes the failure case explicit. We need this because the sequence of entries we get from reading a tarball can include errors.—It is a concrete data type so you can manipulate it directly but it is often clearer to use the provided functions for mapping, folding and unfolding.-Converting from a list can be done with just foldr Next Done0. Converting back into a list can be done with 7: however in that case you must be prepared to handle the  case inherent in the  type.The œI instance lets you concatenate archives or append entries to an archive.8The tar format allows just 100 ASCII characters for the  and  entry types.ÕThe classic tar format allowed just 100 characters for the file name. The USTAR format extended this with an extra 155 characters, however it uses a complex method of splitting the name between the two sections.ÿÁInstead of just putting any overflow into the extended area, it uses the extended area as a prefix. The aggravating insane bit however is that the prefix (if any) must only contain a directory prefix. That is the split between the two areas must be on a directory separator boundary. So there is no simple calculation to work out if a file name is too long. Instead we have to try to find a valid split that makes the name fit in the two areas.ÿbThe rationale presumably was to make it a bit more compatible with old tar programs that only understand the classic format. A classic tar would be able to extract the file name and possibly some dir prefix, but not the full dir prefix. So the files would end up in the wrong place, but that's probably better than ending up with the wrong names too.+So it's understandable but rather annoying.Tar paths use Posix format (ie '/'F directory separators), irrespective of the local path conventions.7The directory separator between the prefix and name is not stored.«There have been a number of extensions to the tar file format over the years. They all share the basic entry fields and put more meta-data in different extended headers.ŽThis is the classic Unix V7 tar format. It does not support owner and group names, just numeric Ids. It also does not support device numbers.œThe "USTAR" format is an extension of the classic V7 format. It was later standardised by POSIX. It has some restrictions but is the most portable format. ¿The GNU tar implementation also extends the classic V7 format, though in a slightly different way from the USTAR format. In general for new archives the standard USTAR/POSIX should be used. &The owner user name. Should be set to "" if unknown. 'The owner group name. Should be set to "" if unknown.(Numeric owner user id. Should be set to 0 if unknown.)Numeric owner group id. Should be set to 0 if unknown.GThe content of a tar archive entry, which depends on the type of entry.&Portable archives should contain only  and .Tar archive entry.[The path of the file or directory within the archive. This is in a tar-specific form. Use ' to get a native .#The real content of the entry. For ; this includes the file data. An entry usually contains a  or a .(File permissions (Unix style file mode)..The user and group to which this file belongs.$The time the file was last modified. $The tar format the archive is using.%*The number of seconds since the UNIX epoch'Native - of the file or directory within the archive.( rw-r--r-- for normal files) rwxr-xr-x for executable files* rwxr-xr-x for directories+An j with all default values except for the file name and type. It uses the portable USTAR/POSIX format (see  UstarHeader).=You can use this as a basis and override specific fields, eg: 2(emptyEntry name HardLink) { linkTarget = target },A tar  for a file.IEntry fields such as file permissions and ownership have default values.tYou can use this as a basis and override specific fields. For example if you need an executable file you could use: :(fileEntry name content) { fileMode = executableFileMode }-A tar  for a directory.HEntry fields such as file permissions and ownership have default values.. Convert a  to a native . The native p will use the native directory separator but it is not otherwise checked for validity or sanity. In particular:?The tar path may be invalid as a native path, eg the file name "nul" is not valid on Windows.4The tar path may be an absolute path or may contain ".."’ components. For security reasons this should not usually be allowed, but it is your responsibility to check for these conditions (eg using  checkSecurity)./ Convert a  to a Unix/Posix .The difference compared to .[ is that it always returns a Unix style path irrespective of the current operating system.This is useful to check how a X would be interpreted on a specific operating system, eg to perform portability checks.0 Convert a  to a Windows . The only difference compared to .^ is that it always returns a Windows style path irrespective of the current operating system.This is useful to check how a X would be interpreted on a specific operating system, eg to perform portability checks.1Convert a native  to a .The conversion may fail if the  is too long. See 7 for a description of the problem with splitting long s.žqTake a sanitised path, split on directory separators and try to pack it into the 155 + 100 tar file name format.ÜThe strategy is this: take the name-directory components in reverse order and try to fit as many components into the 100 long name area as possible. If all the remaining components fit in the 155 name area then we win.2Convert a native  to a tar h. This may fail if the string is longer than 100 characters or if it contains non-portable characters.3Convert a tar  to a native .4Convert a tar  to a Unix/Posix .5Convert a tar  to a Windows .6This is like the standard unfoldr function on lists, but for U. It includes failure as an extra possibility that the stepper function may return.It can be used to generate Z from some other type. For example it is used internally to lazily unfold entries from a Ÿ.7This is like the standard   function on lists, but for . Compared to  G it takes an extra function to account for the possibility of failure.“This is used to consume a sequence of entries. For example it could be used to scan a tarball for problems or to collect an index of the contents.8This is like the standard ¡ function on lists, but for K. It includes failure as a extra possible outcome of the mapping function.GIf your mapping function cannot fail it may be more convenient to use 99Like 8- but the mapping function itself cannot fail.?¢£  !"#$%&'()*+,-./01GIs the path for a directory? This is needed because for directories a  must always use a trailing /.ž23456789¤¥<¢£  !"#$%&'()*+,-./0123456789#¢£   !"#$%&'()*+,-./01ž23456789¤¥—(c) 2007 Bjorn Bringert, 2008 Andrea Vezzosi, 2008-2009 Duncan Coutts, 2011 Max BolingbrokeBSD3duncan@community.haskell.orgportableSafe+::Errors that can be encountered when parsing a Tar archive.CsConvert a data stream in the tar file format into an internal data structure. Decoding errors are reported by the  constructor of the  type.The conversion is done lazily.¦§¨:;<=>?@ABC©ª«¬­®¯°±²³´µ :;<=>?@ABC¦§¨:;<=>?@ABC©ª«¬­®¯°±²³´µ m(c) 2007 Bjorn Bringert, 2008 Andrea Vezzosi, 2008-2009 Duncan CouttsBSD3duncan@community.haskell.orgportableSafeDZCreate the external representation of a tar archive by serialising a list of tar entries.The conversion is done lazily. ¶D·¸¹º»¼½D ¶D·¸¹º»¼½ m(c) 2007 Bjorn Bringert, 2008 Andrea Vezzosi, 2008-2009 Duncan CouttsBSD3duncan@community.haskell.orgportableNoneEÆCreates a tar archive from a list of directory or files. Any directories specified will have their contents included recursively. Paths in the archive will be relative to the given base directory.oThis is a portable implementation of packing suitable for portable archives. In particular it only constructs  and ð entries. Hard links and symbolic links are treated like ordinary files. It cannot be used to pack directories containing recursive symbolic links. Special files like FIFOs (named pipes), sockets or device files will also cause problems.TAn exception will be thrown for any file names that are too long to represent as a .ƒThis function returns results lazily. Subdirectories are scanned and files are read one by one as the list of entries is consumed.FConstruct a tar  based on a local file.ÚThis sets the entry size, the data contained in the file and the file's modification time. If the file is executable then that information is also preserved. File ownership and detailed permissions are not preserved.!The file contents is read lazily.GConstruct a tar 3 based on a local directory (but not its contents).‹The only attribute of the directory that is used is its modification time. Directory ownership and detailed permissions are not preserved.H&This is a utility function, much like ¾E. The difference is that it includes the contents of subdirectories.‰The paths returned are all relative to the top directory. Directory paths are distinguishable by having a trailing path separator (see ¿).ÿWAll directories are listed before the files that they contain. Amongst the contents of a directory, subdirectories are listed after normal files. The overall result is that files within a directory will be together in a single contiguous group. This tends to improve file layout and IO performance when creating or extracting tar archives.‰This function returns results lazily. Subdirectories are not scanned until the files entries in the parent directory have been consumed. EBase directory7Files and directories to pack, relative to the base dirÀÁÂF,Full path to find the file on the local disk,Path to use for the tar Entry in the archiveG,Full path to find the file on the local disk,Path to use for the tar Entry in the archiveHÃÄEFGH EÀÁÂFGHÃÄ(c) 2010-2015 Duncan CouttsBSD3duncan@community.haskell.orgportableNone+CGI=The intermediate type used for incremental construction of a N.J!An offset within a tar file. Use X, Y or Z.:This is actually a tar "record" number, not a byte offset.KThe result of O in a NÖ. It can either be a file directly, or a directory entry containing further entries (and all subdirectories recursively). Note that the subtrees are constructed lazily, so it's cheaper if you don't look at them.N&An index of the entries in a tar file.cThis index type is designed to be quite compact and suitable to store either on disk or in memory.O Look up a given filepath in the N. It may return a L containing the J_ of the file within the tar file, or if the filepath identifies a directory then it returns a M5 containing the list of files within that directory. Given the J, you can then use one of the I/O operations:X to read the whole entry;Y2 to read just the file metadata (e.g. its length);PBuild a N from a sequence of tar . The ! are assumed to start at offset 0 within a file.QThe initial empty I.R Add the next  into the I.SRUse this function if you want to skip some entries and not add them to the final N.TFinish accumulating # information and build the compact N lookup structure.UOThis is the offset immediately following the entry most recently added to the IP. You might use this if you need to know the offsets but don't want to use the N lookup structure. Use with Z . See also W.V”This is the offset immediately following the last entry in the tar file. This can be useful to append further entries into the tar file. Use with Z, or just use ] directly.WCalculate the JD of the next entry, given the size and offset of the current entry.This is much like using S and U, but without using an I.XReads an entire  at the given J in the tar file. The Å* must be open for reading and be seekable.[This reads the whole entry into memory strictly, not incrementally. For more control, use Y* and then read the entry content manually.YRead the header for a  at the given J in the tar file. The C will contain the correct metadata but an empty file content. The Å* must be open for reading and be seekable.The ÅZ position is advanced to the beginning of the entry content (if any). You must check the ! to see if the entry is of type . If it is, the L gives the content length and you are free to read this much data from the Å. œentry <- Tar.hReadEntryHeader hnd case Tar.entryContent entry of Tar.NormalFile _ size -> do content <- BS.hGet hnd size ...6Of course you don't have to read it all in one go (as XE does), you can use any appropriate method to read it incrementally.,In addition to I/O errors, this can throw a :A if the offset is wrong, or if the file is not valid tar format.(There is also the lower level operation Z.ZSet the Å6 position to the position corresponding to the given J.ºThis position is where the entry metadata can be read. If you already know the entry has a body (and perhaps know it's length), you may wish to seek to the body content directly using [.[Set the ÅD position to the entry content position corresponding to the given J. This position is where the entry content can be read using ordinary I/O operations (though you have to know in advance how big the entry content is). This is  only valid if you  already know/ the entry has a body (i.e. is a normal file).\This is a low level variant on YB, that can be used to iterate through a tar file, entry by entry.%It has a few differences compared to Y:AIt returns an indication when the end of the tar file is reached.It does not move the Å3 position to the beginning of the entry content.It returns the J of the next entry.After this action, the ÅW position is not in any useful place. If you want to skip to the next entry, take the J returned and use \# again. Or if having inspected the F header you want to read the entry content (if it has one) then use [ on the original input J.]cSeek to the end of a tar file, to the position where new entries can be appended, and return that J.If you have a valid Ni for this tar file then you should supply it because it allows seeking directly to the correct location.ÿ—If you do not have an index, then this becomes an expensive linear operation because we have to read each tar entry header from the beginning to find the location immediately after the last entry (this is because tar files have a variable length trailer and we cannot reliably find that by starting at the end). In this mode, it will fail with an exception if the file is not in fact in the tar format.^The NO is compact in memory, and it has a similarly compact external representation._-Read the external representation back into a N."IÆJÇÈKLMNÉOÊËPQRSTUVWXYZ[\]^_ÌÍÎÏÐIJKLMNOPQRSTUVWXYZ[\]^_NOKLMJXYPIQRST^_\Z[]WVUIÆJÇÈKLMNÉOÊËPQRSTUVWXYZ[\]^_ÌÍÎÏÐD(c) 2008-2012 Duncan Coutts 2011 Max BolingbrokeBSD3duncan@community.haskell.orgportableSafe+`9The name of a platform that portability issues arise froma%Portability problems in a tar archivefoAn error that occurs if a tar file is a "tar bomb" that would extract files outside of the intended directory.hIErrors arising from tar file names being in some way invalid or dangerousk`This function checks a sequence of tar entries for file name security problems. It checks that:file paths are not absolute8file paths do not contain any path components that are ".."file names are validSThese checks are from the perspective of the current OS. That means we check for "C:blahG" files on Windows and "/blah" files on Unix. For archive entry types  and y the same checks are done for the link target. A failure in any entry terminates the sequence of entries with an error.lÿThis function checks a sequence of tar entries for being a "tar bomb". This means that the tar file does not follow the standard convention that all entries are within a single subdirectory, e.g. a file "foo.tar" would usually have all entries within the "foo/" subdirectory.`Given the expected subdirectory, this function checks all entries are within that subdirectroy.2Note: This check must be used in conjunction with k (or m).mhThis function checks a sequence of tar entries for a number of portability issues. It will complain if:~The old "Unix V7" or "gnu" formats are used. For maximum portability only the POSIX standard "ustar" format should be used.ÆA non-portable entry type is used. Only ordinary files, hard links, symlinks and directories are portable. Device files, pipes and others are not portable between all common operating systems.¥Non-ASCII characters are used in file names. There is no agreed portable convention for Unicode or other extended character sets in file names in tar archives.·File names that would not be portable to both Unix and Windows. This check includes characters that are valid in both systems and the '/' vs '\' directory separator conventions.`abcdefghijkÑÒlÓmÔÕÖרÙÚÛ`abcdefghijklmkhijlfgmabcde``abcdefghijkÑÒlÓmÔÕÖרÙÚÛ m(c) 2007 Bjorn Bringert, 2008 Andrea Vezzosi, 2008-2009 Duncan CouttsBSD3duncan@community.haskell.orgportableSafenICreate local files and directories based on the entries of a tar archive.[This is a portable implementation of unpacking suitable for portable archives. It handles  and ( entries and has simulated support for  and Ì entries. Links are implemented by copying the target file. This therefore works on Windows as well as Unix. All other entry types are ignored, that is they are not unpacked and no exception is raised.If the ÿ ends in an error then it is raised an an exception. Any files or directories that have been unpacked before the error was encountered will not be deleted. For this reason you may want to unpack into an empty directory so that you can easily clean up if unpacking fails part-way.:On its own, this function only checks for security (using kB). You can do other checks by applying checking functions to the . that you pass to this function. For example: -unpack dir (checkTarbomb expectedDir entries)PIf you care about the priority of the reported errors then you may want to use k before l or other checks.nnnm(c) 2007 Bjorn Bringert, 2008 Andrea Vezzosi, 2008-2009 Duncan CouttsBSD3duncan@community.haskell.orgportableNone5  !"#$%&'()*+,-./012345FGH5 ' &!%$#" +,-()*FGH1./02345m(c) 2007 Bjorn Bringert, 2008 Andrea Vezzosi, 2008-2012 Duncan CouttsBSD3duncan@community.haskell.orgportableNoneo Create a new ".tar" file from a directory of files.)It is equivalent to calling the standard tar program like so: #$ tar -f tarball.tar -C base -c dirThis assumes a directory  ./base/dir with files inside, eg ./base/dir/foo.txtD. The file names inside the resulting tar file will be relative to dir, eg  dir/foo.txt.”This is a high level "all in one" operation. Since you may need variations on this function it is instructive to see how it is written. It is just: 4BS.writeFile tar . Tar.write =<< Tar.pack base pathsNotes:cThe files and directories must not change during this operation or the result is not well defined._The intention of this function is to create tarballs that are portable between systems. It is notÅ suitable for doing file system backups because file ownership and permissions are not fully preserved. File ownership is not preserved at all. File permissions are set to simple portable values: rw-r--r-- for normal files rwxr-xr-x for executable files rwxr-xr-x for directoriesp%Extract all the files contained in a ".tar" file.)It is equivalent to calling the standard tar program like so: $ tar -x -f tarball.tar -C dirSo for example if the  tarball.tar file contains  foo/bar.txt then this will extract it to dir/foo/bar.txt.”This is a high level "all in one" operation. Since you may need variations on this function it is instructive to see how it is written. It is just: -Tar.unpack dir . Tar.read =<< BS.readFile tarNotes:ÊExtracting can fail for a number of reasons. The tarball may be incorrectly formatted. There may be IO or permission errors. In such cases an exception will be thrown and extraction will not continue.ÂSince the extraction may fail part way through it is not atomic. For this reason you may want to extract into an empty directory and, if the extraction fails, recursively delete the directory.ÛSecurity: only files inside the target directory will be written. Tarballs containing entries that point outside of the tarball (either absolute paths or relative paths) will be caught and an exception will be thrown.qAppend new entries to a ".tar" file from a directory of files.This is much like o‘, except that all the entries are added to the end of an existing tar file. Or if the file does not already exists then it behaves the same as o.o!Path of the ".tar" file to write.Base directory6Files and directories to archive, relative to base dirpDestination directoryTarballq!Path of the ".tar" file to write.Base directory6Files and directories to archive, relative to base dir$'6789:;<=>?@ABCDEnopq%opqCDEn'8976:;<=>?@ABopqÜ   !"#$$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM N O P Q RSTUVWXYZ[\]^_`abcdefghijklmnoppqrstuv wxyz{|}~~€€‚ƒ„…†$…|‡ˆ‰Š‹ŒYŽ‘’“”•–—˜™Yš}™›œžœŸ ¡¢£¤œ¥¦œ§¨©ª«¬­®¯°±²³´µ¶·¸¹ º » ¼ ½ ¾ ¿ À ÁÂÃÄÅÆÇ È É Ê Ë ÌœÍÎSÏÏXÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâtar_KU6oB9CmvI4BVKeLzCVbudCodec.Archive.TarCodec.Archive.Tar.EntryCodec.Archive.Tar.IndexCodec.Archive.Tar.CheckCodec.Archive.Tar.Index.IntTrie#Codec.Archive.Tar.Index.StringTableCodec.Archive.Tar.TypesCodec.Archive.Tar.ReadCodec.Archive.Tar.WriteCodec.Archive.Tar.PackCodec.Archive.Tar.UnpackEntriesNextDoneFail LinkTargetTarPathFormatV7Format UstarFormat GnuFormat Ownership ownerName groupNameownerIdgroupId EntryContent NormalFile Directory SymbolicLinkHardLinkCharacterDevice BlockDevice NamedPipeOtherEntryTypeEntry entryTarPath entryContententryPermissionsentryOwnership entryTime entryFormat PermissionsTypeCodeDevMinorDevMajor EpochTimeFileSize entryPathordinaryFilePermissionsexecutableFilePermissionsdirectoryPermissions simpleEntry fileEntrydirectoryEntry fromTarPathfromTarPathToPosixPathfromTarPathToWindowsPath toTarPath toLinkTargetfromLinkTargetfromLinkTargetToPosixPathfromLinkTargetToWindowsPath unfoldEntries foldEntries mapEntriesmapEntriesNoFail FormatErrorTruncatedArchive ShortTrailer BadTrailer TrailingJunkChecksumIncorrect NotTarFormatUnrecognisedTarFormatHeaderBadNumericEncodingreadwritepack packFileEntrypackDirectoryEntrygetDirectoryContentsRecursive IndexBuilderTarEntryOffset TarIndexEntry TarFileEntryTarDirTarIndexlookupbuild emptyIndex addNextEntry skipNextEntry finaliseIndexindexNextEntryOffsetindexEndEntryOffsetnextEntryOffset hReadEntryhReadEntryHeaderhSeekEntryOffsethSeekEntryContentOffsethReadEntryHeaderOrEofhSeekEndEntryOffset serialise deserialisePortabilityPlatformPortabilityErrorNonPortableFormatNonPortableFileTypeNonPortableEntryNameCharNonPortableFileName TarBombError FileNameErrorInvalidFileNameAbsoluteFileName checkSecurity checkTarbombcheckPortabilityunpackcreateextractappendPathsIntTrie constructQOffsetTrieTrieF TrieNodeFLeafNode Completions TrieLookuptagLeaftagNodeuntagisNodecompletionsFrommkArray enumToWord32 word32ToEnumunfoldTrieNode unfoldTriemkTrie flattenTriequeueenqueuedequeue int2Word32 enum2Word32$fFunctorTrieNodeF StringTableindexindex'baseGHC.BaseMonoidGHC.IOFilePath splitLongPathbytes_6elQVSg5cWdFrvRnfxTUrHData.ByteString.Lazy.Internal ByteString Data.Foldablefoldrmap$fFunctorEntries$fMonoidEntriesPartialErrorOkgetEntrycorrectChecksumgetOctgetBytesgetBytegetChars getStringpartial$fMonadPartial$fApplicativePartial$fFunctorPartial$fExceptionFormatError$fShowFormatError FieldWidthputEntry putHeaderputHeaderNoChkSum putStringputOctputChar8filldirec_KowvXytSqazBcvN7MGpFtgSystem.DirectorygetDirectoryContentsfilep_KsGE6pHE5eZHSN90ZVax6ASystem.FilePath.PosixhasTrailingPathSeparator preparePaths packPaths interleaverecurseDirectories getModTimeGHC.IO.Handle.TypesHandlePathComponentIdtoComponentIdsfromComponentIdserialiseIntTriedeserialiseIntTrieserialiseStringTabledeserialiseStringTable readWord32BEcheckEntrySecurityshowFileNameErrorcheckEntryTarbombcheckEntryPortability checkEntries$fShowPortabilityError$fExceptionPortabilityError$fShowTarBombError$fExceptionTarBombError$fExceptionFileNameError$fShowFileNameError