Skip to content

Commit

Permalink
Minor fix in OCM share pkg (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored May 6, 2020
1 parent 7dbeb84 commit 07e5b69
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pkg/ocm/share/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceId, g *ocm.ShareGr
_, err := m.getByKey(ctx, key)

// share already exists
if err == nil {
if pi != nil && err == nil {
return nil, errtypes.AlreadyExists(key.String())
}

Expand Down
23 changes: 12 additions & 11 deletions pkg/storage/fs/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ type config struct {
Root string `mapstructure:"root"`
EnableHome bool `mapstructure:"enable_home"`
UserLayout string `mapstructure:"user_layout"`
// Uploads fsolder should be on the same partition as root to make the final rename not fall back to a copy and delete
// Uploads folder should be on the same partition as root to make the final rename not fall back to a copy and delete
Uploads string `mapstructure:"uploads"`
}

type localfs struct {
conf *config
}

func parseConfig(m map[string]interface{}) (*config, error) {
c := &config{}
if err := mapstructure.Decode(m, c); err != nil {
Expand Down Expand Up @@ -92,7 +96,7 @@ func New(m map[string]interface{}) (storage.FS, error) {
return nil, errors.Wrap(err, "could not create uploads dir "+c.Uploads)
}

return &localfs{root: c.Root, conf: c}, nil
return &localfs{conf: c}, nil
}

func (fs *localfs) Shutdown(ctx context.Context) error {
Expand Down Expand Up @@ -123,7 +127,8 @@ func getUser(ctx context.Context) (*userpb.User, error) {
return u, nil
}

func (fs *localfs) wrap(ctx context.Context, p string) (internal string) {
func (fs *localfs) wrap(ctx context.Context, p string) string {
var internal string
if fs.conf.EnableHome {
layout, err := fs.GetHome(ctx)
if err != nil {
Expand All @@ -133,10 +138,11 @@ func (fs *localfs) wrap(ctx context.Context, p string) (internal string) {
} else {
internal = path.Join(fs.conf.Root, p)
}
return
return internal
}

func (fs *localfs) unwrap(ctx context.Context, np string) (external string) {
func (fs *localfs) unwrap(ctx context.Context, np string) string {
var external string
if fs.conf.EnableHome {
layout, err := fs.GetHome(ctx)
if err != nil {
Expand All @@ -150,12 +156,7 @@ func (fs *localfs) unwrap(ctx context.Context, np string) (external string) {
external = "/"
}
}
return
}

type localfs struct {
root string
conf *config
return external
}

func (fs *localfs) normalize(ctx context.Context, fi os.FileInfo, fn string) *provider.ResourceInfo {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/local/local_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
if err != nil {
log.Error().Err(err).Msg("error writing mtime")
}
// device and inode hale no meaning on windows
// device and inode have no meaning on windows
err = binary.Write(h, binary.BigEndian, fi.Size())
if err != nil {
log.Error().Err(err).Msg("error writing size")
Expand Down
29 changes: 13 additions & 16 deletions pkg/storage/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ func (b *reg) ListProviders(ctx context.Context) ([]*registrypb.ProviderInfo, er
// returns the the root path of the first provider in the list.
// TODO(labkode): this is not production ready.
func (b *reg) GetHome(ctx context.Context) (*registrypb.ProviderInfo, error) {
for k, v := range b.c.Rules {
if k == b.c.HomeProvider {
return &registrypb.ProviderInfo{
ProviderPath: k,
Address: v,
}, nil
}
address, ok := b.c.Rules[b.c.HomeProvider]
if ok {
return &registrypb.ProviderInfo{
ProviderPath: b.c.HomeProvider,
Address: address,
}, nil
}
return nil, errors.New("static: home not found")
}
Expand Down Expand Up @@ -113,15 +112,13 @@ func (b *reg) FindProvider(ctx context.Context, ref *provider.Reference) (*regis
if id == nil {
return nil, errtypes.NotFound("storage provider not found for ref " + ref.String())
}

for prefix := range b.c.Rules {
if id.StorageId == prefix {
// TODO(labkode): fill path info based on provider id, if path and storage id points to same id, take that.
return &registrypb.ProviderInfo{
ProviderId: prefix,
Address: b.c.Rules[prefix],
}, nil
}
address, ok := b.c.Rules[id.StorageId]
if ok {
// TODO(labkode): fill path info based on provider id, if path and storage id points to same id, take that.
return &registrypb.ProviderInfo{
ProviderId: id.StorageId,
Address: address,
}, nil
}
return nil, errtypes.NotFound("storage provider not found for ref " + ref.String())
}

0 comments on commit 07e5b69

Please sign in to comment.