Skip to content

Commit

Permalink
go routine gets file path instead of whole config
Browse files Browse the repository at this point in the history
  • Loading branch information
jpappa200 committed Feb 10, 2023
1 parent 353669f commit 528b067
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions cache-config/t3c-apply/util/gitutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -204,24 +203,18 @@ func makeGitCommitMsg(cfg config.Cfg, now time.Time, self bool, success bool) st
return strings.Join([]string{appStr, selfStr, modeStr, successStr, timeStr}, sep)
}

const gitLock = ".git/index.lock"

func IsGitLockFileOld(cfg config.Cfg, now time.Time, maxAge time.Duration) (bool, error) {

lockFile := filepath.Join(cfg.TsConfigDir, gitLock)
oldLock := maxAge * time.Minute
func IsGitLockFileOld(lockFile string, now time.Time, maxAge time.Duration) (bool, error) {
lockFileInfo, err := os.Stat(lockFile)
if err != nil {
return false, fmt.Errorf("stat returned error: %v on file %v", err, lockFile)
}
if diff := now.Sub(lockFileInfo.ModTime()); diff > oldLock {
if diff := now.Sub(lockFileInfo.ModTime()); diff > maxAge {
return true, nil
}
return false, nil
}

func RemoveGitLock(cfg config.Cfg) error {
lockFile := filepath.Join(cfg.TsConfigDir, gitLock)
func RemoveGitLock(lockFile string) error {
err := os.Remove(lockFile)
if err != nil {
return fmt.Errorf("error removing file: %v, %v", lockFile, err.Error())
Expand Down

0 comments on commit 528b067

Please sign in to comment.