Commit a31f0242 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Create all parent directories of extraced files

Previously only created the immediate parent directory.
No rely more heavily on the file security check to make
sure we are not writing files outside of the target area.
parent 954176c3
......@@ -434,7 +434,7 @@ checkEntrySecurity entry = case entryContent entry of
where
check name
| FilePath.Native.isAbsolute name
| not (FilePath.Native.isRelative name)
= Just $ "Absolute file name in tar archive: " ++ show name
| not (FilePath.Native.isValid name)
......@@ -720,6 +720,9 @@ unpack baseDir entries = unpackEntries [] (checkSecurity entries)
>>= emulateLinks
where
-- We're relying here on 'checkSecurity' to make sure we're not scribbling
-- files all over the place.
unpackEntries _ (Fail err) = fail err
unpackEntries links Done = return links
unpackEntries links (Next entry es) = case entryContent entry of
......@@ -734,13 +737,16 @@ unpack baseDir entries = unpackEntries [] (checkSecurity entries)
path = entryPath entry
extractFile path content = do
createDirectoryIfMissing False absDir
-- Note that tar archives do not make sure each directory is created
-- before files they contain, indeed we may have to create several
-- levels of directory.
createDirectoryIfMissing True absDir
BS.writeFile absPath content
where
absDir = baseDir </> FilePath.Native.takeDirectory path
absPath = baseDir </> path
extractDir path = createDirectoryIfMissing False (baseDir </> path)
extractDir path = createDirectoryIfMissing True (baseDir </> path)
saveLink path link links = seq (length path)
$ seq (length link')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment