stack sdist does not handle filenames with non-ASCII characters #2549

Closed
snoyberg opened this Issue Aug 31, 2016 · 3 comments

Projects

None yet

2 participants

@snoyberg
Contributor
snoyberg commented Aug 31, 2016 edited

Steps to reproduce

  1. git clone https://github.com/snoyberg/yaml
  2. cd yaml
  3. git checkout yaml/0.8.18.2
  4. stack sdist
  5. Unpack the tarball printed to standard out, e.g. tar xfv .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/yaml-0.8.18.3.tar.gz

Expected

All files unpack correctly.

Actual

I get the following error from tar due to an incorrectly generated tarball:

yaml-0.8.18.3/test/resources/accent?/foo.yaml: Can't create 'yaml-0.8.18.3/test/resources/accent?/foo.yaml'
tar: Error exit delayed from previous errors.

Stack version

$ stack --version
Version 1.1.2, Git revision cebe10e845fed4420b6224d97dcabf20477bbd4b (3646 commits) x86_64 hpack-0.14.0

Method of installation

  • Executable distributed with the Haskell Platform Minimal (no joke)

Related to: snoyberg/yaml#92

@snoyberg
Contributor
snoyberg commented Sep 1, 2016

Possibly helpful snippet of code just using tar that shows some character corruption going on. I'm not sure of the right way to use the tar package for non-ASCII characters:

#!/usr/bin/env stack
-- stack runghc --resolver lts-6.14 --package tar
{-# LANGUAGE OverloadedStrings #-}
import Codec.Archive.Tar
import Codec.Archive.Tar.Entry
import qualified Data.ByteString.Lazy as L
import System.Process
import System.Exit

main :: IO ()
main = do
    let fp = "accenté.txt"
        Right tarPath = toTarPath False fp

    writeFile fp "test1"
    L.writeFile "tarintl.tar" $ write [fileEntry tarPath "test2"]
    rawSystem "tar" ["xfv", "tarintl.tar"] >>= exitWith
@snoyberg
Contributor
snoyberg commented Sep 1, 2016

Hmm, in the Cabal source code I see the following comment, which may explain why it works:

The 'createArchive' action uses the external @tar@ program...

@snoyberg
Contributor
snoyberg commented Sep 1, 2016

And an ugly workaround is discovered:

#!/usr/bin/env stack
-- stack runghc --resolver lts-6.14 --package tar --package text
{-# LANGUAGE OverloadedStrings #-}
import Codec.Archive.Tar
import Codec.Archive.Tar.Entry
import qualified Data.ByteString.Lazy as L
import System.Process
import System.Exit
import qualified Data.ByteString.Char8 as S8
import qualified Data.Text as T
import qualified Data.Text.Encoding as T

main :: IO ()
main = do
  let fp = "accenté.txt"
      Right tarPath = toTarPath False $ S8.unpack $ T.encodeUtf8 $ T.pack fp
  writeFile fp "test1"
  L.writeFile "tarintl.tar" $ write [fileEntry tarPath "test2"]
  rawSystem "tar" ["xfv", "tarintl.tar"] >>= exitWith
@snoyberg snoyberg added the in progress label Sep 1, 2016
@borsboom borsboom closed this in 74632b7 Sep 5, 2016
@borsboom borsboom removed the in progress label Sep 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment