Skip to content

Commit

Permalink
adjust file lock range
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Feb 17, 2023
1 parent 699b11e commit 57d20af
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions version_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ Success: %t
}

func (s *TestVersionSnapshot) Save(t *testing.T) error {
path, err := filepath.Abs(filepath.Clean(filepath.Join(s.ModuleRootFolder, s.SubModuleRelativeFolder, "TestRecord.md.tmp")))
if err != nil {
return err
}
unlock := recordFileLocks.Lock(path)
defer unlock()
s.load(t)
localPath, err := s.saveToLocal()
err = s.saveToLocal(path)
if err != nil {
return err
}
return s.copyForUploadArtifact(localPath)
return s.copyForUploadArtifact(path)
}

func (s *TestVersionSnapshot) copyForUploadArtifact(localPath string) error {
Expand All @@ -92,10 +98,8 @@ func (s *TestVersionSnapshot) copyForUploadArtifact(localPath string) error {
return copyFile(localPath, pathForUpload)
}

func (s *TestVersionSnapshot) saveToLocal() (string, error) {
path := filepath.Clean(filepath.Join(s.ModuleRootFolder, s.SubModuleRelativeFolder, "TestRecord.md.tmp"))
err := writeStringToFile(path, s.ToString())
return path, err
func (s *TestVersionSnapshot) saveToLocal(path string) error {
return writeStringToFile(path, s.ToString())
}

func copyFile(src, dst string) error {
Expand Down Expand Up @@ -132,8 +136,6 @@ func copyFile(src, dst string) error {

func writeStringToFile(filePath, str string) error {
cleanedFilePath := filepath.Clean(filePath)
unlock := recordFileLocks.Lock(cleanedFilePath)
defer unlock()
if files.FileExists(cleanedFilePath) {
if err := os.Remove(cleanedFilePath); err != nil {
return err
Expand Down

0 comments on commit 57d20af

Please sign in to comment.