ftctechnh/ftc_app

Latest matchlog is being deleted instead of old ones by RobotLog

ftc-team-astro-bruins opened this issue · 0 comments

Below function pruneMatchLogsIfNecessary, even though the author is wanting to delete the old logs the code actually deletes the latest logs. You can test this by creating 5 or more logs and see that after 5 logs are created it always deleted the latest log instead of the old one. I could not find the repo of FTC SDK, if you could point me to the original FTC SDK repo i can send you in the required change.
/*

  • pruneMatchLogsIfNecessary
  • Some reasonable upper bound on number of files to keep around. Remove via first in, first out.
    */
    protected static void pruneMatchLogsIfNecessary() {
    File directory = AppUtil.MATCH_LOG_FOLDER;
    File[] files = directory.listFiles();
if (files.length >= AppUtil.MAX_MATCH_LOGS_TO_KEEP) {
  Arrays.sort(files, new Comparator<File>() {
    public int compare(File f1, File f2) {
      /*
       * Reverse sorting on purpose.
       */
      return Long.compare(f2.lastModified(), f1.lastModified());
    }
  });

  /*
   * There should never be more than one extra log, but just to be paranoid...
   */
  for (int i = 0; i < files.length - AppUtil.MAX_MATCH_LOGS_TO_KEEP; i++) {
    RobotLog.ii(TAG, "Pruning old logs deleting " + files[i].getName());
    files[i].delete();
  }
}

}