Skip to content

Commit

Permalink
Made FilesAreOlderThan function to rationalize code
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Aug 28, 2023
1 parent b193537 commit 8b7738f
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions legacy/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ func findAllFilesInFolder(sourcePath *paths.Path, recurse bool) (paths.PathList,
paths.FilterOutDirectories())
}

// FilesAreOlderThan returns true if the given files are older than target.
func FilesAreOlderThan(files paths.PathList, target *paths.Path) (bool, error) {
targetStat, err := target.Stat()
if err != nil {
return false, err
}
targetModTime := targetStat.ModTime()
for _, file := range files {
file, err := file.Stat()
if err != nil {
return false, err
}
if file.ModTime().After(targetModTime) {
return false, nil
}
}
return true, nil
}

func CompileFiles(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
return compileFiles(ctx, sourcePath, false, buildPath, buildProperties, includes)
}
Expand Down Expand Up @@ -310,51 +329,35 @@ func removeEndingBackSlash(s string) string {
}

func CoreOrReferencedCoreHasChanged(corePath, targetCorePath, targetFile *paths.Path) bool {
files, err := findAllFilesInFolder(corePath, true)
if err != nil {
return true
}

targetFileStat, err := targetFile.Stat()
if err == nil {
files, err := findAllFilesInFolder(corePath, true)
if err != nil {
return true
}
for _, file := range files {
fileStat, err := file.Stat()
if err != nil || fileStat.ModTime().After(targetFileStat.ModTime()) {
return true
}
}
if targetCorePath != nil && !strings.EqualFold(corePath.String(), targetCorePath.String()) {
return CoreOrReferencedCoreHasChanged(targetCorePath, nil, targetFile)
}
return false
if isOlder, err := FilesAreOlderThan(files, targetFile); err != nil || !isOlder {
return true
}

if targetCorePath != nil && !strings.EqualFold(corePath.String(), targetCorePath.String()) {
return CoreOrReferencedCoreHasChanged(targetCorePath, nil, targetFile)
}
return true
return false
}

func TXTBuildRulesHaveChanged(corePath, targetCorePath, targetFile *paths.Path) bool {
files, err := utils.FindFilesInFolder(corePath, true, []string{".txt"})
if err != nil {
return true
}

targetFileStat, err := targetFile.Stat()
if err == nil {
files, err := findAllFilesInFolder(corePath, true)
if err != nil {
return true
}
for _, file := range files {
// report changes only for .txt files
if file.Ext() != ".txt" {
continue
}
fileStat, err := file.Stat()
if err != nil || fileStat.ModTime().After(targetFileStat.ModTime()) {
return true
}
}
if targetCorePath != nil && !corePath.EqualsTo(targetCorePath) {
return TXTBuildRulesHaveChanged(targetCorePath, nil, targetFile)
}
return false
if isOlder, err := FilesAreOlderThan(files, targetFile); err != nil || !isOlder {
return true
}

if targetCorePath != nil && !corePath.EqualsTo(targetCorePath) {
return TXTBuildRulesHaveChanged(targetCorePath, nil, targetFile)
}
return true
return false
}

func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile *paths.Path, objectFilesToArchive paths.PathList, buildProperties *properties.Map) (*paths.Path, error) {
Expand Down

0 comments on commit 8b7738f

Please sign in to comment.