zip-archive
zip-archive copied to clipboard
Module : Codec.Archive.Zip - extractFilesFromArchive error with special characters in filenames for Windows
Thereafter a patch to manage special character the same way than for an url :
import Storage.URL( encString )
import Data.Char( isAlpha, isAscii, isDigit )
-- | Writes contents of an 'Entry' to a file.
writeEntry :: [ZipOption] -> Entry -> IO ()
writeEntry opts entry = do
let path = case [d | OptDestination d <- opts] of
(x:_) -> x </> eRelativePath entry
_ -> eRelativePath entry
-- create directories if needed
let dir = takeDirectory path
exists <- doesDirectoryExist dir
unless exists $ do
createDirectoryIfMissing True dir
when (OptVerbose `elem` opts) $
hPutStrLn stderr $ " creating: " ++ dir
if length path > 0 && last path == '/' -- path is a directory
then return ()
else do
when (OptVerbose `elem` opts) $ do
hPutStrLn stderr $ case eCompressionMethod entry of
Deflate -> " inflating: " ++ path
NoCompression -> "extracting: " ++ path
+ #ifdef _WINDOWS
+ let encPath = (encString False (\x -> (isAscii x && isAlpha x) || isDigit x || (elem x "_-. /~")) path)
+ B.writeFile encPath (fromEntry entry)
+ #else
+ B.writeFile path (fromEntry entry)
+ #endif
-- Note that last modified times are supported only for POSIX, not for
-- Windows.
setFileTimeStamp path (eLastModified entry)
Sorry, I've lost the context for this. Can you explain what problem this is supposed to solve?
Le 07/08/2015 21:23, John MacFarlane a écrit :
Sorry, I've lost the context for this. Can you explain what problem this is supposed to solve?
— Reply to this email directly or view it on GitHub https://github.com/jgm/zip-archive/issues/24#issuecomment-128801045.
Thank you for looking my patch
Windows filename have non valid characters like /:*?
but those characters are valid for unix filename.
It is possible to decompress zip archives from unix to windows and my patch is a proposal to manage non valid charset in filename.
I discovered this issue when trying to decompress an zip archive with a filename containing an EOL (\n) character
best regards
Is it really the case that Windows can't handle non-ascii letters in filenames? THat would surprise me.
Le 08/08/2015 22:20, John MacFarlane a écrit :
Is it really the case that Windows can't handle non-ascii letters in filenames? THat would surprise me.
— Reply to this email directly or view it on GitHub https://github.com/jgm/zip-archive/issues/24#issuecomment-129042456.
Let's try to handle the attached zip archives with Codec.Archive.Zip This would raise errors.