Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added listversions command #4301

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/list-versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Added listversions command

https://github.com/cs3org/reva/pull/4301
67 changes: 67 additions & 0 deletions cmd/reva/listversions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2018-2023 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package main

import (
"fmt"
"io"

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/pkg/errors"
)

func listVersionsCommand() *command {
cmd := newCommand("listversions")
cmd.Description = func() string { return "list the versions of a file" }
cmd.Usage = func() string { return "Usage: listversions <file_name>" }

cmd.Action = func(w ...io.Writer) error {
if cmd.NArg() < 1 {
return errors.New("Invalid arguments: " + cmd.Usage())
}

fn := cmd.Args()[0]
client, err := getClient()
if err != nil {
return err
}

ref := &provider.Reference{Path: fn}
req := &provider.ListFileVersionsRequest{Ref: ref}

ctx := getAuthContext()
res, err := client.ListFileVersions(ctx, req)
if err != nil {
return err
}

if res.Status.Code != rpc.Code_CODE_OK {
return formatError(res.Status)
}

vers := res.Versions
for _, info := range vers {
fmt.Printf("Key: %s Size: %d mtime:%d\n", info.Key, info.Size, info.Mtime)
}

return nil
}
return cmd
}
1 change: 1 addition & 0 deletions cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
loginCommand(),
whoamiCommand(),
lsCommand(),
listVersionsCommand(),
statCommand(),
uploadCommand(),
downloadCommand(),
Expand Down
14 changes: 11 additions & 3 deletions pkg/eosclient/eosgrpc/eoshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,6 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
log.Debug().Str("func", "PUTFile").Msg("sending req")

resp, err := c.doReq(req, remoteuser)
if resp != nil {
resp.Body.Close()
}

// Let's support redirections... and if we retry we retry at the same FST
if resp != nil && resp.StatusCode == 307 {
Expand Down Expand Up @@ -424,6 +421,9 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos

log.Debug().Str("func", "PUTFile").Str("location", loc.String()).Msg("redirection")
nredirs++
if (resp != nil) && (resp.Body != nil) {
resp.Body.Close()
}
resp = nil
err = nil
continue
Expand All @@ -432,12 +432,17 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
// And get an error code (if error) that is worth propagating
e := c.getRespError(resp, err)
if e != nil {
if (resp != nil) && (resp.Body != nil) {
resp.Body.Close()
}
if os.IsTimeout(e) {
ntries++
log.Warn().Str("func", "PUTFile").Str("url", finalurl).Str("err", e.Error()).Int("try", ntries).Msg("recoverable network timeout")
continue
}

log.Error().Str("func", "PUTFile").Str("url", finalurl).Str("err", e.Error()).Msg("")

return e
}

Expand All @@ -446,6 +451,9 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
return errtypes.NotFound(fmt.Sprintf("url: %s", finalurl))
}

if (resp != nil) && (resp.Body != nil) {
resp.Body.Close()
}
return nil
}
}
Expand Down