Skip to content

Commit

Permalink
fix(server): public plugin was deleted on installing privte plugin th…
Browse files Browse the repository at this point in the history
…at has same name
  • Loading branch information
rot1024 committed Jan 13, 2023
1 parent 436b689 commit d240344
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/internal/infrastructure/gcs/file.go
Expand Up @@ -90,6 +90,8 @@ func (f *fileRepo) UploadAsset(ctx context.Context, file *file.File) (*url.URL,
}

func (f *fileRepo) RemoveAsset(ctx context.Context, u *url.URL) error {
log.Infof("gcs: asset deleted: %s", u)

sn := getGCSObjectNameFromURL(f.base, u)
if sn == "" {
return gateway.ErrInvalidFile
Expand Down Expand Up @@ -117,6 +119,8 @@ func (f *fileRepo) UploadPluginFile(ctx context.Context, pid id.PluginID, file *
}

func (f *fileRepo) RemovePlugin(ctx context.Context, pid id.PluginID) error {
log.Infof("gcs: plugin deleted: %s", pid)

return f.deleteAll(ctx, path.Join(gcsPluginBasePath, pid.String()))
}

Expand Down Expand Up @@ -148,6 +152,8 @@ func (f *fileRepo) MoveBuiltScene(ctx context.Context, oldName, name string) err
}

func (f *fileRepo) RemoveBuiltScene(ctx context.Context, name string) error {
log.Infof("gcs: built scene deleted: %s", name)

sn := sanitize.Path(name + ".json")
if sn == "" {
return gateway.ErrInvalidFile
Expand Down
6 changes: 6 additions & 0 deletions server/internal/usecase/interactor/plugin_upload.go
Expand Up @@ -95,6 +95,12 @@ func (i *Plugin) upload(ctx context.Context, p *pluginpack.Package, sid id.Scene
var oldPManifest *manifest.Manifest
newpid := p.Manifest.Plugin.ID()
oldpid := s.Plugins().PluginByName(newpid.Name()).PluginRef()

// if the old plugin is public, it should not be deleted
if oldpid != nil && oldpid.Scene() == nil {
return nil, nil, interfaces.ErrPluginAlreadyInstalled
}

if oldpid != nil {
oldPlugin, err := i.pluginRepo.FindByID(ctx, *oldpid)
if err != nil {
Expand Down

0 comments on commit d240344

Please sign in to comment.