diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-07-04 16:32:04 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-07-04 16:32:17 +0300 |
commit | 5e6ca2cd1e4f6e1eaa9fc09a147a3f2741421c42 (patch) | |
tree | 00c4e9c4d1490bd56865861a90c9cbf92294f6dc /internal/vfs | |
parent | 9c299c70e8b328b512281166bb9e9668ea76ea65 (diff) |
Convert archive field to a local variable
Diffstat (limited to 'internal/vfs')
-rw-r--r-- | internal/vfs/zip/archive.go | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/internal/vfs/zip/archive.go b/internal/vfs/zip/archive.go index 432f92d1..134842ab 100644 --- a/internal/vfs/zip/archive.go +++ b/internal/vfs/zip/archive.go @@ -56,7 +56,6 @@ type zipArchive struct { resource *httprange.Resource reader *httprange.RangedReader - archive *zip.Reader err error files map[string]*zip.File @@ -128,13 +127,15 @@ func (a *zipArchive) readArchive(url string) { return } + var archive *zip.Reader + // load all archive files into memory using a cached ranged reader a.reader = httprange.NewRangedReader(a.resource) a.reader.WithCachedReader(ctx, func() { - a.archive, a.err = zip.NewReader(a.reader, a.resource.Size) + archive, a.err = zip.NewReader(a.reader, a.resource.Size) }) - if a.archive == nil || a.err != nil { + if archive == nil || a.err != nil { log.WithFields(log.Fields{ "archive_url": url, }).WithError(a.err).Infoln("loading zip archive files into memory failed") @@ -143,7 +144,7 @@ func (a *zipArchive) readArchive(url string) { } // TODO: Improve preprocessing of zip archives https://gitlab.com/gitlab-org/gitlab-pages/-/issues/432 - for _, file := range a.archive.File { + for _, file := range archive.File { if !strings.HasPrefix(file.Name, dirPrefix) { continue } @@ -164,9 +165,6 @@ func (a *zipArchive) readArchive(url string) { a.addPathDirectory(file.Name) } - // recycle memory - a.archive = nil - fileCount := float64(len(a.files)) metrics.ZipOpened.WithLabelValues("ok").Inc() metrics.ZipOpenedEntriesCount.Add(fileCount) |