001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017
018package org.apache.logging.log4j.core.appender.rolling.action;
019
020import java.nio.file.Files;
021import java.nio.file.Path;
022import java.nio.file.attribute.BasicFileAttributes;
023
024/**
025 * Filter that accepts or rejects a candidate {@code Path} for deletion.
026 */
027public interface PathCondition {
028
029    /**
030     * Invoked before a new {@linkplain Files#walkFileTree(Path, java.util.Set, int, java.nio.file.FileVisitor) file
031     * tree walk} is started. Stateful PathConditions can reset their state when this method is called.
032     */
033    void beforeFileTreeWalk();
034
035    /**
036     * Returns {@code true} if the specified candidate path should be deleted, {@code false} otherwise.
037     *
038     * @param baseDir the directory from where to start scanning for deletion candidate files
039     * @param relativePath the candidate for deletion. This path is relative to the baseDir.
040     * @param attrs attributes of the candidate path
041     * @return whether the candidate path should be deleted
042     */
043    boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs);
044}