Skip to content

Commit

Permalink
fix(storage-client): Path Rename (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoaguimaraes authored Sep 12, 2022
1 parent 8dfba5c commit 4626771
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pkg/common/clients/storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand All @@ -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
Expand All @@ -64,20 +63,20 @@ 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
}

return true
}

// 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
}

0 comments on commit 4626771

Please sign in to comment.