Make sure we reject files that are not children of a sync-path

This commit is contained in:
Frank 2021-08-16 01:01:51 +02:00
parent 0b9d6093a0
commit fdbde2e0a6
6 changed files with 99 additions and 19 deletions

View file

@ -0,0 +1,17 @@
package ru.bclib.util;
import java.nio.file.Path;
public class PathUtil {
public static boolean isChildOf(Path parent, Path child){
if (child==null || parent==null) return false;
final int pCount = parent.getNameCount();
final int cCount = child.getNameCount();
if (cCount > pCount) return isChildOf(parent, child.getParent());
if (cCount < pCount) return false;
return child.equals(parent);
}
}