Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev committed Jan 24, 2024
1 parent 08787c7 commit d73d376
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 29 deletions.
68 changes: 41 additions & 27 deletions private/bufpkg/bufmodule/bufmodulestore/module_data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func (p *moduleDataStore) getModuleDataForModuleKey(
}
defer func() {
if retErr != nil {
p.logDebugModuleKey(
moduleKey,
"module data store deleting invalid data",
zap.Error(retErr),
)
retErr = p.deleteInvalidModuleData(ctx, moduleKey, retErr)
}
}()
Expand Down Expand Up @@ -200,31 +205,39 @@ func (p *moduleDataStore) getModuleDataForModuleKey(
if err != nil {
return nil, err
}
// We do not want to use bufconfig.GetBufYAMLFileForPrefix as this validates the
// buf.yaml, and potentially calls out to i.e. resolve digests. We just want to raw data.
v1BufYAMLFileData, err := storage.ReadPath(ctx, moduleCacheBucket, externalModuleData.V1BufYAMLFile)
if err != nil {
return nil, err
}
v1BufYAMLObjectData, err := bufmodule.NewObjectData(
normalpath.Base(externalModuleData.V1BufYAMLFile),
v1BufYAMLFileData,
)
if err != nil {
return nil, err
}
// We do not want to use bufconfig.GetBufLockFileForPrefix as this validates the
// buf.lock, and potentially calls out to i.e. resolve digests. We just want to raw data.
v1BufLockFileData, err := storage.ReadPath(ctx, moduleCacheBucket, externalModuleData.V1BufLockFile)
if err != nil {
return nil, err
var v1BufYAMLObjectData bufmodule.ObjectData
// TODO: make this required
if externalModuleData.V1BufYAMLFile != "" {
// We do not want to use bufconfig.GetBufYAMLFileForPrefix as this validates the
// buf.yaml, and potentially calls out to i.e. resolve digests. We just want to raw data.
v1BufYAMLFileData, err := storage.ReadPath(ctx, moduleCacheBucket, externalModuleData.V1BufYAMLFile)
if err != nil {
return nil, err
}
v1BufYAMLObjectData, err = bufmodule.NewObjectData(
normalpath.Base(externalModuleData.V1BufYAMLFile),
v1BufYAMLFileData,
)
if err != nil {
return nil, err
}
}
v1BufLockObjectData, err := bufmodule.NewObjectData(
normalpath.Base(externalModuleData.V1BufLockFile),
v1BufLockFileData,
)
if err != nil {
return nil, err
var v1BufLockObjectData bufmodule.ObjectData
// TODO: make this required
if externalModuleData.V1BufLockFile != "" {
// We do not want to use bufconfig.GetBufLockFileForPrefix as this validates the
// buf.lock, and potentially calls out to i.e. resolve digests. We just want to raw data.
v1BufLockFileData, err := storage.ReadPath(ctx, moduleCacheBucket, externalModuleData.V1BufLockFile)
if err != nil {
return nil, err
}
v1BufLockObjectData, err = bufmodule.NewObjectData(
normalpath.Base(externalModuleData.V1BufLockFile),
v1BufLockFileData,
)
if err != nil {
return nil, err
}
}
// We rely on the module.yaml file being the last file to be written in the store.
// If module.yaml does not exist, we act as if there is no value in the store, which will
Expand Down Expand Up @@ -531,9 +544,10 @@ func (e externalModuleData) isValid() bool {
}
}
return e.Version == externalModuleDataVersion &&
len(e.FilesDir) > 0 &&
len(e.V1BufYAMLFile) > 0 &&
len(e.V1BufLockFile) > 0
len(e.FilesDir) > 0
// TODO: re-enable
//len(e.V1BufYAMLFile) > 0 &&
//len(e.V1BufLockFile) > 0
}

// externalModuleDataDep represents a dependency.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package bufmodulestore

import (
"context"
"os"
"testing"

"github.com/bufbuild/buf/private/bufpkg/bufmodule"
Expand All @@ -24,8 +25,9 @@ import (
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/storage"
"github.com/bufbuild/buf/private/pkg/storage/storagemem"
"github.com/bufbuild/buf/private/pkg/zaputil"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func TestModuleDataStoreBasicDir(t *testing.T) {
Expand All @@ -45,7 +47,8 @@ func testModuleDataStoreBasic(t *testing.T, tar bool) {
if tar {
moduleDataStoreOptions = append(moduleDataStoreOptions, ModuleDataStoreWithTar())
}
moduleDataStore := NewModuleDataStore(zap.NewNop(), bucket, moduleDataStoreOptions...)
logger := zaputil.NewLogger(os.Stderr, zapcore.DebugLevel, zaputil.NewTextEncoder())
moduleDataStore := NewModuleDataStore(logger, bucket, moduleDataStoreOptions...)
moduleKeys, moduleDatas := testGetModuleKeysAndModuleDatas(t, ctx)

foundModuleDatas, notFoundModuleKeys, err := moduleDataStore.GetModuleDatasForModuleKeys(
Expand Down

0 comments on commit d73d376

Please sign in to comment.