aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/arangodb/helpers.go
diff options
context:
space:
mode:
authorgfx <86091021+gfxlabs@users.noreply.github.com>2022-09-09 11:43:42 -0500
committerGitHub <noreply@github.com>2022-09-09 09:43:42 -0700
commit48db56ddade2ef076fae4498ca9357a280270bc5 (patch)
tree458a2facf0a6f1559210260b846e2679a33eb98b /weed/filer/arangodb/helpers.go
parent10d545060f5b1ef517786857726f409ed0f95652 (diff)
downloadseaweedfs-48db56ddade2ef076fae4498ca9357a280270bc5.tar.xz
seaweedfs-48db56ddade2ef076fae4498ca9357a280270bc5.zip
arangodb s3 bucket name compatibility (#3588)
* Update arangodb_store.go * update readme, properly escape queries, add name patching * use underscore * use underscore * better comment * fix readme Co-authored-by: a <a@a.a>
Diffstat (limited to 'weed/filer/arangodb/helpers.go')
-rw-r--r--weed/filer/arangodb/helpers.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/weed/filer/arangodb/helpers.go b/weed/filer/arangodb/helpers.go
index 3f36acb0a..776e6d1b8 100644
--- a/weed/filer/arangodb/helpers.go
+++ b/weed/filer/arangodb/helpers.go
@@ -12,7 +12,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/util"
)
-//convert a string into arango-key safe hex bytes hash
+// convert a string into arango-key safe hex bytes hash
func hashString(dir string) string {
h := md5.New()
io.WriteString(h, dir)
@@ -98,8 +98,26 @@ func (store *ArangodbStore) ensureBucket(ctx context.Context, bucket string) (bc
return store.buckets[bucket], nil
}
+// transform to an arango compliant name
+func bucketToCollectionName(s string) string {
+ if len(s) == 0 {
+ return ""
+ }
+ // replace all "." with _
+ s = strings.ReplaceAll(s, ".", "_")
+
+ // if starts with number or '.' then add a special prefix
+ if (s[0] >= '0' && s[0] <= '9') || (s[0] == '.' || s[0] == '_' || s[0] == '-') {
+ s = "xN--" + s
+ }
+ return s
+}
+
// creates collection if not exist, ensures indices if not exist
-func (store *ArangodbStore) ensureCollection(ctx context.Context, name string) (c driver.Collection, err error) {
+func (store *ArangodbStore) ensureCollection(ctx context.Context, bucket_name string) (c driver.Collection, err error) {
+ // convert the bucket to collection name
+ name := bucketToCollectionName(bucket_name)
+
ok, err := store.database.CollectionExists(ctx, name)
if err != nil {
return