-
Notifications
You must be signed in to change notification settings - Fork 116
fix(core): prefer current repo when resolving amber home path #4263
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ package org.apache.texera.amber.engine.common | |
| import com.typesafe.scalalogging.LazyLogging | ||
| import org.apache.texera.amber.engine.architecture.rpc.controlreturns.WorkflowAggregatedState | ||
|
|
||
| import java.nio.file.{Files, Path, Paths} | ||
| import java.util.concurrent.locks.Lock | ||
| import scala.annotation.tailrec | ||
|
|
||
|
|
@@ -36,25 +35,52 @@ object Utils extends LazyLogging { | |
| * | ||
| * @return the real absolute path to amber home directory | ||
| */ | ||
|
|
||
| import java.nio.file.{Files, Path, Paths} | ||
| import scala.jdk.CollectionConverters._ | ||
| import scala.util.Using | ||
|
|
||
| lazy val amberHomePath: Path = { | ||
| val currentWorkingDirectory = Paths.get(".").toRealPath() | ||
| // check if the current directory is the amber home path | ||
|
|
||
| if (isAmberHomePath(currentWorkingDirectory)) { | ||
| currentWorkingDirectory | ||
| } else { | ||
| // from current path's parent directory, search its children to find amber home path | ||
| // current max depth is set to 2 (current path's siblings and direct children) | ||
| val searchChildren = Files | ||
| .walk(currentWorkingDirectory.getParent, 2) | ||
| .filter((path: Path) => isAmberHomePath(path)) | ||
| .findAny | ||
| if (searchChildren.isPresent) { | ||
| searchChildren.get | ||
| } else { | ||
| val parent = Option(currentWorkingDirectory.getParent).getOrElse { | ||
| throw new RuntimeException( | ||
| "Finding texera home path failed. Current working directory is " + currentWorkingDirectory | ||
| s"Cannot search for texera home from filesystem root: $currentWorkingDirectory" | ||
| ) | ||
|
Comment on lines
+49
to
52
|
||
| } | ||
|
|
||
| // Pass 1: prefer the closest prefix (deepest ancestor) of currentWorkingDirectory | ||
| val closestPrefix: Option[Path] = | ||
| Using.resource(Files.walk(parent, 2)) { stream => | ||
| stream | ||
| .iterator() | ||
| .asScala | ||
| .filter(path => isAmberHomePath(path)) | ||
| .map(_.toRealPath()) // normalize after filtering | ||
| .filter(path => path.startsWith(currentWorkingDirectory)) | ||
| .maxByOption(_.getNameCount) // deepest prefix = closest ancestor | ||
| } | ||
|
Comment on lines
+55
to
+65
|
||
|
|
||
| closestPrefix.getOrElse { | ||
| // Pass 2: fallback to any valid match | ||
| val anyMatch = | ||
| Using.resource(Files.walk(parent, 2)) { stream => | ||
| stream | ||
| .filter((path: Path) => isAmberHomePath(path)) | ||
| .findAny() | ||
| } | ||
|
Comment on lines
+56
to
+74
|
||
|
|
||
| if (anyMatch.isPresent) { | ||
| anyMatch.get().toRealPath() | ||
| } else { | ||
| throw new RuntimeException( | ||
| s"Finding texera home path failed. Current working directory is $currentWorkingDirectory" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
43
to
84
|
||
| } | ||
| val AMBER_HOME_FOLDER_NAME = "amber"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new imports are placed inside the
Utilsobject, while other files in this package keep imports at the top of the file. Consider moving them to the top-level import section for consistency and to make dependencies easier to spot.