Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Sep 7, 2024
1 parent 740618f commit 0f907b7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ wd / os.up
wd / os.up / os.up
----

`os.pwd` can be modified in certain scopes via the `os.pwd0` dynamic variable, but
`os.pwd` can be modified in certain scopes via the `os.dynamicPwd` dynamic variable, but
best practice is not to change it. Instead simply define a new path, e.g.

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

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

val up: RelPath = RelPath.up
Expand Down
4 changes: 2 additions & 2 deletions os/test/src/PathTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ object PathTests extends TestSuite {
System.err.printf("p[%s]\n", posix(p))
assert(posix(p) contains "/omg")
}
test("pwd0") {
test("dynamicPwd") {
val x = os.pwd
val y = os.pwd0.withValue(os.pwd / "hello") {
val y = os.dynamicPwd.withValue(os.pwd / "hello") {
os.pwd
}

Expand Down
4 changes: 2 additions & 2 deletions os/test/src/SubprocessTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ object SubprocessTests extends TestSuite {
assert(output.out.lines() == Seq("HELLO /usr"))
}
}
test("pwd0") {
test("dynamicPwd") {
// Windows doesnt have bash installed so a bit inconvenient
// to run these subprocesses for testing
if (!scala.util.Properties.isWin) {
val outsidePwd = os.pwd
val tmp0 = os.temp.dir()
val tmp = os.followLink(tmp0).getOrElse(tmp0)
val x = proc("bash", "-c", "pwd").call()
val y = os.pwd0.withValue(tmp) {
val y = os.dynamicPwd.withValue(tmp) {
proc("bash", "-c", "pwd").call()
}

Expand Down

0 comments on commit 0f907b7

Please sign in to comment.