Skip to content

Commit

Permalink
tarball number encoding is terrible
Browse files Browse the repository at this point in the history
  • Loading branch information
guzba committed Feb 4, 2022
1 parent 0b231af commit ec6c83b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
15 changes: 13 additions & 2 deletions src/zippy/tarballs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ export common, tarballs_v1
import strutils

proc parseTarOctInt(s: string): int =
# Walk the bytes to find the start and len of the acii digits
var start, len: int
for c in s:
if c in {'0' .. '9'}:
break
inc start
for i in start ..< s.len:
if s[i] notin {'0' .. '9'}:
break
inc len

try:
if s[0] == '\0':
if len == 0:
0
else:
parseOctInt(s)
parseOctInt(s[start ..< start + len])
except ValueError:
raise currentExceptionAsZippyError()

Expand Down
Binary file added tests/data/tarballs/libressl-3.4.2.tar.gz
Binary file not shown.
56 changes: 28 additions & 28 deletions tests/test_tarballs.nim
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import std/os, std/strformat, zippy/tarballs

block:
let testFilePath = "tests/data/tarballs/Nim-1.6.2.tar.gz"
let testFilePaths = [
# "tests/data/tarballs/Nim-1.6.2.tar.gz",
"tests/data/tarballs/libressl-3.4.2.tar.gz"
]

removeDir("tmp/tar")
createDir("tmp/tar")

extractAll(testFilePath, "tmp/tar/zippy")
for testFilePath in testFilePaths:
removeDir("tmp/tar")
createDir("tmp/tar")

createDir("tmp/tar/gold")
let cmd = &"tar -xf {testFilePath} -C tmp/tar/gold"
doAssert execShellCmd(cmd) == 0
extractAll(testFilePath, "tmp/tar/zippy")

for path in walkDirRec(
"tmp/tar/gold",
yieldFilter = {pcFile, pcDir, pcLinkToFile, pcLinkToDir},
relative = true
):
let
goldPath = "tmp/tar/gold" / path
zippyPath = "tmp/tar/zippy" / path
createDir("tmp/tar/gold")
let cmd = &"tar -xf {testFilePath} -C tmp/tar/gold"
doAssert execShellCmd(cmd) == 0

if dirExists(goldPath):
doAssert dirExists(zippyPath)
else:
when defined(windows):
# tar on Windows creates this monster, zippy handles this file correctly
if path == "Nim-1.6.2\\tests\\misc\\\226\148\156\195\145\226\148\156\195\177\226\148\156\226\149\162.nim":
continue
doAssert fileExists(zippyPath)
doAssert readFile(goldPath) == readFile(zippyPath)
for path in walkDirRec(
"tmp/tar/gold",
yieldFilter = {pcFile, pcDir, pcLinkToFile, pcLinkToDir},
relative = true
):
let
goldPath = "tmp/tar/gold" / path
zippyPath = "tmp/tar/zippy" / path

when defined(windows):
doAssert getFilePermissions(goldPath) == getFilePermissions(zippyPath)
doAssert getLastModificationTime(goldPath) == getLastModificationTime(zippyPath)
if dirExists(goldPath):
doAssert dirExists(zippyPath)
else:
when defined(windows):
# tar on Windows creates this monster, zippy handles this file correctly
if path == "Nim-1.6.2\\tests\\misc\\\226\148\156\195\145\226\148\156\195\177\226\148\156\226\149\162.nim":
continue
doAssert fileExists(zippyPath)
doAssert readFile(goldPath) == readFile(zippyPath)

when not defined(windows):
block:
Expand Down

0 comments on commit ec6c83b

Please sign in to comment.