jgm/zip-archive

Module : Codec.Archive.Zip - extractFilesFromArchive error with special characters in filenames for Windows

Opened this issue · 4 comments

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)
jgm commented

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
#24 (comment).

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

jgm commented

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
#24 (comment).

Let's try to handle the attached zip archives with Codec.Archive.Zip
This would raise errors.