| 
30 | 30 | package builder  | 
31 | 31 | 
 
  | 
32 | 32 | import (  | 
 | 33 | +	"math"  | 
33 | 34 | 	"os"  | 
34 | 35 | 	"path/filepath"  | 
 | 36 | +	"strconv"  | 
35 | 37 | 	"strings"  | 
 | 38 | +	"time"  | 
36 | 39 | 
 
  | 
37 | 40 | 	"github.com/arduino/arduino-builder/constants"  | 
38 | 41 | 	"github.com/arduino/arduino-builder/i18n"  | 
@@ -153,6 +156,11 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*  | 
153 | 156 | 		return nil, i18n.WrapError(err)  | 
154 | 157 | 	}  | 
155 | 158 | 
 
  | 
 | 159 | +	timeDiff, newestFile := newestAndOldestFileDifferBy(libraryFolder)  | 
 | 160 | +	if timeDiff > (5*time.Minute) && time.Since(newestFile) < 24*time.Hour {  | 
 | 161 | +		library.IsBeingModified = true  | 
 | 162 | +	}  | 
 | 163 | + | 
156 | 164 | 	if debugLevel >= 0 {  | 
157 | 165 | 		for _, subFolder := range subFolders {  | 
158 | 166 | 			if utils.IsSCCSOrHiddenFile(subFolder) {  | 
@@ -220,3 +228,22 @@ func appendPathToLibrariesFolders(librariesFolders []string, newLibrariesFolder  | 
220 | 228 | 
 
  | 
221 | 229 | 	return utils.AppendIfNotPresent(librariesFolders, newLibrariesFolder)  | 
222 | 230 | }  | 
 | 231 | + | 
 | 232 | +func newestAndOldestFileDifferBy(path string) (time.Duration, time.Time) {  | 
 | 233 | +	var newestTime int64 = 0  | 
 | 234 | +	var oldestTime int64 = math.MaxInt64  | 
 | 235 | + | 
 | 236 | +	filepath.Walk(path,  | 
 | 237 | +		func(path string, info os.FileInfo, err error) error {  | 
 | 238 | +			currTime := info.ModTime().Unix()  | 
 | 239 | +			if currTime > newestTime {  | 
 | 240 | +				newestTime = currTime  | 
 | 241 | +			}  | 
 | 242 | +			if currTime < oldestTime {  | 
 | 243 | +				oldestTime = currTime  | 
 | 244 | +			}  | 
 | 245 | +			return nil  | 
 | 246 | +		})  | 
 | 247 | +	duration, _ := time.ParseDuration(strconv.FormatInt(newestTime-oldestTime, 10) + "s")  | 
 | 248 | +	return duration, time.Unix(newestTime, 0)  | 
 | 249 | +}  | 
0 commit comments