diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2022-07-12 07:39:53 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2022-07-12 07:39:53 +0300 |
commit | 8dd16c9c043d08617a1d01d46880d7506a299ba2 (patch) | |
tree | 65537d02c52e4be9518e4ca6ebf87001ec94b076 /internal/vfs | |
parent | 1f9cc507928429fc0a85eaa504bfca692c56ff2a (diff) | |
parent | 57195a5ae472878c19dae4b6a65bc37a76e992e4 (diff) |
Merge branch 'perf/lazy-open-serve' into 'master'revert-perf-lazy-open-master
perf: open files lazily when serving content
See merge request gitlab-org/gitlab-pages!803
Diffstat (limited to 'internal/vfs')
-rw-r--r-- | internal/vfs/local/root.go | 4 | ||||
-rw-r--r-- | internal/vfs/root.go | 5 | ||||
-rw-r--r-- | internal/vfs/zip/archive.go | 19 |
3 files changed, 28 insertions, 0 deletions
diff --git a/internal/vfs/local/root.go b/internal/vfs/local/root.go index 9cd67a9f..d15fa4e1 100644 --- a/internal/vfs/local/root.go +++ b/internal/vfs/local/root.go @@ -105,3 +105,7 @@ func (r *Root) Open(ctx context.Context, name string) (vfs.File, error) { return file, nil } + +func (r *Root) IsCompressed(_ string) (bool, error) { + return false, nil +} diff --git a/internal/vfs/root.go b/internal/vfs/root.go index 9c7528b3..1a2e9ccd 100644 --- a/internal/vfs/root.go +++ b/internal/vfs/root.go @@ -16,6 +16,7 @@ type Root interface { Lstat(ctx context.Context, name string) (os.FileInfo, error) Readlink(ctx context.Context, name string) (string, error) Open(ctx context.Context, name string) (File, error) + IsCompressed(name string) (bool, error) } type instrumentedRoot struct { @@ -68,3 +69,7 @@ func (i *instrumentedRoot) Open(ctx context.Context, name string) (File, error) return f, err } + +func (i *instrumentedRoot) IsCompressed(name string) (bool, error) { + return i.root.IsCompressed(name) +} diff --git a/internal/vfs/zip/archive.go b/internal/vfs/zip/archive.go index 2b04310d..23ad7b2e 100644 --- a/internal/vfs/zip/archive.go +++ b/internal/vfs/zip/archive.go @@ -239,6 +239,25 @@ func (a *zipArchive) Open(ctx context.Context, name string) (vfs.File, error) { } } +// IsCompressed finds the file by name and checks its compression method. If the method is +// zip.Store it means it's not compressed. +// Returns errNotFile for directories or non-regular files. +func (a *zipArchive) IsCompressed(name string) (bool, error) { + file := a.findFile(name) + if file == nil { + if a.findDirectory(name) != nil { + return false, errNotFile + } + return false, os.ErrNotExist + } + + if !file.Mode().IsRegular() { + return false, errNotFile + } + + return file.Method != zip.Store, nil +} + // Lstat finds the file by name inside the zipArchive and returns its FileInfo func (a *zipArchive) Lstat(ctx context.Context, name string) (os.FileInfo, error) { file := a.findFile(name) |