Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Latest matchlog is being deleted instead of old ones by RobotLog #673

Open
ftc-team-astro-bruins opened this issue Jan 2, 2019 · 0 comments

Comments

@ftc-team-astro-bruins
Copy link

ftc-team-astro-bruins commented Jan 2, 2019

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();
  }
}

}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant