Skip to content

Commit

Permalink
fix critical CleanUp LocalDateTime.now() calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
kochetkov-ma committed Jul 10, 2022
1 parent 7ee9943 commit 611e25a
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public class CleanUpProperties {
private final Collection<PathCleanUpItem> paths;
private final int minAge;

private final transient LocalDateTime closestEdgeDate;
private final transient LocalDateTime edgeDate;

public CleanUpProperties() {
this(false, MIDNIGHT, 0, Collections.emptyList());
}
Expand All @@ -42,8 +39,14 @@ public CleanUpProperties(boolean dryRun, LocalTime time, int ageDays, Collection
this.paths = defaultIfNull(paths, Collections.emptyList());

this.minAge = concat(Stream.of(ageDays), this.paths.stream().map(PathCleanUpItem::getAgeDays)).min(naturalOrder()).orElse(0);
this.closestEdgeDate = LocalDateTime.now().minusDays(this.minAge);
this.edgeDate = LocalDateTime.now().minusDays(this.ageDays);
}

public LocalDateTime getClosestEdgeDate() {
return LocalDateTime.now().minusDays(this.minAge);
}

public LocalDateTime getEdgeDate() {
return LocalDateTime.now().minusDays(this.ageDays);
}

public boolean isNotDryRun() {
Expand All @@ -56,12 +59,13 @@ public static class PathCleanUpItem {
private final String path;
private final int ageDays;

private final transient LocalDateTime edgeDate;

public PathCleanUpItem(String path, int ageDays) {
this.path = path;
this.ageDays = ageDays;
this.edgeDate = LocalDateTime.now().minusDays(this.ageDays);
}

public LocalDateTime getEdgeDate() {
return LocalDateTime.now().minusDays(this.ageDays);
}
}
}

0 comments on commit 611e25a

Please sign in to comment.