diff --git a/libraries_loader.go b/libraries_loader.go index 1730bf44..088ef8ed 100644 --- a/libraries_loader.go +++ b/libraries_loader.go @@ -30,9 +30,12 @@ package builder import ( + "math" "os" "path/filepath" + "strconv" "strings" + "time" "github.com/arduino/arduino-builder/constants" "github.com/arduino/arduino-builder/i18n" @@ -153,6 +156,11 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (* return nil, i18n.WrapError(err) } + timeDiff, newestFile := newestAndOldestFileDifferBy(libraryFolder) + if timeDiff > (5*time.Minute) && time.Since(newestFile) < 24*time.Hour { + library.IsBeingModified = true + } + if debugLevel >= 0 { for _, subFolder := range subFolders { if utils.IsSCCSOrHiddenFile(subFolder) { @@ -220,3 +228,22 @@ func appendPathToLibrariesFolders(librariesFolders []string, newLibrariesFolder return utils.AppendIfNotPresent(librariesFolders, newLibrariesFolder) } + +func newestAndOldestFileDifferBy(path string) (time.Duration, time.Time) { + var newestTime int64 = 0 + var oldestTime int64 = math.MaxInt64 + + filepath.Walk(path, + func(path string, info os.FileInfo, err error) error { + currTime := info.ModTime().Unix() + if currTime > newestTime { + newestTime = currTime + } + if currTime < oldestTime { + oldestTime = currTime + } + return nil + }) + duration, _ := time.ParseDuration(strconv.FormatInt(newestTime-oldestTime, 10) + "s") + return duration, time.Unix(newestTime, 0) +} diff --git a/types/types.go b/types/types.go index d535386d..4d2f6e80 100644 --- a/types/types.go +++ b/types/types.go @@ -162,26 +162,27 @@ const ( ) type Library struct { - Folder string - SrcFolder string - UtilityFolder string - Layout LibraryLayout - Name string - RealName string - Archs []string - DotALinkage bool - Precompiled bool - LDflags string - IsLegacy bool - Version string - Author string - Maintainer string - Sentence string - Paragraph string - URL string - Category string - License string - Properties map[string]string + Folder string + SrcFolder string + UtilityFolder string + Layout LibraryLayout + Name string + RealName string + Archs []string + DotALinkage bool + Precompiled bool + LDflags string + IsLegacy bool + Version string + Author string + Maintainer string + Sentence string + Paragraph string + URL string + Category string + License string + Properties map[string]string + IsBeingModified bool } func (library *Library) String() string {