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

Allow even more dynamic instrumentation of pwd via os.dynamicPwdFunction #299

Merged
merged 1 commit into from
Sep 7, 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
5 changes: 5 additions & 0 deletions Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,11 @@ string, int or set representations of the `os.PermSet` via:

== Changelog

[#main]
=== main

* Make `os.pwd` modifiable via the `os.dynamicPwd0`

[#0-10-6]
=== 0.10.6

Expand Down
16 changes: 13 additions & 3 deletions os/src-jvm/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@ package object os {
/**
* The current working directory for this process.
*/
def pwd: Path = dynamicPwd.value
val dynamicPwd: DynamicVariable[Path] =
new DynamicVariable(os.Path(java.nio.file.Paths.get(".").toAbsolutePath))
def pwd: Path = dynamicPwdFunction.value()

private val pwd0 = os.Path(java.nio.file.Paths.get(".").toAbsolutePath)

/**
* Used to override `pwd` within a certain scope with a generated value
*/
val dynamicPwdFunction: DynamicVariable[() => Path] = new DynamicVariable(() => dynamicPwd.value)

/**
* Used to override `pwd` within a certain scope with a fixed value
*/
val dynamicPwd: DynamicVariable[Path] = new DynamicVariable(pwd0)

val up: RelPath = RelPath.up

Expand Down
16 changes: 13 additions & 3 deletions os/src-native/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ package object os {
/**
* The current working directory for this process.
*/
def pwd: Path = dynamicPwd.value
val dynamicPwd: DynamicVariable[Path] =
new DynamicVariable(os.Path(java.nio.file.Paths.get(".").toAbsolutePath))
def pwd: Path = dynamicPwdFunction.value()

private val pwd0 = os.Path(java.nio.file.Paths.get(".").toAbsolutePath)

/**
* Used to override `pwd` within a certain scope with a generated value
*/
val dynamicPwdFunction: DynamicVariable[() => Path] = new DynamicVariable(() => dynamicPwd.value)

/**
* Used to override `pwd` within a certain scope with a fixed value
*/
val dynamicPwd: DynamicVariable[Path] = new DynamicVariable(pwd0)

val up: RelPath = RelPath.up

Expand Down