diff --git a/codex/tarballs/directorymanifest.nim b/codex/tarballs/directorymanifest.nim index c81bb80e..1e83158b 100644 --- a/codex/tarballs/directorymanifest.nim +++ b/codex/tarballs/directorymanifest.nim @@ -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] diff --git a/codex/tarballs/tarballs.nim b/codex/tarballs/tarballs.nim index 04db1c29..b0ba59e9 100644 --- a/codex/tarballs/tarballs.nim +++ b/codex/tarballs/tarballs.nim @@ -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,