-
Notifications
You must be signed in to change notification settings - Fork 75
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
[#323] added Files.createTemp* Managed methods; added Files.deleteRec… #327
Conversation
31064ba
to
6ea8686
Compare
@@ -106,6 +133,9 @@ object Files { | |||
def deleteIfExists(path: Path): ZIO[Blocking, IOException, Boolean] = | |||
effectBlocking(JFiles.deleteIfExists(path.javaPath)).refineToOrDie[IOException] | |||
|
|||
def deleteRecursive(path: Path): ZIO[Blocking, IOException, Long] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this method may be useful independently of the rest updates
prefix: Option[String], | ||
fileAttributes: Iterable[FileAttribute[_]] | ||
): ZManaged[Blocking, IOException, Path] = | ||
ZManaged.make(createTempDirectory(prefix, fileAttributes))(release = deleteRecursive(_).ignore) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 100% sure about recursive directory deletion. But it seems to be reasonable in terms of temporary directories
prefix: Option[String], | ||
fileAttributes: Iterable[FileAttribute[_]] | ||
): ZManaged[Blocking, IOException, Path] = | ||
ZManaged.make(createTempFile(suffix, prefix, fileAttributes))(release = deleteIfExists(_).ignore) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what exactly should be used in the finalization block: ignore or orDie?
In most cases, it won't fail so I choose to ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm not 100% sure either, but ignore
seems good.
@@ -74,6 +81,13 @@ object Files { | |||
effectBlocking(Path.fromJava(JFiles.createTempFile(prefix.orNull, suffix, fileAttributes.toSeq: _*))) | |||
.refineToOrDie[IOException] | |||
|
|||
def createTempFileManaged( | |||
suffix: String = ".tmp", | |||
prefix: Option[String], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fine to have prefix
default to None
and fileAttributes
to default to Iterable.empty
?
import zio.test._ | ||
import zio.test.Assertion._ | ||
|
||
object FilesSpec extends BaseSpec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thank you!
#327) * [#323] added Files.createTemp* Managed methods; added Files.deleteRecursive method * [#323] added default arguments to createTempFileManaged Co-authored-by: Vitalii Honta <[email protected]> Co-authored-by: Lachlan O'Dea <[email protected]>
No description provided.