Skip to content

Commit 803d307

Browse files
committed
rename to os.temp.with[File|Dir]
1 parent 68c310e commit 803d307

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

Readme.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,11 +1157,11 @@ os.followLink(wd / "misc" / "folder-symlink") ==> Some(wd / "folder1")
11571157
os.followLink(wd / "misc" / "broken-symlink") ==> None
11581158
----
11591159

1160-
==== `os.temp.withTempFile`
1160+
==== `os.temp.withFile`
11611161

11621162
[source,scala]
11631163
----
1164-
os.temp.withTempFile[A](fun: Path => A): Try[A]
1164+
os.temp.withFile[A](fun: Path => A): A
11651165
----
11661166

11671167
Creates a temporary file, passes it to the given function and removes it immediately after the function completed, even if the function threw an exception.
@@ -1170,16 +1170,16 @@ This doesn't rely on the JVM's `deleteOnExit` handler, therefor the temp file ge
11701170

11711171
[source,scala]
11721172
----
1173-
withTempFile { file =>
1173+
os.temp.withFile { file =>
11741174
os.write(file, "some content")
11751175
}
11761176
----
11771177

1178-
==== `os.temp.withTempDir`
1178+
==== `os.temp.withDir`
11791179

11801180
[source,scala]
11811181
----
1182-
os.temp.withTempDir[A](fun: Path => A): Try[A]
1182+
os.temp.withDir[A](fun: Path => A): A
11831183
----
11841184

11851185
Creates a temporary directory, passes it to the given function and removes it immediately after the function completed, even if the function threw an exception.
@@ -1188,7 +1188,7 @@ This doesn't rely on the JVM's `deleteOnExit` handler, therefor the temp dir get
11881188

11891189
[source,scala]
11901190
----
1191-
withTempDir { file =>
1191+
os.temp.withDir { file =>
11921192
val file = dir / "somefile"
11931193
os.write(file, "some content")
11941194
}

os/src/TempOps.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import java.nio.file.attribute.{FileAttribute, PosixFilePermissions}
44
import scala.util.Using
55

66
/**
7-
* Create temporary files and directories. [[withTempFile]] and [[withTempDir]]
7+
* Create temporary files and directories. [[withFile]] and [[withDir]]
88
* are convenience methods that handle the most common case. They delete the temp
99
* file/dir immediately after the given function completed - even if the given
1010
* function threw an exception.
1111
*
1212
* {{{
13-
* withTempFile { file =>
13+
* os.temp.withFile { file =>
1414
* os.write(file, "some content")
1515
* }
1616
* }}}
@@ -87,12 +87,12 @@ object temp {
8787
* after the given function completed - even if the function throws an exception.
8888
*
8989
* {{{
90-
* withTempFile { file =>
90+
* os.temp.withFile { file =>
9191
* os.write(file, "some content")
9292
* }
9393
* }}}
9494
*/
95-
def withTempFile[A](fun: Path => A): A =
95+
def withFile[A](fun: Path => A): A =
9696
Using.resource(os.temp(
9797
deleteOnExit = false // TempFile.close() deletes it, no need to register with JVM
9898
))(fun)
@@ -102,13 +102,13 @@ object temp {
102102
* after the given function completed - even if the function throws an exception.
103103
*
104104
* {{{
105-
* withTempDir { file =>
105+
* os.temp.withDir { file =>
106106
* val file = dir / "somefile"
107107
* os.write(file, "some content")
108108
* }
109109
* }}}
110110
*/
111-
def withTempDir[A](fun: Path => A): A =
111+
def withDir[A](fun: Path => A): A =
112112
Using.resource(os.temp.dir(
113113
deleteOnExit = false // TempFile.close() deletes it, no need to register with JVM
114114
))(fun)

os/test/src/TempPathTests.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package test.os
22

33
import os._
4-
import os.temp.{withTempFile, withTempDir}
54
import scala.util.Using
65
import utest.{assert => _, _}
76

87
object TempPathTests extends TestSuite{
98
val tests = Tests {
109

1110
test("convenience methods") {
12-
test("withTempFile") {
11+
test("temp.withFile") {
1312
var tempFilePath: String = null
14-
withTempFile { file =>
13+
os.temp.withFile { file =>
1514
tempFilePath = file.toString
1615
assert(os.exists(file))
1716
}
1817
assert(!os.exists(os.Path(tempFilePath)), s"temp file did not get auto-deleted after `Using` block: $tempFilePath")
1918
}
20-
test("withTempDir") {
19+
test("temp.withDir") {
2120
var tempDirPath: String = null
2221
var tempFilePath: String = null
23-
withTempDir { dir =>
22+
os.temp.withDir { dir =>
2423
val file = dir / "somefile"
2524
tempDirPath = dir.toString
2625
tempFilePath = file.toString

0 commit comments

Comments
 (0)