Skip to content

Commit

Permalink
DD-1492 dd-manage-deposits improvemnets fixes for DD-1419 - Part 2 di…
Browse files Browse the repository at this point in the history
…rectory search depth limit
  • Loading branch information
Ali Sheikhi authored and Ali Sheikhi committed Feb 8, 2024
1 parent ecc1fef commit 90eb06a
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2023 DANS - Data Archiving and Networked Services ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.managedeposit.core.service;

import org.apache.commons.io.filefilter.AbstractFileFilter;

import java.io.File;
import java.nio.file.Path;

public class DepthFileFilter extends AbstractFileFilter {
private final Path baseFolder;
private final int depthLimit;

public DepthFileFilter(Path baseFolder, int depthLimit) {
this.baseFolder = baseFolder;
this.depthLimit = depthLimit;

}

public boolean accept(File file) {
Path parent = file.toPath();
for (int depth = 0; depth < this.depthLimit; depth++)
parent = parent.getParent();
if (parent.endsWith(this.baseFolder))
return true;

return false;
}
}

0 comments on commit 90eb06a

Please sign in to comment.