Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix: file path selection bug. #247

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package io.tofhir.server.model
* Represents a node for each file in the file system
* @param label The name of the file
* @param isFolder True if the file is a folder
* @param path file path of the node
* @param children The children of the folder
*/
case class FilePathNode(label: String, isFolder: Boolean, children: List[FilePathNode])
case class FilePathNode(label: String, isFolder: Boolean, path: String, children: List[FilePathNode])
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ class FileSystemTreeStructureService {

/**
* Get the folder tree structure of the given base path
* @param basePath The base path to start with
* @param basePathString The base path to start with
* @param includeFiles if false, only folders will be included in the tree
* @return
*/
def getFolderTreeStructure(basePath: String, includeFiles: Boolean): FilePathNode = {
def getFolderTreeStructure(basePathString: String, includeFiles: Boolean): FilePathNode = {
var fileCount = 0 // Track total number of files processed

val basePath = FileUtils.getPath(basePathString)
if(!basePath.toAbsolutePath.normalize().startsWith(FileUtils.getPath("").toAbsolutePath)) {
throw new IllegalArgumentException("The given path is outside the root context path.")
}

def buildNode(path: Path): FilePathNode = {
if (fileCount >= FILE_LIMIT) {
throw new IllegalStateException(s"File limit exceeded. The maximum number of files to process is $FILE_LIMIT.")
Expand All @@ -50,14 +55,9 @@ class FileSystemTreeStructureService {
} else {
List.empty[FilePathNode]
}
FilePathNode(path.getFileName.toString, Files.isDirectory(path), children)
}

val path = FileUtils.getPath(basePath)
if(!path.toAbsolutePath.normalize().startsWith(FileUtils.getPath("").toAbsolutePath)) {
throw new IllegalArgumentException("The given path is outside the root context path.")
FilePathNode(path.getFileName.toString, Files.isDirectory(path), basePath.relativize(path).toString.replaceAll("\\\\", "/"), children)
}
buildNode(path)
buildNode(basePath)
}

}
Expand Down
Loading