Skip to content

Commit

Permalink
Update UUID package import to use Google's UUID package
Browse files Browse the repository at this point in the history
  • Loading branch information
divyam234 committed Apr 20, 2024
1 parent c947190 commit e6067a8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
5 changes: 2 additions & 3 deletions backend/teldrive/teldrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strings"
"time"

"github.com/gofrs/uuid"
"github.com/google/uuid"
"github.com/rclone/rclone/backend/teldrive/api"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config"
Expand Down Expand Up @@ -594,8 +594,7 @@ func (f *Fs) putUnchecked(ctx context.Context, in0 io.Reader, src fs.ObjectInfo,
partReader := io.LimitReader(in, chunkSize)

if f.opt.RandomisePart {
u1, _ := uuid.NewV4()
partName = hex.EncodeToString(u1.Bytes())
partName = getMD5Hash(uuid.New().String())
} else if totalParts > 1 {
partName = fmt.Sprintf("%s.part.%03d", leaf, partNo)
}
Expand Down
12 changes: 8 additions & 4 deletions backend/teldrive/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package teldrive

import (
"context"
"crypto/md5"
"encoding/hex"
"fmt"
"io"
Expand All @@ -11,7 +12,7 @@ import (
"strconv"
"sync"

"github.com/gofrs/uuid"
"github.com/google/uuid"
"github.com/rclone/rclone/backend/teldrive/api"
"github.com/rclone/rclone/lib/rest"

Expand Down Expand Up @@ -40,6 +41,11 @@ type objectChunkWriter struct {
encryptFile bool
}

func getMD5Hash(text string) string {
hash := md5.Sum([]byte(text))
return hex.EncodeToString(hash[:])
}

// WriteChunk will write chunk number with reader bytes, where chunk number >= 0
func (w *objectChunkWriter) WriteChunk(ctx context.Context, chunkNumber int, reader io.ReadSeeker) (size int64, err error) {
if chunkNumber < 0 {
Expand Down Expand Up @@ -78,10 +84,8 @@ func (w *objectChunkWriter) WriteChunk(ctx context.Context, chunkNumber int, rea

fs.Debugf(w.o, "Sending chunk %d length %d", chunkNumber, size)
if w.f.opt.RandomisePart {
u1, _ := uuid.NewV4()
partName = hex.EncodeToString(u1.Bytes())
partName = getMD5Hash(uuid.New().String())
} else {

partName = fileName
if w.totalParts > 1 {
partName = fmt.Sprintf("%s.part.%03d", fileName, chunkNumber)
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ require (
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.18.0
github.com/putdotio/go-putio/putio v0.0.0-20200123120452-16d982cac2b8
github.com/rclone/gofakes3 v0.0.3-0.20240413171058-b7a9fdb78ddb
github.com/rfjakob/eme v1.1.2
github.com/rivo/uniseg v0.4.4
github.com/rogpeppe/go-internal v1.11.0
Expand Down Expand Up @@ -118,7 +119,6 @@ require (
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-resty/resty/v2 v2.11.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand Down Expand Up @@ -158,7 +158,6 @@ require (
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 // indirect
github.com/rclone/gofakes3 v0.0.3-0.20240413171058-b7a9fdb78ddb // indirect
github.com/relvacode/iso8601 v1.3.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
Expand Down Expand Up @@ -458,8 +456,6 @@ github.com/quic-go/qtls-go1-20 v0.4.1 h1:D33340mCNDAIKBqXuAvexTNMUByrYmFYVfKfDN5
github.com/quic-go/quic-go v0.40.1 h1:X3AGzUNFs0jVuO3esAGnTfvdgvL4fq655WaOi1snv1Q=
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 h1:UVArwN/wkKjMVhh2EQGC0tEc1+FqiLlvYXY5mQ2f8Wg=
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93/go.mod h1:Nfe4efndBz4TibWycNE+lqyJZiMX4ycx+QKV8Ta0f/o=
github.com/rclone/gofakes3 v0.0.3-0.20240413163749-372c3e746e45 h1:qrH/G7j3Ru2E6tuKaNvpA+KD9uQSujTTMyQoonCJ7kU=
github.com/rclone/gofakes3 v0.0.3-0.20240413163749-372c3e746e45/go.mod h1:L0VIBE0mT6ArN/5dfHsJm3UjqCpi5B/cdN+qWDNh7ko=
github.com/rclone/gofakes3 v0.0.3-0.20240413171058-b7a9fdb78ddb h1:HJJ7XgRBfXew3EosVk45aGPJRY5wSTSpmAJqz8Kiw0w=
github.com/rclone/gofakes3 v0.0.3-0.20240413171058-b7a9fdb78ddb/go.mod h1:L0VIBE0mT6ArN/5dfHsJm3UjqCpi5B/cdN+qWDNh7ko=
github.com/relvacode/iso8601 v1.3.0 h1:HguUjsGpIMh/zsTczGN3DVJFxTU/GX+MMmzcKoMO7ko=
Expand Down

0 comments on commit e6067a8

Please sign in to comment.