Package eu.mrapik.minecraftservermcp.fs
Record Class ServerFilePaths
java.lang.Object
java.lang.Record
eu.mrapik.minecraftservermcp.fs.ServerFilePaths
- Record Components:
serverRoot- directory containingserver.jar(or the parent of the world folder); typicallygetServer().getWorldContainer().getParentFile()
Canonical Minecraft server root directory and helpers to resolve user-supplied relative paths safely.
resolveChecked(String) rejects path traversal: after normalizing, the resolved path must remain under
the canonical server root (using File.getCanonicalFile() for the root and Path.normalize() for the
combined path). A null return means the request path escapes the jail or is otherwise unusable.
-
Constructor Summary
ConstructorsConstructorDescriptionServerFilePaths(File serverRoot) Creates an instance of aServerFilePathsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.relativeToRoot(Path absolute) Computes a forward-slash path relative to the server root for policy checks and messages.resolveChecked(String relativePath) Resolves a path relative to the server root and ensures it stays inside that directory.Returns the value of theserverRootrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ServerFilePaths
Creates an instance of aServerFilePathsrecord class.- Parameters:
serverRoot- the value for theserverRootrecord component
-
-
Method Details
-
resolveChecked
Resolves a path relative to the server root and ensures it stays inside that directory.Leading slashes are stripped so
/fooandfoobehave consistently. Backslashes are normalized to forward slashes before resolution. Symbolic links are not specially handled beyond whatPath.normalize()provides; the final check usesstartsWith(root)on normalized paths.- Parameters:
relativePath- user input relative to server root- Returns:
- absolute normalized path under the server root, or
nullif outside the root - Throws:
IOException- if canonical path resolution fails
-
relativeToRoot
Computes a forward-slash path relative to the server root for policy checks and messages.- Parameters:
absolute- path that must already be under the canonical server root- Returns:
- relative path using
/separators - Throws:
IOException- if canonical root resolution failsIllegalArgumentException- ifabsoluteis not under the server root
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
serverRoot
Returns the value of theserverRootrecord component.- Returns:
- the value of the
serverRootrecord component
-