From 4626771e78d4ab025a25fba8a8faf26f1a9f6ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renato=20Guimar=C3=A3es?= Date: Mon, 12 Sep 2022 16:37:04 -0300 Subject: [PATCH] fix(storage-client): Path Rename (#71) --- pkg/common/clients/storage_client.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/common/clients/storage_client.go b/pkg/common/clients/storage_client.go index a42a983..2da2b51 100644 --- a/pkg/common/clients/storage_client.go +++ b/pkg/common/clients/storage_client.go @@ -19,7 +19,7 @@ type StorageClientInterface interface { CreateDirectory(relativePath string) error RemoveDirectory(relativePath string) error CheckIfExists(relativePath string) bool - Rename(fromRelativePath, toAbsolutePath string) bool + Rename(fromRelativePath, toAbsolutePath string) error } // NewStorageClient returns an initialized struct with the required dependencies injected @@ -37,12 +37,11 @@ func (sc *StorageClient) BasePath() string { // CreateDirectory attempts to create a directory to hold requirements.txt func (sc *StorageClient) CreateDirectory(relativePath string) error { - fullPath := fmt.Sprintf("%s/%s", sc.configuration.BasePath, relativePath) - - sc.logger.Infof("attempting to create directory %s", fullPath) + sc.logger.Infof("attempting to create directory %s", relativePath) + fullPath := fmt.Sprintf("%s/%s", sc.configuration.BasePath, relativePath) if _, err := os.Stat(fullPath); os.IsNotExist(err) { - sc.logger.Errorf("while create path %s", relativePath) + sc.logger.Errorf("while create path %s. Error:", relativePath, err) return os.MkdirAll(fullPath, os.ModePerm) } @@ -54,7 +53,7 @@ func (sc *StorageClient) RemoveDirectory(relativePath string) error { fullPath := fmt.Sprintf("%s/%s", sc.configuration.BasePath, relativePath) sc.logger.Infof("attempting to remove %s", fullPath) if err := os.RemoveAll(fullPath); err != nil { - sc.logger.Errorf("while remove path %s", relativePath) + sc.logger.Errorf("while remove path %s. Error:", relativePath, err) return err } return nil @@ -64,7 +63,7 @@ func (sc *StorageClient) RemoveDirectory(relativePath string) error { func (sc *StorageClient) CheckIfExists(relativePath string) bool { fullPath := fmt.Sprintf("%s/%s", sc.configuration.BasePath, relativePath) if _, err := os.Stat(fullPath); err != nil && os.IsNotExist(err) { - sc.logger.Errorf("while check path %s", relativePath) + sc.logger.Errorf("while check path %s. Error:", relativePath, err) return false } @@ -72,12 +71,12 @@ func (sc *StorageClient) CheckIfExists(relativePath string) bool { } // Rename attempts to rename a path -func (sc *StorageClient) Rename(fromRelativePath, toAbsolutePath string) bool { +func (sc *StorageClient) Rename(fromRelativePath, toAbsolutePath string) error { sc.logger.Infof("attempting to rename from %s to %s", fromRelativePath, toAbsolutePath) if err := os.Rename(fromRelativePath, toAbsolutePath); err != nil { - sc.logger.Errorf("while rename path from %s to %s", fromRelativePath, toAbsolutePath) - return false + sc.logger.Errorf("while rename path from %s to %s. Error:", fromRelativePath, toAbsolutePath, err) + return err } - return true + return nil }