package com.njcn.gather.systemops.database.util;

import cn.hutool.core.util.StrUtil;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 数据库运维文件路径工具。
 */
public final class DatabasePathUtil {

    private DatabasePathUtil() {
    }

    public static Path normalize(String filePath) {
        if (StrUtil.isBlank(filePath)) {
            return null;
        }
        return Paths.get(filePath).toAbsolutePath().normalize();
    }

    public static boolean isUnder(Path path, Path root) {
        if (path == null || root == null) {
            return false;
        }
        Path normalizedPath = path.toAbsolutePath().normalize();
        Path normalizedRoot = root.toAbsolutePath().normalize();
        return normalizedPath.startsWith(normalizedRoot);
    }
}
