■ ■ ■ ■ ■ ■
commons-utils/src/main/java/io/onedev/commons/utils/PathUtils.java
| skipped 265 lines |
266 | 266 | | return StringUtils.isBlank(path) || FilenameUtils.normalize(path).length() == 0; |
267 | 267 | | } |
268 | 268 | | |
| 269 | + | public static boolean isSelfOrAncestor(String ancestor, String path) { |
| 270 | + | return path.equals(ancestor) || path.startsWith(ancestor+"/"); |
| 271 | + | } |
| 272 | + | |
| 273 | + | public static String substituteSelfOrAncestor(String path, String oldAncestor, String newAncestor) { |
| 274 | + | if (isSelfOrAncestor(oldAncestor, path)) |
| 275 | + | return newAncestor + path.substring(oldAncestor.length()); |
| 276 | + | else |
| 277 | + | return path; |
| 278 | + | } |
| 279 | + | |
269 | 280 | | } |
270 | 281 | | |