resolvePath method
Resolves the given path
relative to the currentDirectory and the specific file system rules (physical or virtual).
Implementations must handle normalization, security checks (staying within allowed boundaries), and mapping (for virtual systems).
Implementation
@override
String resolvePath(String path) {
// '.' or '' means current directory, '/' means root
if (path.isEmpty || path == '.') {
return currentDirectory;
}
if (path == '/' || p.normalize(path) == p.separator) {
return rootDirectory;
}
final cleanPath = p.normalize(path);
final absPath = p.isAbsolute(cleanPath)
? p.normalize(p.join(rootDirectory, cleanPath.substring(1)))
: p.normalize(p.join(currentDirectory, cleanPath));
// Restrict to root
if (!p.isWithin(rootDirectory, absPath) &&
!p.equals(rootDirectory, absPath)) {
throw FileSystemException(
"Path resolution failed: Path is outside the root directory",
absPath);
}
return absPath;
}