Cleans up directory manifest and tartballs

This commit is contained in:
Marcin Czenko 2025-04-27 01:35:28 +02:00
parent 58c9e2001b
commit 071cb9bdab
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
2 changed files with 9 additions and 13 deletions

View File

@ -10,16 +10,8 @@
{.push raises: [].}
import pkg/libp2p/cid
# import pkg/stew/byteutils
# import pkg/questionable
# import pkg/questionable/results
# import ../merkletree/codex/codex
import ../utils/json
# import ../errors
# import ../codextypes
type DirectoryManifest* = ref object
name* {.serialize.}: string
cids* {.serialize.}: seq[Cid]

View File

@ -16,6 +16,8 @@ import pkg/libp2p/[cid, multicodec, multihash]
import pkg/serde/json
import ../blocktype
import ../manifest
import ./directorymanifest
proc example2*(_: type Block, size: int = 4096): ?!Block =
let length = rand(size)
@ -43,9 +45,9 @@ type
TarballEntry* = object
kind*: EntryKind
name: string
cid: Cid
contentLength: int
name*: string
cid*: Cid
contentLength*: int
lastModified*: times.Time
permissions*: set[FilePermission]
@ -87,7 +89,7 @@ proc `$`*(tarballEntry: TarballEntry): string =
## Returns a string representation of the tarball entry.
result = fmt"({tarballEntry.kind}, {tarballEntry.name})"
proc parseFilePermissions(permissions: uint32): set[FilePermission] =
proc parseFilePermissions*(permissions: uint32): set[FilePermission] =
if defined(windows) or permissions == 0:
# Ignore file permissions on Windows. If they are absent (.zip made on
# Windows for example), set default permissions.
@ -178,10 +180,12 @@ proc openStreamImpl(
return failure("Attempted to read past end of file, corrupted tarball?")
let normalizedFileName = normalizePathEnd(fileName)
if typeFlag == '0' or typeFlag == '\0':
if not onProcessedTarFile.isNil:
let stream = newStringStream(data[pos ..< pos + fileSize])
without cid =? await onProcessedTarFile(stream, normalizedFileName), err:
without cid =?
await onProcessedTarFile(stream, normalizedFileName.lastPathPart), err:
return failure(err.msg)
tarball.contents[(fileNamePrefix / fileName).toUnixPath()] = TarballEntry(
kind: ekNormalFile,