Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

snoyberg opened this issue Aug 31, 2016 · 3 comments
Assignees

Comments

@snoyberg
Copy link
Contributor

@snoyberg snoyberg commented Aug 31, 2016

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
Copy link
Contributor Author

@snoyberg 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
Copy link
Contributor Author

@snoyberg 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
Copy link
Contributor Author

@snoyberg 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants