-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Reading, writing and manipulating ".tar" archive files. -- -- This library is for working with ".tar" archive files. It can -- read and write a range of common variations of archive format -- including V7, USTAR, POSIX and GNU formats. It provides support for -- packing and unpacking portable archives. This makes it suitable for -- distribution but not backup because details like file ownership and -- exact permissions are not preserved. @package tar @version 0.3.2.0 -- | Perform various checks on tar file entries. module Codec.Archive.Tar.Check -- | This function checks a sequence of tar entries for file name security -- problems. It checks that: -- --
-- import qualified Codec.Archive.Tar as Tar -- import qualified Codec.Archive.Tar.Entry as Tar --module Codec.Archive.Tar.Entry -- | Tar archive entry. data Entry Entry :: !TarPath -> !EntryContent -> !Permissions -> !Ownership -> !EpochTime -> !Format -> Entry -- | The path of the file or directory within the archive. This is in a -- tar-specific form. Use entryPath to get a native -- FilePath. entryTarPath :: Entry -> !TarPath -- | The real content of the entry. For NormalFile this includes the -- file data. An entry usually contains a NormalFile or a -- Directory. entryContent :: Entry -> !EntryContent -- | File permissions (Unix style file mode). entryPermissions :: Entry -> !Permissions -- | The user and group to which this file belongs. entryOwnership :: Entry -> !Ownership -- | The time the file was last modified. entryTime :: Entry -> !EpochTime -- | The tar format the archive is using. entryFormat :: Entry -> !Format -- | Native FilePath of the file or directory within the archive. entryPath :: Entry -> FilePath -- | The content of a tar archive entry, which depends on the type of -- entry. -- -- Portable archives should contain only NormalFile and -- Directory. data EntryContent NormalFile :: ByteString -> !FileSize -> EntryContent Directory :: EntryContent SymbolicLink :: !LinkTarget -> EntryContent HardLink :: !LinkTarget -> EntryContent CharacterDevice :: !DevMajor -> !DevMinor -> EntryContent BlockDevice :: !DevMajor -> !DevMinor -> EntryContent NamedPipe :: EntryContent OtherEntryType :: !TypeCode -> ByteString -> !FileSize -> EntryContent data Ownership Ownership :: String -> String -> !Int -> !Int -> Ownership -- | The owner user name. Should be set to "" if unknown. ownerName :: Ownership -> String -- | The owner group name. Should be set to "" if unknown. groupName :: Ownership -> String -- | Numeric owner user id. Should be set to 0 if unknown. ownerId :: Ownership -> !Int -- | Numeric owner group id. Should be set to 0 if unknown. groupId :: Ownership -> !Int type FileSize = Int64 type Permissions = FileMode -- | The number of seconds since the UNIX epoch type EpochTime = Int64 type DevMajor = Int type DevMinor = Int type TypeCode = Char -- | 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. data Format -- | 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. V7Format :: Format -- | 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. UstarFormat :: 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. GnuFormat :: Format -- | An Entry 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: -- --
-- (emptyEntry name HardLink) { linkTarget = target }
--
simpleEntry :: TarPath -> EntryContent -> Entry
-- | A tar Entry for a file.
--
-- Entry fields such as file permissions and ownership have default
-- values.
--
-- You 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 }
--
fileEntry :: TarPath -> ByteString -> Entry
-- | A tar Entry for a directory.
--
-- Entry fields such as file permissions and ownership have default
-- values.
directoryEntry :: TarPath -> Entry
-- | rw-r--r-- for normal files
ordinaryFilePermissions :: Permissions
-- | rwxr-xr-x for executable files
executableFilePermissions :: Permissions
-- | rwxr-xr-x for directories
directoryPermissions :: Permissions
-- | Construct a tar Entry 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.
--
-- -- import qualified Codec.Archive.Tar as Tar --module Codec.Archive.Tar -- | 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 dir ---- -- This assumes a directory ./base/dir with files inside, eg -- ./base/dir/foo.txt. 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: -- --
-- BS.writeFile tar . Tar.write =<< Tar.pack base paths ---- -- Notes: -- -- The 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: -- --
-- $ tar -x -f tarball.tar -C dir ---- -- So 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 tar ---- -- Notes: -- -- 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. extract :: FilePath -> FilePath -> IO () -- | Convert a data stream in the tar file format into an internal data -- structure. Decoding errors are reported by the Fail constructor -- of the Entries type. -- --
-- unpack dir (checkTarbomb expectedDir entries) ---- -- If you care about the priority of the reported errors then you may -- want to use checkSecurity before checkTarbomb or other -- checks. unpack :: FilePath -> Entries -> IO () -- | Tar archive entry. data Entry -- | Native FilePath of the file or directory within the archive. entryPath :: Entry -> FilePath -- | The real content of the entry. For NormalFile this includes the -- file data. An entry usually contains a NormalFile or a -- Directory. entryContent :: Entry -> EntryContent -- | The content of a tar archive entry, which depends on the type of -- entry. -- -- Portable archives should contain only NormalFile and -- Directory. data EntryContent NormalFile :: ByteString -> !FileSize -> EntryContent Directory :: EntryContent SymbolicLink :: !LinkTarget -> EntryContent HardLink :: !LinkTarget -> EntryContent CharacterDevice :: !DevMajor -> !DevMinor -> EntryContent BlockDevice :: !DevMajor -> !DevMinor -> EntryContent NamedPipe :: EntryContent OtherEntryType :: !TypeCode -> ByteString -> !FileSize -> EntryContent -- | 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 Done. -- Converting back into a list can be done with foldEntries -- however in that case you must be prepared to handle the Fail -- case inherent in the Entries type. -- -- The Monoid instance lets you concatenate archives or append -- entries to an archive. data Entries Next :: Entry -> Entries -> Entries Done :: Entries Fail :: String -> Entries -- | This is like the standard map function on lists, but for -- Entries. It includes failure as a extra possible outcome of the -- mapping function. mapEntries :: (Entry -> Either String Entry) -> Entries -> Entries -- | This is like the standard foldr function on lists, but for -- Entries. Compared to foldr 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. foldEntries :: (Entry -> a -> a) -> a -> (String -> a) -> Entries -> a -- | This is like the standard unfoldr function on lists, but for -- Entries. It includes failure as an extra possibility that the -- stepper function may return. -- -- It can be used to generate Entries from some other type. For -- example it is used internally to lazily unfold entries from a -- ByteString. unfoldEntries :: (a -> Either String (Maybe (Entry, a))) -> a -> Entries