bump reva to use UploadSessionLister interface

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2023-11-30 17:27:42 +01:00
parent 26411f1f3b
commit a6a7c69e8f
10 changed files with 373 additions and 164 deletions
+17 -23
View File
@@ -3,11 +3,8 @@ package command
import (
"fmt"
"os"
"strconv"
"sync"
"time"
tusd "github.com/tus/tusd/pkg/handler"
"github.com/urfave/cli/v2"
"github.com/cs3org/reva/v2/pkg/storage"
@@ -51,20 +48,21 @@ func ListUploads(cfg *config.Config) *cli.Command {
return err
}
managingFS, ok := fs.(storage.UploadsManager)
managingFS, ok := fs.(storage.UploadSessionLister)
if !ok {
fmt.Fprintf(os.Stderr, "'%s' storage does not support listing expired uploads\n", cfg.Driver)
os.Exit(1)
}
uploads, err := managingFS.ListUploads()
falseValue := false
uploads, err := managingFS.ListUploadSessions(c.Context, storage.UploadSessionFilter{Expired: &falseValue})
if err != nil {
return err
}
fmt.Println("Incomplete uploads:")
for _, u := range uploads {
fmt.Printf(" - %s (%s, Size: %d, Expires: %s)\n", u.ID, u.MetaData["filename"], u.Size, expiredString(u.MetaData["expires"]))
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())
}
return nil
},
@@ -92,7 +90,7 @@ func PurgeExpiredUploads(cfg *config.Config) *cli.Command {
return err
}
managingFS, ok := fs.(storage.UploadsManager)
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)
@@ -100,18 +98,23 @@ func PurgeExpiredUploads(cfg *config.Config) *cli.Command {
wg := sync.WaitGroup{}
wg.Add(1)
purgedChannel := make(chan tusd.FileInfo)
falseValue := false
trueValue := false
uploads, err := managingFS.ListUploadSessions(c.Context, storage.UploadSessionFilter{Expired: &trueValue, Processing: &falseValue})
if err != nil {
return err
}
fmt.Println("Cleaned uploads:")
fmt.Println("purging uploads:")
go func() {
for purged := range purgedChannel {
fmt.Printf(" - %s (%s, Size: %d, Expires: %s)\n", purged.ID, purged.MetaData["filename"], purged.Size, expiredString(purged.MetaData["expires"]))
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()
}()
err = managingFS.PurgeExpiredUploads(purgedChannel)
close(purgedChannel)
wg.Wait()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to clean expired uploads '%s'\n", err)
@@ -121,12 +124,3 @@ func PurgeExpiredUploads(cfg *config.Config) *cli.Command {
},
}
}
func expiredString(e string) string {
expired := "N/A"
iExpires, err := strconv.Atoi(e)
if err == nil {
expired = time.Unix(int64(iExpires), 0).Format(time.RFC3339)
}
return expired
}