From f66ba99f34d14a63f90910855e4f073c0456d349 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Thu, 28 Nov 2024 23:36:08 +0530 Subject: [PATCH] use path package --- dstorage/dstorage.go | 8 ++++++-- migration/migrate.go | 12 ++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dstorage/dstorage.go b/dstorage/dstorage.go index c0ec2a8..4e27109 100644 --- a/dstorage/dstorage.go +++ b/dstorage/dstorage.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "path" "path/filepath" "strconv" "strings" @@ -97,11 +98,14 @@ func (d *DStorageService) Replace(ctx context.Context, remotePath string, r io.R } func (d *DStorageService) Upload(ctx context.Context, remotePath string, r io.Reader, size int64, contentType string, isUpdate bool) sdk.OperationRequest { + if !path.IsAbs(remotePath) { + fmt.Println("Remote path is not absolute", remotePath) + } fileMeta := sdk.FileMeta{ - RemotePath: filepath.Clean(remotePath), + RemotePath: path.Clean(remotePath), ActualSize: size, MimeType: contentType, - RemoteName: filepath.Base(remotePath), + RemoteName: path.Base(remotePath), } opType := constants.FileOperationInsert diff --git a/migration/migrate.go b/migration/migrate.go index 4263f54..2fc2e9c 100644 --- a/migration/migrate.go +++ b/migration/migrate.go @@ -147,17 +147,17 @@ func InitMigration(mConfig *MigrationConfig) error { // use client id instead of access token to prevent expiry time ClientID, ClientSecret := util.GetClientCredentialsFromEnv() cfg := oauth2.Config{ - ClientID: ClientID, + ClientID: ClientID, ClientSecret: ClientSecret, Endpoint: oauth2.Endpoint{ - AuthURL :"https://accounts.google.com/o/oauth2/auth", - DeviceAuthURL :"https://oauth2.googleapis.com/device/code", - TokenURL :"https://oauth2.googleapis.com/token", + AuthURL: "https://accounts.google.com/o/oauth2/auth", + DeviceAuthURL: "https://oauth2.googleapis.com/device/code", + TokenURL: "https://oauth2.googleapis.com/token", }, } token := &oauth2.Token{ - AccessToken: util.GetAccessKeyFromEnv(), + AccessToken: util.GetAccessKeyFromEnv(), RefreshToken: util.GetRefreshKeyFromEnv(), } @@ -459,7 +459,7 @@ func getUniqueShortObjKey(objectKey string) string { } func getRemotePath(objectKey string) string { - return filepath.Join(migration.migrateTo, migration.bucket, getUniqueShortObjKey(objectKey)) + return path.Join(migration.migrateTo, migration.bucket, getUniqueShortObjKey(objectKey)) } func checkIsFileExist(ctx context.Context, downloadObj *DownloadObjectMeta) error {