Skip to content
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
45 changes: 45 additions & 0 deletions Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,51 @@ os.isLink(wd / "misc/folder-symlink") ==> true
os.isLink(wd / "folder1") ==> false
----

==== `os.isReadable`

[source,scala]
----
os.isReadable(p: Path): Boolean
----

Returns `true` if the given path is readable.

[source,scala]
----
os.isReadable(wd / "misc/file1") ==> false
os.isReadable(wd / "misc/file2") ==> true
----

==== `os.isWritable`

[source,scala]
----
os.isWritable(p: Path): Boolean
----

Returns `true` if the given path is writable.

[source,scala]
----
os.isWritable(wd / "misc/file1") ==> false
os.isWritable(wd / "misc/file2") ==> true
----

==== `os.isExecutable`

[source,scala]
----
os.isExecutable(p: Path): Boolean
----

Returns `true` if the given path is executable.

[source,scala]
----
os.isExecutable(wd / "misc/file1") ==> false
os.isExecutable(wd / "misc/file2.sh") ==> true
----

==== `os.size`

[source,scala]
Expand Down
27 changes: 27 additions & 0 deletions os/src/StatOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@ object isDir extends Function1[Path, Boolean] {
}
}

/**
* Checks whether the given path is readable
*
* Returns `false` if the path does not exist
*/
object isReadable extends Function1[Path, Boolean] {
def apply(p: Path): Boolean = Files.isReadable(p.wrapped)
}

/**
* Checks whether the given path is writable
*
* Returns `false` if the path does not exist
*/
object isWritable extends Function1[Path, Boolean] {
def apply(p: Path): Boolean = Files.isWritable(p.wrapped)
}

/**
* Checks whether the given path is executable
*
* Returns `false` if the path does not exist
*/
object isExecutable extends Function1[Path, Boolean] {
def apply(p: Path): Boolean = Files.isExecutable(p.wrapped)
}

/**
* Gets the size of the given file or folder
*
Expand Down
21 changes: 21 additions & 0 deletions os/test/src/FilesystemMetadataTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ object FilesystemMetadataTests extends TestSuite {
os.isLink(wd / "folder1") ==> false
}
}
test("isReadable") {
test - prep { wd =>
os.isReadable(wd / "File.txt") ==> true
os.isReadable(wd / "folder1") ==> true
}
}
test("isWritable") {
test - prep { wd =>
os.isWritable(wd / "File.txt") ==> true
os.isWritable(wd / "folder1") ==> true
}
}
test("isExecutable") {
test - prep { wd =>
if (Unix()) {
os.perms.set(wd / "File.txt", "rw-rw-rw-")
os.isExecutable(wd / "File.txt") ==> false
os.isExecutable(wd / "misc/echo") ==> true
}
}
}
test("size") {
test - prep { wd =>
os.size(wd / "File.txt") ==> 8
Expand Down