Skip to content

Commit

Permalink
Remove deprecated CLI commands
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Oct 29, 2024
1 parent 5fc891c commit f16c7de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 104 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/remove-deprecated-cli-commans.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Remove deprecated CLI commands

We removed the following deprecated CLI commands:
`ocis storage-users uploads list`
`ocis storage-users uploads clean`

https://github.com/owncloud/ocis/pull/10430
https://github.com/owncloud/ocis/issues/10428
104 changes: 0 additions & 104 deletions services/storage-users/pkg/command/uploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"strconv"
"strings"
"sync"
"time"

tw "github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -47,53 +46,7 @@ func Uploads(cfg *config.Config) *cli.Command {
Name: "uploads",
Usage: "manage unfinished uploads",
Subcommands: []*cli.Command{
ListUploads(cfg),
ListUploadSessions(cfg),
PurgeExpiredUploads(cfg),
},
}
}

// ListUploads prints a list of all incomplete uploads
func ListUploads(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "list",
Usage: "Print a list of all incomplete uploads (deprecated, use sessions)",
Before: func(c *cli.Context) error {
return configlog.ReturnFatal(parser.ParseConfig(cfg))
},
Action: func(c *cli.Context) error {
fmt.Println("Warning: This command is deprecated, use 'uploads sessions' instead")

f, ok := registry.NewFuncs[cfg.Driver]
if !ok {
fmt.Fprintf(os.Stderr, "Unknown filesystem driver '%s'\n", cfg.Driver)
os.Exit(1)
}
drivers := revaconfig.StorageProviderDrivers(cfg)
fs, err := f(drivers[cfg.Driver].(map[string]interface{}), nil)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize filesystem driver '%s'\n", cfg.Driver)
return err
}

managingFS, ok := fs.(storage.UploadSessionLister)
if !ok {
fmt.Fprintf(os.Stderr, "'%s' storage does not support listing upload sessions\n", cfg.Driver)
os.Exit(1)
}
expired := false
uploads, err := managingFS.ListUploadSessions(c.Context, storage.UploadSessionFilter{Expired: &expired})
if err != nil {
return err
}

fmt.Println("Incomplete uploads:")
for _, u := range uploads {
ref := u.Reference()
fmt.Printf(" - %s (Space: %s, Name: %s, Size: %d/%d, Expires: %s, Processing: %t)\n", u.ID(), ref.GetResourceId().GetSpaceId(), u.Filename(), u.Offset(), u.Size(), u.Expires(), u.IsProcessing())
}
return nil
},
}
}
Expand Down Expand Up @@ -258,63 +211,6 @@ func ListUploadSessions(cfg *config.Config) *cli.Command {
}
}

// PurgeExpiredUploads is the entry point for the clean command
func PurgeExpiredUploads(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "clean",
Usage: "Clean up leftovers from expired uploads",
Before: func(c *cli.Context) error {
return configlog.ReturnFatal(parser.ParseConfig(cfg))
},
Action: func(c *cli.Context) error {
fmt.Println("Warning: This command is deprecated, use 'uploads sessions --clean' instead")
f, ok := registry.NewFuncs[cfg.Driver]
if !ok {
fmt.Fprintf(os.Stderr, "Unknown filesystem driver '%s'\n", cfg.Driver)
os.Exit(1)
}
drivers := revaconfig.StorageProviderDrivers(cfg)
fs, err := f(drivers[cfg.Driver].(map[string]interface{}), nil)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize filesystem driver '%s'\n", cfg.Driver)
return err
}

managingFS, ok := fs.(storage.UploadSessionLister)
if !ok {
fmt.Fprintf(os.Stderr, "'%s' storage does not support clean expired uploads\n", cfg.Driver)
os.Exit(1)
}

wg := sync.WaitGroup{}
wg.Add(1)
processing := false
expired := true
uploads, err := managingFS.ListUploadSessions(c.Context, storage.UploadSessionFilter{Expired: &expired, Processing: &processing})
if err != nil {
return err
}

fmt.Println("purging uploads:")
go func() {
for _, u := range uploads {
ref := u.Reference()
fmt.Printf(" - %s (Space: %s, Name: %s, Size: %d/%d, Expires: %s, Processing: %t)\n", ref.GetResourceId().GetSpaceId(), u.ID(), u.Filename(), u.Offset(), u.Size(), u.Expires(), u.IsProcessing())
u.Purge(c.Context)
}
wg.Done()
}()

wg.Wait()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to clean expired uploads '%s'\n", err)
return err
}
return nil
},
}
}

func buildFilter(c *cli.Context) storage.UploadSessionFilter {
filter := storage.UploadSessionFilter{}
if c.IsSet("processing") {
Expand Down

0 comments on commit f16c7de

Please sign in to comment.