From ca4921d00bca36c58b104e1433d0efaff1dfb789 Mon Sep 17 00:00:00 2001 From: bufdev Date: Tue, 11 Jul 2023 15:56:31 -0400 Subject: [PATCH] Delete storage.NoExternalPathReadBucket --- private/pkg/storage/external_paths.go | 79 ------------------- .../storage/storagetesting/storagetesting.go | 21 ----- 2 files changed, 100 deletions(-) delete mode 100644 private/pkg/storage/external_paths.go diff --git a/private/pkg/storage/external_paths.go b/private/pkg/storage/external_paths.go deleted file mode 100644 index a5b21d4e7b..0000000000 --- a/private/pkg/storage/external_paths.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2020-2023 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package storage - -import ( - "context" - - "github.com/bufbuild/buf/private/pkg/storage/storageutil" -) - -// NoExternalPathReadBucket disables the external paths for the ReadBucket. -// -// This results in ExternalPath just calling Path. -func NoExternalPathReadBucket(readBucket ReadBucket) ReadBucket { - return newNoExternalPathReadBucket(readBucket) -} - -type noExternalPathReadBucket struct { - delegate ReadBucket -} - -func newNoExternalPathReadBucket( - delegate ReadBucket, -) *noExternalPathReadBucket { - return &noExternalPathReadBucket{ - delegate: delegate, - } -} - -func (r *noExternalPathReadBucket) Get(ctx context.Context, path string) (ReadObjectCloser, error) { - readObjectCloser, err := r.delegate.Get(ctx, path) - // TODO: if this is a path error, we should replace the path - if err != nil { - return nil, err - } - return disableReadObjectCloserExternalPath(readObjectCloser), nil -} - -func (r *noExternalPathReadBucket) Stat(ctx context.Context, path string) (ObjectInfo, error) { - objectInfo, err := r.delegate.Stat(ctx, path) - // TODO: if this is a path error, we should replace the path - if err != nil { - return nil, err - } - return disableObjectInfoExternalPath(objectInfo), nil -} - -func (r *noExternalPathReadBucket) Walk(ctx context.Context, prefix string, f func(ObjectInfo) error) error { - return r.delegate.Walk( - ctx, - prefix, - func(objectInfo ObjectInfo) error { - return f(disableObjectInfoExternalPath(objectInfo)) - }, - ) -} - -func disableObjectInfoExternalPath(objectInfo ObjectInfo) ObjectInfo { - return storageutil.NewObjectInfo( - objectInfo.Path(), - objectInfo.Path(), - ) -} - -func disableReadObjectCloserExternalPath(readObjectCloser ReadObjectCloser) ReadObjectCloser { - return compositeReadObjectCloser{disableObjectInfoExternalPath(readObjectCloser), readObjectCloser} -} diff --git a/private/pkg/storage/storagetesting/storagetesting.go b/private/pkg/storage/storagetesting/storagetesting.go index f3a71748ac..60e66b6cfd 100644 --- a/private/pkg/storage/storagetesting/storagetesting.go +++ b/private/pkg/storage/storagetesting/storagetesting.go @@ -1424,27 +1424,6 @@ func RunTestSuite( require.True(t, isEmpty) require.NoError(t, tmpDir.Close()) }) - t.Run("no-external-path", func(t *testing.T) { - t.Parallel() - readBucket, getExternalPathFunc := newReadBucket(t, oneDirPath, defaultProvider) - readBucket = storage.MapReadBucket( - readBucket, - storage.MapOnPrefix("root/a"), - ) - AssertObjectInfo( - t, - readBucket, - "1.proto", - getExternalPathFunc(t, oneDirPath, filepath.Join("root", "a", "1.proto")), - ) - readBucket = storage.NoExternalPathReadBucket(readBucket) - AssertObjectInfo( - t, - readBucket, - "1.proto", - "1.proto", - ) - }) t.Run("limit-write-bucket", func(t *testing.T) { t.Parallel() writeBucket := newWriteBucket(t, defaultProvider)