Skip to content
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

Merged
merged 3 commits into from
Apr 5, 2021

Conversation

vitaliihonta
Copy link
Contributor

@vitaliihonta vitaliihonta commented Mar 19, 2021

No description provided.

@vitaliihonta vitaliihonta requested a review from a team as a code owner March 19, 2021 14:38
@CLAassistant
Copy link

CLAassistant commented Mar 19, 2021

CLA assistant check
All committers have signed the CLA.

@@ -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] =
Copy link
Contributor Author

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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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

Copy link
Contributor

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],
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link
Contributor

@quelgar quelgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

@quelgar quelgar merged commit 58d9198 into zio:master Apr 5, 2021
svroonland pushed a commit that referenced this pull request Aug 9, 2021
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants