View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  
18  package org.apache.logging.log4j.core.appender.rolling.action;
19  
20  import java.nio.file.Files;
21  import java.nio.file.Path;
22  import java.nio.file.attribute.BasicFileAttributes;
23  
24  /**
25   * Filter that accepts or rejects a candidate {@code Path} for deletion.
26   */
27  public interface PathCondition {
28  
29      /**
30       * Invoked before a new {@linkplain Files#walkFileTree(Path, java.util.Set, int, java.nio.file.FileVisitor) file
31       * tree walk} is started. Stateful PathConditions can reset their state when this method is called.
32       */
33      void beforeFileTreeWalk();
34  
35      /**
36       * Returns {@code true} if the specified candidate path should be deleted, {@code false} otherwise.
37       *
38       * @param baseDir the directory from where to start scanning for deletion candidate files
39       * @param relativePath the candidate for deletion. This path is relative to the baseDir.
40       * @param attrs attributes of the candidate path
41       * @return whether the candidate path should be deleted
42       */
43      boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs);
44  }