diff --git a/lib/datestampedfileops.js b/lib/datestampedfileops.js index da501d2..aeabb90 100644 --- a/lib/datestampedfileops.js +++ b/lib/datestampedfileops.js @@ -89,9 +89,14 @@ function DateStampedFileOps(logpath, totalFiles, totalSize, gzip) { }); } + function filterUnstattedFiles(logstats, next) { + filteredlogstats = logstats.filter(logstat => logstat && logstat.stat && logstat.stat.mtime); + next(null, filteredlogstats); + } + function sortFilesByModifiedTime(logstats, next) { async.sortBy(logstats, function (logstat, next) { - next(null, -_.get(logstat,'stat.mtime')); + next(null, -logstat?.stat?.mtime); }, next); } @@ -141,6 +146,7 @@ function DateStampedFileOps(logpath, totalFiles, totalSize, gzip) { getFilesInLogDirectory, filterJustOurLogFiles(matchzippedfiles), statEachFile, + filterUnstattedFiles, sortFilesByModifiedTime ], function (err, logfiles) { next(err, logfiles);