-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4491 from dragonchaser/filename-incrementor
Add filename incrementor for secret filedrops.
- Loading branch information
Showing
10 changed files
with
162 additions
and
14 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
changelog/unreleased/fileincrementor-for-secret-file-drops.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Enhancement: Add filename incrementor for secret filedrops | ||
|
||
We have added a function that appends a number to the filename if the file already exists in a secret filedrop. | ||
This is useful if you want to upload a file with the same name multiple times. | ||
|
||
https://github.com/cs3org/reva/pull/4491 | ||
https://github.com/owncloud/ocis/issues/8291 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ocdav | ||
|
||
import ( | ||
"context" | ||
|
||
cs3storage "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" | ||
) | ||
|
||
type tokenStatInfoKey struct{} | ||
|
||
// ContextWithTokenStatInfo adds the token stat info to the context | ||
func ContextWithTokenStatInfo(ctx context.Context, info *cs3storage.ResourceInfo) context.Context { | ||
return context.WithValue(ctx, tokenStatInfoKey{}, info) | ||
} | ||
|
||
// TokenStatInfoFromContext returns the token stat info from the context | ||
func TokenStatInfoFromContext(ctx context.Context) (*cs3storage.ResourceInfo, bool) { | ||
v, ok := ctx.Value(tokenStatInfoKey{}).(*cs3storage.ResourceInfo) | ||
return v, ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ocdav | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
|
||
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" | ||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" | ||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" | ||
) | ||
|
||
// FindName returns the next filename available when the current | ||
func FindName(ctx context.Context, client gatewayv1beta1.GatewayAPIClient, name string, parentid *provider.ResourceId) (string, *rpc.Status, error) { | ||
lReq := &provider.ListContainerRequest{ | ||
Ref: &provider.Reference{ | ||
ResourceId: parentid, | ||
}, | ||
} | ||
lRes, err := client.ListContainer(ctx, lReq) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
if lRes.Status.Code != rpc.Code_CODE_OK { | ||
return "", lRes.Status, nil | ||
} | ||
// iterate over the listing to determine next suffix | ||
var itemMap = make(map[string]struct{}) | ||
for _, fi := range lRes.Infos { | ||
itemMap[fi.GetName()] = struct{}{} | ||
} | ||
ext := filepath.Ext(name) | ||
fileName := strings.TrimSuffix(name, ext) | ||
if strings.HasSuffix(fileName, ".tar") { | ||
fileName = strings.TrimSuffix(fileName, ".tar") | ||
ext = filepath.Ext(fileName) + "." + ext | ||
} | ||
// starts with two because "normal" humans begin counting with 1 and we say the existing file is the first one | ||
for i := 2; i < len(itemMap)+3; i++ { | ||
if _, ok := itemMap[fileName+" ("+strconv.Itoa(i)+")"+ext]; !ok { | ||
return fileName + " (" + strconv.Itoa(i) + ")" + ext, lRes.GetStatus(), nil | ||
} | ||
} | ||
return "", nil, errors.New("could not determine new filename") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters