From f15aec8859840126a39c9e4b2d077877976df64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Mon, 30 May 2022 13:38:24 +0200 Subject: [PATCH 1/5] Implement a "migrate" command for migrating between share managers --- ocis/pkg/command/migrate.go | 153 ++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 ocis/pkg/command/migrate.go diff --git a/ocis/pkg/command/migrate.go b/ocis/pkg/command/migrate.go new file mode 100644 index 000000000..08d2e29ac --- /dev/null +++ b/ocis/pkg/command/migrate.go @@ -0,0 +1,153 @@ +package command + +import ( + "encoding/json" + "fmt" + "os" + "sync" + + collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" + "github.com/cs3org/reva/v2/pkg/share" + "github.com/cs3org/reva/v2/pkg/share/manager/registry" + sharing "github.com/owncloud/ocis/v2/extensions/sharing/pkg/config" + "github.com/owncloud/ocis/v2/ocis-pkg/config" + "github.com/owncloud/ocis/v2/ocis-pkg/config/parser" + "github.com/owncloud/ocis/v2/ocis/pkg/register" + "github.com/urfave/cli/v2" +) + +// Migrate is the entrypoint for the Migrate command. +func Migrate(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "migrate", + Usage: "migrate data from an existing instance to a new version", + Category: "migration", + Before: func(c *cli.Context) error { + if err := parser.ParseConfig(cfg); err != nil { + s, _ := json.MarshalIndent(cfg, "", " ") + fmt.Print(string(s)) + fmt.Printf("%v", err) + return err + } + return nil + }, + Subcommands: []*cli.Command{ + MigrateShares(cfg), + }, + } +} + +func init() { + register.AddCommand(Migrate) +} + +func MigrateShares(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "shares", + Usage: "migrates shares from the previous to the new ", + Before: func(c *cli.Context) error { + err := parser.ParseConfig(cfg) + if err != nil { + fmt.Printf("%v", err) + os.Exit(1) + } + return err + }, + Action: func(c *cli.Context) error { + rcfg := revaConfig(cfg.Sharing) + oldDriver := "json" + newDriver := "cs3" + shareChan := make(chan *collaboration.Share) + receivedShareChan := make(chan share.ReceivedShareDump) + + f, ok := registry.NewFuncs[oldDriver] + if !ok { + fmt.Println("Unknown share manager type '" + oldDriver + "'") + os.Exit(1) + } + oldMgr, err := f(rcfg[oldDriver].(map[string]interface{})) + if err != nil { + fmt.Println("failed to initiate source share manager", err) + os.Exit(1) + } + if _, ok := oldMgr.(share.DumpableManager); !ok { + fmt.Println("Share manager type '" + oldDriver + "' does not support migration.") + os.Exit(1) + } + + f, ok = registry.NewFuncs[newDriver] + if !ok { + fmt.Println("Unknown share manager type '" + oldDriver + "'") + os.Exit(1) + } + newMgr, err := f(rcfg[newDriver].(map[string]interface{})) + if err != nil { + fmt.Println("failed to initiate source share manager", err) + os.Exit(1) + } + if _, ok := newMgr.(share.LoadableManager); !ok { + fmt.Println("Share manager type '" + newDriver + "' does not support migration.") + os.Exit(1) + } + + var wg sync.WaitGroup + wg.Add(2) + go func() { + fmt.Println("Loading...") + err = newMgr.(share.LoadableManager).Load(shareChan, receivedShareChan) + fmt.Println("Finished loading...") + if err != nil { + fmt.Println("Error while loading shares", err) + os.Exit(1) + } + wg.Done() + }() + go func() { + err = oldMgr.(share.DumpableManager).Dump(shareChan, receivedShareChan) + if err != nil { + fmt.Println("Error while dumping shares", err) + os.Exit(1) + } + wg.Done() + }() + wg.Wait() + return nil + }, + } +} + +func revaConfig(cfg *sharing.Config) map[string]interface{} { + return map[string]interface{}{ + "json": map[string]interface{}{ + "file": cfg.UserSharingDrivers.JSON.File, + "gateway_addr": cfg.Reva.Address, + }, + "sql": map[string]interface{}{ // cernbox sql + "db_username": cfg.UserSharingDrivers.SQL.DBUsername, + "db_password": cfg.UserSharingDrivers.SQL.DBPassword, + "db_host": cfg.UserSharingDrivers.SQL.DBHost, + "db_port": cfg.UserSharingDrivers.SQL.DBPort, + "db_name": cfg.UserSharingDrivers.SQL.DBName, + "password_hash_cost": cfg.UserSharingDrivers.SQL.PasswordHashCost, + "enable_expired_shares_cleanup": cfg.UserSharingDrivers.SQL.EnableExpiredSharesCleanup, + "janitor_run_interval": cfg.UserSharingDrivers.SQL.JanitorRunInterval, + }, + "owncloudsql": map[string]interface{}{ + "gateway_addr": cfg.Reva.Address, + "storage_mount_id": cfg.UserSharingDrivers.OwnCloudSQL.UserStorageMountID, + "db_username": cfg.UserSharingDrivers.OwnCloudSQL.DBUsername, + "db_password": cfg.UserSharingDrivers.OwnCloudSQL.DBPassword, + "db_host": cfg.UserSharingDrivers.OwnCloudSQL.DBHost, + "db_port": cfg.UserSharingDrivers.OwnCloudSQL.DBPort, + "db_name": cfg.UserSharingDrivers.OwnCloudSQL.DBName, + }, + "cs3": map[string]interface{}{ + "gateway_addr": cfg.UserSharingDrivers.CS3.ProviderAddr, + "provider_addr": cfg.UserSharingDrivers.CS3.ProviderAddr, + "service_user_id": cfg.UserSharingDrivers.CS3.SystemUserID, + "service_user_idp": cfg.UserSharingDrivers.CS3.SystemUserIDP, + "machine_auth_apikey": cfg.UserSharingDrivers.CS3.SystemUserAPIKey, + }, + } + +} From df6f00ffbbcd7f56bcbdd3b7ed044c607282f617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Wed, 1 Jun 2022 08:44:03 +0200 Subject: [PATCH 2/5] Make the source and destination managers configurable --- ocis/pkg/command/migrate.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ocis/pkg/command/migrate.go b/ocis/pkg/command/migrate.go index 08d2e29ac..bcffa9d33 100644 --- a/ocis/pkg/command/migrate.go +++ b/ocis/pkg/command/migrate.go @@ -45,6 +45,18 @@ func MigrateShares(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "shares", Usage: "migrates shares from the previous to the new ", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "from", + Value: "json", + Usage: "Share manager to export the data from", + }, + &cli.StringFlag{ + Name: "to", + Value: "cs3", + Usage: "Share manager to import the data to", + }, + }, Before: func(c *cli.Context) error { err := parser.ParseConfig(cfg) if err != nil { @@ -55,8 +67,8 @@ func MigrateShares(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { rcfg := revaConfig(cfg.Sharing) - oldDriver := "json" - newDriver := "cs3" + oldDriver := c.String("from") + newDriver := c.String("to") shareChan := make(chan *collaboration.Share) receivedShareChan := make(chan share.ReceivedShareDump) @@ -71,7 +83,7 @@ func MigrateShares(cfg *config.Config) *cli.Command { os.Exit(1) } if _, ok := oldMgr.(share.DumpableManager); !ok { - fmt.Println("Share manager type '" + oldDriver + "' does not support migration.") + fmt.Println("Share manager type '" + oldDriver + "' does not support dumping its shares.") os.Exit(1) } @@ -86,16 +98,16 @@ func MigrateShares(cfg *config.Config) *cli.Command { os.Exit(1) } if _, ok := newMgr.(share.LoadableManager); !ok { - fmt.Println("Share manager type '" + newDriver + "' does not support migration.") + fmt.Println("Share manager type '" + newDriver + "' does not support loading a shares dump.") os.Exit(1) } var wg sync.WaitGroup wg.Add(2) go func() { - fmt.Println("Loading...") + fmt.Println("Migrating shares...") err = newMgr.(share.LoadableManager).Load(shareChan, receivedShareChan) - fmt.Println("Finished loading...") + fmt.Println("Finished migrating shares.") if err != nil { fmt.Println("Error while loading shares", err) os.Exit(1) From 42e32e5b693224232eade2ff57a6e5d1a49e75ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Thu, 2 Jun 2022 10:32:41 +0200 Subject: [PATCH 3/5] Implement migrating public shares --- ocis/pkg/command/migrate.go | 162 +++++++++++++++++++++++++++++++----- 1 file changed, 140 insertions(+), 22 deletions(-) diff --git a/ocis/pkg/command/migrate.go b/ocis/pkg/command/migrate.go index bcffa9d33..125a0cd60 100644 --- a/ocis/pkg/command/migrate.go +++ b/ocis/pkg/command/migrate.go @@ -1,18 +1,21 @@ package command import ( - "encoding/json" + "context" "fmt" "os" "sync" collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" + "github.com/cs3org/reva/v2/pkg/publicshare" + publicregistry "github.com/cs3org/reva/v2/pkg/publicshare/manager/registry" "github.com/cs3org/reva/v2/pkg/share" "github.com/cs3org/reva/v2/pkg/share/manager/registry" sharing "github.com/owncloud/ocis/v2/extensions/sharing/pkg/config" "github.com/owncloud/ocis/v2/ocis-pkg/config" "github.com/owncloud/ocis/v2/ocis-pkg/config/parser" "github.com/owncloud/ocis/v2/ocis/pkg/register" + "github.com/rs/zerolog" "github.com/urfave/cli/v2" ) @@ -23,9 +26,7 @@ func Migrate(cfg *config.Config) *cli.Command { Usage: "migrate data from an existing instance to a new version", Category: "migration", Before: func(c *cli.Context) error { - if err := parser.ParseConfig(cfg); err != nil { - s, _ := json.MarshalIndent(cfg, "", " ") - fmt.Print(string(s)) + if err := parser.ParseConfig(cfg, true); err != nil { fmt.Printf("%v", err) return err } @@ -33,6 +34,7 @@ func Migrate(cfg *config.Config) *cli.Command { }, Subcommands: []*cli.Command{ MigrateShares(cfg), + MigratePublicShares(cfg), }, } } @@ -44,7 +46,7 @@ func init() { func MigrateShares(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "shares", - Usage: "migrates shares from the previous to the new ", + Usage: "migrates shares from the previous to the new manager", Flags: []cli.Flag{ &cli.StringFlag{ Name: "from", @@ -58,7 +60,7 @@ func MigrateShares(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg, true) if err != nil { fmt.Printf("%v", err) os.Exit(1) @@ -66,58 +68,60 @@ func MigrateShares(cfg *config.Config) *cli.Command { return err }, Action: func(c *cli.Context) error { - rcfg := revaConfig(cfg.Sharing) + log := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger() + ctx := log.WithContext(context.Background()) + rcfg := revaShareConfig(cfg.Sharing) oldDriver := c.String("from") newDriver := c.String("to") shareChan := make(chan *collaboration.Share) - receivedShareChan := make(chan share.ReceivedShareDump) + receivedShareChan := make(chan share.ReceivedShareWithUser) f, ok := registry.NewFuncs[oldDriver] if !ok { - fmt.Println("Unknown share manager type '" + oldDriver + "'") + log.Error().Msg("Unknown share manager type '" + oldDriver + "'") os.Exit(1) } oldMgr, err := f(rcfg[oldDriver].(map[string]interface{})) if err != nil { - fmt.Println("failed to initiate source share manager", err) + log.Error().Err(err).Msg("failed to initiate source share manager") os.Exit(1) } if _, ok := oldMgr.(share.DumpableManager); !ok { - fmt.Println("Share manager type '" + oldDriver + "' does not support dumping its shares.") + log.Error().Msg("Share manager type '" + oldDriver + "' does not support dumping its shares.") os.Exit(1) } f, ok = registry.NewFuncs[newDriver] if !ok { - fmt.Println("Unknown share manager type '" + oldDriver + "'") + log.Error().Msg("Unknown share manager type '" + oldDriver + "'") os.Exit(1) } newMgr, err := f(rcfg[newDriver].(map[string]interface{})) if err != nil { - fmt.Println("failed to initiate source share manager", err) + log.Error().Err(err).Msg("failed to initiate source share manager") os.Exit(1) } if _, ok := newMgr.(share.LoadableManager); !ok { - fmt.Println("Share manager type '" + newDriver + "' does not support loading a shares dump.") + log.Error().Msg("Share manager type '" + newDriver + "' does not support loading a shares dump.") os.Exit(1) } var wg sync.WaitGroup wg.Add(2) go func() { - fmt.Println("Migrating shares...") - err = newMgr.(share.LoadableManager).Load(shareChan, receivedShareChan) - fmt.Println("Finished migrating shares.") + log.Info().Msg("Migrating shares...") + err = newMgr.(share.LoadableManager).Load(ctx, shareChan, receivedShareChan) + log.Info().Msg("Finished migrating shares.") if err != nil { - fmt.Println("Error while loading shares", err) + log.Error().Err(err).Msg("Error while loading shares") os.Exit(1) } wg.Done() }() go func() { - err = oldMgr.(share.DumpableManager).Dump(shareChan, receivedShareChan) + err = oldMgr.(share.DumpableManager).Dump(ctx, shareChan, receivedShareChan) if err != nil { - fmt.Println("Error while dumping shares", err) + log.Error().Err(err).Msg("Error while dumping shares") os.Exit(1) } wg.Done() @@ -128,7 +132,96 @@ func MigrateShares(cfg *config.Config) *cli.Command { } } -func revaConfig(cfg *sharing.Config) map[string]interface{} { +func MigratePublicShares(cfg *config.Config) *cli.Command { + return &cli.Command{ + Name: "publicshares", + Usage: "migrates public shares from the previous to the new manager", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "from", + Value: "json", + Usage: "Share manager to export the data from", + }, + &cli.StringFlag{ + Name: "to", + Value: "cs3", + Usage: "Share manager to import the data to", + }, + }, + Before: func(c *cli.Context) error { + err := parser.ParseConfig(cfg, true) + if err != nil { + fmt.Printf("%v", err) + os.Exit(1) + } + return err + }, + Action: func(c *cli.Context) error { + log := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger() + ctx := log.WithContext(context.Background()) + + rcfg := revaPublicShareConfig(cfg.Sharing) + oldDriver := c.String("from") + newDriver := c.String("to") + shareChan := make(chan *publicshare.WithPassword) + + f, ok := publicregistry.NewFuncs[oldDriver] + if !ok { + log.Error().Msg("Unknown share manager type '" + oldDriver + "'") + os.Exit(1) + } + oldMgr, err := f(rcfg[oldDriver].(map[string]interface{})) + if err != nil { + log.Error().Err(err).Msg("failed to initiate source share manager") + os.Exit(1) + } + if _, ok := oldMgr.(publicshare.DumpableManager); !ok { + log.Error().Msg("Publicshare manager type '" + oldDriver + "' does not support dumping its shares.") + os.Exit(1) + } + + f, ok = publicregistry.NewFuncs[newDriver] + if !ok { + log.Error().Msg("Unknown share manager type '" + oldDriver + "'") + os.Exit(1) + } + newMgr, err := f(rcfg[newDriver].(map[string]interface{})) + if err != nil { + log.Error().Err(err).Msg("failed to initiate source share manager") + os.Exit(1) + } + if _, ok := newMgr.(publicshare.LoadableManager); !ok { + log.Error().Msg("PUblicshare manager type '" + newDriver + "' does not support loading a shares dump.") + os.Exit(1) + } + + var wg sync.WaitGroup + wg.Add(2) + go func() { + log.Info().Msg("Migrating public shares...") + err = newMgr.(publicshare.LoadableManager).Load(ctx, shareChan) + log.Info().Msg("Finished migrating public shares.") + if err != nil { + log.Error().Err(err).Msg("Error while loading shares") + os.Exit(1) + } + wg.Done() + }() + go func() { + err = oldMgr.(publicshare.DumpableManager).Dump(ctx, shareChan) + if err != nil { + log.Error().Err(err).Msg("Error while dumping public shares") + os.Exit(1) + } + wg.Done() + }() + wg.Wait() + return nil + }, + } +} + +func revaShareConfig(cfg *sharing.Config) map[string]interface{} { return map[string]interface{}{ "json": map[string]interface{}{ "file": cfg.UserSharingDrivers.JSON.File, @@ -161,5 +254,30 @@ func revaConfig(cfg *sharing.Config) map[string]interface{} { "machine_auth_apikey": cfg.UserSharingDrivers.CS3.SystemUserAPIKey, }, } - +} + +func revaPublicShareConfig(cfg *sharing.Config) map[string]interface{} { + return map[string]interface{}{ + "json": map[string]interface{}{ + "file": cfg.PublicSharingDrivers.JSON.File, + "gateway_addr": cfg.Reva.Address, + }, + "sql": map[string]interface{}{ + "db_username": cfg.PublicSharingDrivers.SQL.DBUsername, + "db_password": cfg.PublicSharingDrivers.SQL.DBPassword, + "db_host": cfg.PublicSharingDrivers.SQL.DBHost, + "db_port": cfg.PublicSharingDrivers.SQL.DBPort, + "db_name": cfg.PublicSharingDrivers.SQL.DBName, + "password_hash_cost": cfg.PublicSharingDrivers.SQL.PasswordHashCost, + "enable_expired_shares_cleanup": cfg.PublicSharingDrivers.SQL.EnableExpiredSharesCleanup, + "janitor_run_interval": cfg.PublicSharingDrivers.SQL.JanitorRunInterval, + }, + "cs3": map[string]interface{}{ + "gateway_addr": cfg.PublicSharingDrivers.CS3.ProviderAddr, + "provider_addr": cfg.PublicSharingDrivers.CS3.ProviderAddr, + "service_user_id": cfg.PublicSharingDrivers.CS3.SystemUserID, + "service_user_idp": cfg.PublicSharingDrivers.CS3.SystemUserIDP, + "machine_auth_apikey": cfg.PublicSharingDrivers.CS3.SystemUserAPIKey, + }, + } } From f2cbffa9389158effbd8eb0bd55e14feb5e8596c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 21 Jun 2022 14:33:20 +0200 Subject: [PATCH 4/5] Incorporate review suggestions --- ocis/pkg/command/migrate.go | 55 +++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/ocis/pkg/command/migrate.go b/ocis/pkg/command/migrate.go index 125a0cd60..b45bdf188 100644 --- a/ocis/pkg/command/migrate.go +++ b/ocis/pkg/command/migrate.go @@ -23,7 +23,7 @@ import ( func Migrate(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "migrate", - Usage: "migrate data from an existing instance to a new version", + Usage: "migrate data from an existing to another instance", Category: "migration", Before: func(c *cli.Context) error { if err := parser.ParseConfig(cfg, true); err != nil { @@ -46,7 +46,7 @@ func init() { func MigrateShares(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "shares", - Usage: "migrates shares from the previous to the new manager", + Usage: "migrates shares from the previous to the new share manager", Flags: []cli.Flag{ &cli.StringFlag{ Name: "from", @@ -56,7 +56,7 @@ func MigrateShares(cfg *config.Config) *cli.Command { &cli.StringFlag{ Name: "to", Value: "cs3", - Usage: "Share manager to import the data to", + Usage: "Share manager to import the data into", }, }, Before: func(c *cli.Context) error { @@ -65,7 +65,7 @@ func MigrateShares(cfg *config.Config) *cli.Command { fmt.Printf("%v", err) os.Exit(1) } - return err + return nil }, Action: func(c *cli.Context) error { log := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger() @@ -86,22 +86,24 @@ func MigrateShares(cfg *config.Config) *cli.Command { log.Error().Err(err).Msg("failed to initiate source share manager") os.Exit(1) } - if _, ok := oldMgr.(share.DumpableManager); !ok { + dumpMgr, ok := oldMgr.(share.DumpableManager) + if !ok { log.Error().Msg("Share manager type '" + oldDriver + "' does not support dumping its shares.") os.Exit(1) } f, ok = registry.NewFuncs[newDriver] if !ok { - log.Error().Msg("Unknown share manager type '" + oldDriver + "'") + log.Error().Msg("Unknown share manager type '" + newDriver + "'") os.Exit(1) } newMgr, err := f(rcfg[newDriver].(map[string]interface{})) if err != nil { - log.Error().Err(err).Msg("failed to initiate source share manager") + log.Error().Err(err).Msg("failed to initiate destination share manager") os.Exit(1) } - if _, ok := newMgr.(share.LoadableManager); !ok { + loadMgr, ok := newMgr.(share.LoadableManager) + if !ok { log.Error().Msg("Share manager type '" + newDriver + "' does not support loading a shares dump.") os.Exit(1) } @@ -110,7 +112,7 @@ func MigrateShares(cfg *config.Config) *cli.Command { wg.Add(2) go func() { log.Info().Msg("Migrating shares...") - err = newMgr.(share.LoadableManager).Load(ctx, shareChan, receivedShareChan) + err = loadMgr.Load(ctx, shareChan, receivedShareChan) log.Info().Msg("Finished migrating shares.") if err != nil { log.Error().Err(err).Msg("Error while loading shares") @@ -119,11 +121,13 @@ func MigrateShares(cfg *config.Config) *cli.Command { wg.Done() }() go func() { - err = oldMgr.(share.DumpableManager).Dump(ctx, shareChan, receivedShareChan) + err = dumpMgr.Dump(ctx, shareChan, receivedShareChan) if err != nil { log.Error().Err(err).Msg("Error while dumping shares") os.Exit(1) } + close(shareChan) + close(receivedShareChan) wg.Done() }() wg.Wait() @@ -135,17 +139,17 @@ func MigrateShares(cfg *config.Config) *cli.Command { func MigratePublicShares(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "publicshares", - Usage: "migrates public shares from the previous to the new manager", + Usage: "migrates public shares from the previous to the new public share manager", Flags: []cli.Flag{ &cli.StringFlag{ Name: "from", Value: "json", - Usage: "Share manager to export the data from", + Usage: "Public share manager to export the data from", }, &cli.StringFlag{ Name: "to", Value: "cs3", - Usage: "Share manager to import the data to", + Usage: "Public share manager to import the data into", }, }, Before: func(c *cli.Context) error { @@ -167,31 +171,33 @@ func MigratePublicShares(cfg *config.Config) *cli.Command { f, ok := publicregistry.NewFuncs[oldDriver] if !ok { - log.Error().Msg("Unknown share manager type '" + oldDriver + "'") + log.Error().Msg("Unknown public share manager type '" + oldDriver + "'") os.Exit(1) } oldMgr, err := f(rcfg[oldDriver].(map[string]interface{})) if err != nil { - log.Error().Err(err).Msg("failed to initiate source share manager") + log.Error().Err(err).Msg("failed to initiate source public share manager") os.Exit(1) } - if _, ok := oldMgr.(publicshare.DumpableManager); !ok { - log.Error().Msg("Publicshare manager type '" + oldDriver + "' does not support dumping its shares.") + dumpMgr, ok := oldMgr.(publicshare.DumpableManager) + if !ok { + log.Error().Msg("Public share manager type '" + oldDriver + "' does not support dumping its public shares.") os.Exit(1) } f, ok = publicregistry.NewFuncs[newDriver] if !ok { - log.Error().Msg("Unknown share manager type '" + oldDriver + "'") + log.Error().Msg("Unknown public share manager type '" + newDriver + "'") os.Exit(1) } newMgr, err := f(rcfg[newDriver].(map[string]interface{})) if err != nil { - log.Error().Err(err).Msg("failed to initiate source share manager") + log.Error().Err(err).Msg("failed to initiate destination public share manager") os.Exit(1) } - if _, ok := newMgr.(publicshare.LoadableManager); !ok { - log.Error().Msg("PUblicshare manager type '" + newDriver + "' does not support loading a shares dump.") + loadMgr, ok := newMgr.(publicshare.LoadableManager) + if !ok { + log.Error().Msg("Public share manager type '" + newDriver + "' does not support loading a public shares dump.") os.Exit(1) } @@ -199,20 +205,21 @@ func MigratePublicShares(cfg *config.Config) *cli.Command { wg.Add(2) go func() { log.Info().Msg("Migrating public shares...") - err = newMgr.(publicshare.LoadableManager).Load(ctx, shareChan) + err = loadMgr.Load(ctx, shareChan) log.Info().Msg("Finished migrating public shares.") if err != nil { - log.Error().Err(err).Msg("Error while loading shares") + log.Error().Err(err).Msg("Error while loading public shares") os.Exit(1) } wg.Done() }() go func() { - err = oldMgr.(publicshare.DumpableManager).Dump(ctx, shareChan) + err = dumpMgr.Dump(ctx, shareChan) if err != nil { log.Error().Err(err).Msg("Error while dumping public shares") os.Exit(1) } + close(shareChan) wg.Done() }() wg.Wait() From 54c352331c5ad10fa0a1f51f5cccf1074c38c114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 21 Jun 2022 15:32:54 +0200 Subject: [PATCH 5/5] Bump reva --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 84a6cceea..e7b814da6 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/blevesearch/bleve_index_api v1.0.2 github.com/coreos/go-oidc/v3 v3.2.0 github.com/cs3org/go-cs3apis v0.0.0-20220512100524-551800f020d8 - github.com/cs3org/reva/v2 v2.5.2-0.20220621092317-04f64d9da591 + github.com/cs3org/reva/v2 v2.5.2-0.20220621133128-d90c8aa60a15 github.com/disintegration/imaging v1.6.2 github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.1 diff --git a/go.sum b/go.sum index 969bfd41c..a00f582f2 100644 --- a/go.sum +++ b/go.sum @@ -294,8 +294,8 @@ github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3p github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4= github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A= github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= -github.com/cs3org/reva/v2 v2.5.2-0.20220621092317-04f64d9da591 h1:uorP+QgVZqMnsmDDAIhE9guwi2kjr4mmHNRvKHh5GI0= -github.com/cs3org/reva/v2 v2.5.2-0.20220621092317-04f64d9da591/go.mod h1:zAHqzr36X4lIalonDQeNbwrIXjn66C38lp5A+MTRS1c= +github.com/cs3org/reva/v2 v2.5.2-0.20220621133128-d90c8aa60a15 h1:isQbNMNY9PSWy0CWT1KQIdCyD85XUdu6Ww1HjIuR6uc= +github.com/cs3org/reva/v2 v2.5.2-0.20220621133128-d90c8aa60a15/go.mod h1:zAHqzr36X4lIalonDQeNbwrIXjn66C38lp5A+MTRS1c= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=