Skip to content

Commit

Permalink
copy dir
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Sep 5, 2023
1 parent 6ed2ae1 commit 63bc340
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions utils/io/fileutils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,13 @@ type FileDetails struct {

// Removing the provided path from the filesystem
func RemovePath(testPath string) error {
if _, err := os.Stat(testPath); err == nil {
if file, err := os.Stat(testPath); err == nil {
if file.IsDir() {
err = RemoveTempDir(testPath)
} else {
err = errorutils.CheckError(os.Remove(testPath))
}
// Delete the path
err = errors.Join(err, RemoveTempDir(testPath))
if err != nil {
return errors.New("Cannot remove path: " + testPath + " due to: " + err.Error())
}
Expand Down
13 changes: 7 additions & 6 deletions utils/io/fileutils/temp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
)

var (
Expand Down Expand Up @@ -81,21 +80,23 @@ func CleanOldDirs() error {
// Get all files at temp dir
files, err := os.ReadDir(tempDirBase)
if err != nil {
log.Error(err)
return errorutils.CheckError(err)
}
now := time.Now()
// Search for files/dirs that match the template.
for _, file := range files {
if strings.HasPrefix(file.Name(), tempPrefix) {
timeStamp, err := extractTimestamp(file.Name())
fileName := file.Name()
if strings.HasPrefix(fileName, tempPrefix) {
var timeStamp time.Time
timeStamp, err = extractTimestamp(fileName)
if err != nil {
return err
}
// Delete old file/dirs.
if now.Sub(timeStamp).Hours() > maxFileAge {
if err := os.RemoveAll(path.Join(tempDirBase, file.Name())); err != nil {
return errorutils.CheckError(err)
err = RemovePath(path.Join(tempDirBase, fileName))
if err != nil {
return err
}
}
}
Expand Down

0 comments on commit 63bc340

Please sign in to comment.