Skip to content

Commit 8c02044

Browse files
committed
Added experimental annotation and updated checks in move
1 parent 2f357dc commit 8c02044

File tree

10 files changed

+40
-6
lines changed

10 files changed

+40
-6
lines changed

build.sc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ trait MiMaChecks extends Mima {
7272
// this is fine, because ProcessLike is sealed (and its subclasses should be final)
7373
ProblemFilter.exclude[ReversedMissingMethodProblem]("os.ProcessLike.joinPumperThreadsHook")
7474
)
75+
override def mimaExcludeAnnotations: T[Seq[String]] = Seq(
76+
"os.experimental"
77+
)
7578
}
7679

7780
trait OsLibModule

os/src/FileOps.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import scala.util.Try
2222
* ignore the destination if it already exists, using [[os.makeDir.all]]
2323
*/
2424
object makeDir extends Function1[Path, Unit] {
25+
@experimental
2526
def apply(path: Path): Unit = {
2627
checker.value.onWrite(path)
2728
Files.createDirectory(path.wrapped)
2829
}
30+
@experimental
2931
def apply(path: Path, perms: PermSet): Unit = {
3032
checker.value.onWrite(path)
3133
Files.createDirectory(
@@ -41,6 +43,7 @@ object makeDir extends Function1[Path, Unit] {
4143
*/
4244
object all extends Function1[Path, Unit] {
4345
def apply(path: Path): Unit = apply(path, null, true)
46+
@experimental
4447
def apply(path: Path, perms: PermSet = null, acceptLinkedDirectory: Boolean = true): Unit = {
4548
checker.value.onWrite(path)
4649
// We special case calling makeDir.all on a symlink to a directory;
@@ -82,15 +85,15 @@ object move {
8285
def matching(partialFunction: PartialFunction[Path, Path]): PartialFunction[Path, Unit] = {
8386
matching()(partialFunction)
8487
}
88+
@experimental
8589
def apply(
8690
from: Path,
8791
to: Path,
8892
replaceExisting: Boolean = false,
8993
atomicMove: Boolean = false,
9094
createFolders: Boolean = false
9195
): Unit = {
92-
checker.value.onRead(from)
93-
checker.value.onWrite(from / RelPath.up)
96+
checker.value.onWrite(from)
9497
checker.value.onWrite(to)
9598
if (createFolders && to.segmentCount != 0) makeDir.all(to / up)
9699
val opts1 =
@@ -175,6 +178,7 @@ object copy {
175178
matching()(partialFunction)
176179
}
177180

181+
@experimental
178182
def apply(
179183
from: Path,
180184
to: Path,
@@ -319,6 +323,7 @@ object copy {
319323
*/
320324
object remove extends Function1[Path, Boolean] {
321325
def apply(target: Path): Boolean = apply(target, false)
326+
@experimental
322327
def apply(target: Path, checkExists: Boolean = false): Boolean = {
323328
checker.value.onWrite(target)
324329
if (checkExists) {
@@ -330,6 +335,7 @@ object remove extends Function1[Path, Boolean] {
330335
}
331336

332337
object all extends Function1[Path, Unit] {
338+
@experimental
333339
def apply(target: Path) = {
334340
require(target.segmentCount != 0, s"Cannot remove a root directory: $target")
335341
checker.value.onWrite(target)
@@ -360,6 +366,7 @@ object exists extends Function1[Path, Boolean] {
360366
* Creates a hardlink between two paths
361367
*/
362368
object hardlink {
369+
@experimental
363370
def apply(link: Path, dest: Path) = {
364371
checker.value.onWrite(link)
365372
checker.value.onRead(dest)
@@ -371,6 +378,7 @@ object hardlink {
371378
* Creates a symbolic link between two paths
372379
*/
373380
object symlink {
381+
@experimental
374382
def apply(link: Path, dest: FilePath, perms: PermSet = null): Unit = {
375383
checker.value.onWrite(link)
376384
checker.value.onRead(dest match {

os/src/Model.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,10 @@ object PosixStatInfo {
288288
* Defines hooks for path based operations.
289289
*
290290
* This, in conjunction with [[checker]], can be used to implement custom checks like
291-
* - restricting operations to some path(s)
292-
* - logging operations
291+
* - restricting an operation to some path(s)
292+
* - logging an operation
293293
*/
294+
@experimental
294295
trait Checker {
295296

296297
/** A hook for a read operation on `path`. */
@@ -300,6 +301,7 @@ trait Checker {
300301
def onWrite(path: Path): Unit
301302
}
302303

304+
@experimental
303305
object Checker {
304306

305307
/** A no-op [[Checker]]. */

os/src/PermsOps.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ object perms extends Function1[Path, PermSet] {
2323
* default set of permissions and having `os.perms.set` over-write them later
2424
*/
2525
object set {
26+
@experimental
2627
def apply(p: Path, arg2: PermSet): Unit = {
2728
checker.value.onWrite(p)
2829
Files.setPosixFilePermissions(p.wrapped, arg2.toSet())
@@ -45,6 +46,7 @@ object owner extends Function1[Path, UserPrincipal] {
4546
* Set the owner of the file/folder at the given path
4647
*/
4748
object set {
49+
@experimental
4850
def apply(arg1: Path, arg2: UserPrincipal): Unit = {
4951
checker.value.onWrite(arg1)
5052
Files.setOwner(arg1.wrapped, arg2)
@@ -76,6 +78,7 @@ object group extends Function1[Path, GroupPrincipal] {
7678
* Set the owning group of the file/folder at the given path
7779
*/
7880
object set {
81+
@experimental
7982
def apply(arg1: Path, arg2: GroupPrincipal): Unit = {
8083
checker.value.onWrite(arg1)
8184
Files.getFileAttributeView(

os/src/ReadWriteOps.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ object write {
2121
/**
2222
* Open a [[java.io.OutputStream]] to write to the given file
2323
*/
24+
@experimental
2425
def outputStream(
2526
target: Path,
2627
perms: PermSet = null,
@@ -47,6 +48,7 @@ object write {
4748
* from `java.nio.file.Files.write` so we could re-use it properly for
4849
* different combinations of flags and all sorts of [[Source]]s
4950
*/
51+
@experimental
5052
def write(
5153
target: Path,
5254
data: Source,
@@ -167,6 +169,7 @@ object write {
167169
* Opens a [[SeekableByteChannel]] to write to the given file.
168170
*/
169171
object channel extends Function1[Path, SeekableByteChannel] {
172+
@experimental
170173
def write(p: Path, options: Seq[StandardOpenOption]) = {
171174
checker.value.onWrite(p)
172175
java.nio.file.Files.newByteChannel(p.toNIO, options.toArray: _*)
@@ -214,6 +217,7 @@ object write {
214217
* given size, does nothing.
215218
*/
216219
object truncate {
220+
@experimental
217221
def apply(p: Path, size: Long): Unit = {
218222
checker.value.onWrite(p)
219223
val channel = FileChannel.open(p.toNIO, StandardOpenOption.WRITE)
@@ -246,6 +250,7 @@ object read extends Function1[ReadablePath, String] {
246250
* Opens a [[java.io.InputStream]] to read from the given file
247251
*/
248252
object inputStream extends Function1[ReadablePath, java.io.InputStream] {
253+
@experimental
249254
def apply(p: ReadablePath): java.io.InputStream = {
250255
checker.value.onRead(p)
251256
p.getInputStream
@@ -269,6 +274,7 @@ object read extends Function1[ReadablePath, String] {
269274
* Opens a [[SeekableByteChannel]] to read from the given file.
270275
*/
271276
object channel extends Function1[Path, SeekableByteChannel] {
277+
@experimental
272278
def apply(p: Path): SeekableByteChannel = {
273279
checker.value.onRead(p)
274280
p.toSource.getChannel()

os/src/StatOps.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ object mtime extends Function1[Path, Long] {
7373
* https://stackoverflow.com/questions/17308363/symlink-lastmodifiedtime-in-java-1-7
7474
*/
7575
object set {
76+
@experimental
7677
def apply(p: Path, millis: Long) = {
7778
checker.value.onWrite(p)
7879
Files.setLastModifiedTime(p.wrapped, FileTime.fromMillis(millis))

os/src/TempOps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ object temp {
2020
* By default, temporary files are deleted on JVM exit. You can disable that
2121
* behavior by setting `deleteOnExit = false`
2222
*/
23+
@experimental
2324
def apply(
2425
contents: Source = null,
2526
dir: Path = null,
@@ -28,7 +29,6 @@ object temp {
2829
deleteOnExit: Boolean = true,
2930
perms: PermSet = null
3031
): Path = {
31-
import collection.JavaConverters._
3232
val permArray: Array[FileAttribute[_]] =
3333
if (perms == null) Array.empty
3434
else Array(PosixFilePermissions.asFileAttribute(perms.toSet()))
@@ -53,6 +53,7 @@ object temp {
5353
* By default, temporary directories are deleted on JVM exit. You can disable that
5454
* behavior by setting `deleteOnExit = false`
5555
*/
56+
@experimental
5657
def dir(
5758
dir: Path = null,
5859
prefix: String = null,

os/src/ZipOps.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ object zip {
3636
* @param compressionLevel number from 0-9, where 0 is no compression and 9 is best compression. Defaults to -1 (default compression)
3737
* @return The path to the created ZIP archive.
3838
*/
39+
@experimental
3940
def apply(
4041
dest: os.Path,
4142
sources: Seq[ZipSource] = List(),
@@ -265,6 +266,7 @@ object unzip {
265266
* @param dest The path to the destination directory for extracted files.
266267
* @param excludePatterns A list of regular expression patterns to exclude files during extraction. (Optional)
267268
*/
269+
@experimental
268270
def stream(
269271
source: geny.Readable,
270272
dest: os.Path,

os/src/experimental.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package os
2+
3+
import scala.annotation.StaticAnnotation
4+
5+
/**
6+
* Annotation to mark experimental API, which is not guaranteed to stay.
7+
*/
8+
class experimental extends StaticAnnotation {}

os/test/src/ManipulatingFilesFoldersTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object ManipulatingFilesFoldersTests extends TestSuite {
3939
|And I look good on the barbecue""".stripMargin
4040
}
4141
test("checker") - prepChecker { wd =>
42-
intercept[ReadDenied] {
42+
intercept[WriteDenied] {
4343
os.move(rd / "folder1/one.txt", wd / "folder1/File.txt")
4444
}
4545
os.list(wd / "folder1") ==> Seq(wd / "folder1/one.txt")

0 commit comments

Comments
 (0)