From 8278737250f1873b7d15de61ddab0d859016ca18 Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Tue, 1 Aug 2023 01:21:43 +0200 Subject: [PATCH 1/8] remove unneeded Scope requirement in FtpAccessors --- zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala b/zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala index 3d1b9736..fb55e76e 100644 --- a/zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala +++ b/zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala @@ -73,6 +73,6 @@ trait FtpAccessors[+A] { * @param source data stream to store * @tparam R environment of the specified stream source, required to extend Blocking */ - def upload[R](path: String, source: ZStream[R, Throwable, Byte]): ZIO[R with Scope, IOException, Unit] + def upload[R](path: String, source: ZStream[R, Throwable, Byte]): ZIO[R, IOException, Unit] } From 7b7452ae06e00041d365e715fc97a323d0b7f5af Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Tue, 1 Aug 2023 01:24:55 +0200 Subject: [PATCH 2/8] remove unused import --- zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala b/zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala index fb55e76e..03720b39 100644 --- a/zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala +++ b/zio-ftp/src/main/scala/zio/ftp/FtpAccessors.scala @@ -1,7 +1,7 @@ package zio.ftp import java.io.IOException -import zio.{ Scope, ZIO } +import zio.ZIO import zio.stream.ZStream trait FtpAccessors[+A] { From 7cdd0e432fcd0cd31ba1ecfbdef2400470c1f228 Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Tue, 1 Aug 2023 12:22:55 +0200 Subject: [PATCH 3/8] zio-ftp should clean up after itself --- zio-ftp/src/main/scala/zio/ftp/TestFtp.scala | 24 ++++++++++--------- .../src/main/scala/zio/ftp/UnsecureFtp.scala | 18 +++++++------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/zio-ftp/src/main/scala/zio/ftp/TestFtp.scala b/zio-ftp/src/main/scala/zio/ftp/TestFtp.scala index 4aac8ca3..abbd45f4 100644 --- a/zio-ftp/src/main/scala/zio/ftp/TestFtp.scala +++ b/zio-ftp/src/main/scala/zio/ftp/TestFtp.scala @@ -23,7 +23,7 @@ import java.nio.file.attribute.PosixFilePermission import zio.nio.file.{ Path => ZPath } import zio.nio.file.Files import zio.stream.{ ZSink, ZStream } -import zio.{ Cause, Scope, ZIO } +import zio.{ Cause, ZIO } object TestFtp { @@ -98,18 +98,20 @@ object TestFtp { override def upload[R]( path: String, source: ZStream[R, Throwable, Byte] - ): ZIO[R with Scope, IOException, Unit] = { + ): ZIO[R, IOException, Unit] = { val file = (root / ZPath(path).elements.mkString("/")).toFile - ZIO - .fromAutoCloseable(ZIO.attempt(new FileOutputStream(file))) - .flatMap { out => - source - .run(ZSink.fromOutputStream(out)) - .unit - } - .refineToOrDie[IOException] - .catchAll(err => ZIO.fail(new IOException(s"Path is invalid. Cannot upload data to : $path", err))) + ZIO.scoped[R] { + ZIO + .fromAutoCloseable(ZIO.attempt(new FileOutputStream(file))) + .flatMap { out => + source + .run(ZSink.fromOutputStream(out)) + .unit + } + .refineToOrDie[IOException] + .catchAll(err => ZIO.fail(new IOException(s"Path is invalid. Cannot upload data to : $path", err))) + } } } } diff --git a/zio-ftp/src/main/scala/zio/ftp/UnsecureFtp.scala b/zio-ftp/src/main/scala/zio/ftp/UnsecureFtp.scala index bbdf2068..0cec9d7a 100644 --- a/zio-ftp/src/main/scala/zio/ftp/UnsecureFtp.scala +++ b/zio-ftp/src/main/scala/zio/ftp/UnsecureFtp.scala @@ -79,14 +79,16 @@ final private class UnsecureFtp(unsafeClient: Client) extends FtpAccessors[Clien ZStream(FtpResource.fromFtpFile(f, Some(path))) } - def upload[R](path: String, source: ZStream[R, Throwable, Byte]): ZIO[R with Scope, IOException, Unit] = - source.toInputStream - .mapError(new IOException(_)) - .flatMap(is => - execute(_.storeFile(path, is)) - .filterOrFail(identity)(InvalidPathError(s"Path is invalid. Cannot upload data to : $path")) - .unit - ) + def upload[R](path: String, source: ZStream[R, Throwable, Byte]): ZIO[R, IOException, Unit] = + ZIO.scoped[R] { + source.toInputStream + .mapError(new IOException(_)) + .flatMap(is => + execute(_.storeFile(path, is)) + .filterOrFail(identity)(InvalidPathError(s"Path is invalid. Cannot upload data to : $path")) + .unit + ) + } override def execute[T](f: Client => T): ZIO[Any, IOException, T] = attemptBlockingIO(f(unsafeClient)) From f1c9951976c98df82c5b46a5a8b0830e25f41cb0 Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Tue, 1 Aug 2023 12:26:24 +0200 Subject: [PATCH 4/8] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6aa7587..3f05c1fc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ In order to use this library, we need to add the following line in our `build.sbt` file: ```scala -libraryDependencies += "dev.zio" %% "zio-ftp" % "0.4.0" +libraryDependencies += "dev.zio" %% "zio-ftp" % "0.4.1" ``` ## How to use it? From 188c5b9344028751e9fa71e8c3fbc26738299573 Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Tue, 1 Aug 2023 12:41:15 +0200 Subject: [PATCH 5/8] run docs/generateGithubWorkflow --- .github/workflows/site.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index 6b55d119..223121b5 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -18,7 +18,7 @@ jobs: if: ${{ github.event_name == 'pull_request' }} steps: - name: Git Checkout - uses: actions/checkout@v3.5.1 + uses: actions/checkout@v3.3.0 with: fetch-depth: '0' - name: Setup Scala @@ -41,7 +41,7 @@ jobs: if: ${{ ((github.event_name == 'release') && (github.event.action == 'published')) || (github.event_name == 'workflow_dispatch') }} steps: - name: Git Checkout - uses: actions/checkout@v3.5.1 + uses: actions/checkout@v3.3.0 with: fetch-depth: '0' - name: Setup Scala @@ -65,7 +65,7 @@ jobs: if: ${{ (github.event_name == 'push') || ((github.event_name == 'release') && (github.event_name == 'published')) }} steps: - name: Git Checkout - uses: actions/checkout@v3.5.1 + uses: actions/checkout@v3.3.0 with: ref: ${{ github.head_ref }} fetch-depth: '0' From de23156d1b4dacd5ae9ae0c8569151769fa16717 Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Tue, 1 Aug 2023 18:43:45 +0200 Subject: [PATCH 6/8] remove Scope requirement from Layers as well --- zio-ftp/src/main/scala/zio/ftp/package.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zio-ftp/src/main/scala/zio/ftp/package.scala b/zio-ftp/src/main/scala/zio/ftp/package.scala index 0e258ce8..a35fa08d 100644 --- a/zio-ftp/src/main/scala/zio/ftp/package.scala +++ b/zio-ftp/src/main/scala/zio/ftp/package.scala @@ -137,11 +137,11 @@ package object ftp { ZStream.serviceWithStream(_.readFile(path, chunkSize)) } - def unsecure(settings: UnsecureFtpSettings): ZLayer[Scope, ConnectionError, Ftp] = - ZLayer.fromZIO(UnsecureFtp.connect(settings)) + def unsecure(settings: UnsecureFtpSettings): ZLayer[Any, ConnectionError, Ftp] = + ZLayer.scoped(UnsecureFtp.connect(settings)) - def secure(settings: SecureFtpSettings): ZLayer[Scope, ConnectionError, SFtp] = - ZLayer.fromZIO(SecureFtp.connect(settings)) + def secure(settings: SecureFtpSettings): ZLayer[Any, ConnectionError, SFtp] = + ZLayer.scoped(SecureFtp.connect(settings)) def stub(path: ZPath): Layer[Any, StubFtp] = ZLayer.succeed(TestFtp.create(path)) From 042a37d3e6c5185d498fe77b3de719e4ab2fc85d Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Tue, 1 Aug 2023 20:00:30 +0200 Subject: [PATCH 7/8] remove Scope requirement in more cases --- README.md | 2 +- docs/index.md | 2 +- zio-ftp/src/main/scala/zio/ftp/package.scala | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3f05c1fc..567e1e5b 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ object ZIOFTPExample extends ZIOAppDefault { private val settings = UnsecureFtpSettings("127.0.0.1", 21, FtpCredentials("one", "1234")) - private val myApp: ZIO[Scope with Ftp, IOException, Unit] = + private val myApp: ZIO[Ftp, IOException, Unit] = for { _ <- Console.printLine("List of files at root directory:") resource <- ls("/").runCollect diff --git a/docs/index.md b/docs/index.md index 6ec767b2..c07e610e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -77,7 +77,7 @@ object ZIOFTPExample extends ZIOAppDefault { private val settings = UnsecureFtpSettings("127.0.0.1", 21, FtpCredentials("one", "1234")) - private val myApp: ZIO[Scope with Ftp, IOException, Unit] = + private val myApp: ZIO[Ftp, IOException, Unit] = for { _ <- Console.printLine("List of files at root directory:") resource <- ls("/").runCollect diff --git a/zio-ftp/src/main/scala/zio/ftp/package.scala b/zio-ftp/src/main/scala/zio/ftp/package.scala index a35fa08d..6176f184 100644 --- a/zio-ftp/src/main/scala/zio/ftp/package.scala +++ b/zio-ftp/src/main/scala/zio/ftp/package.scala @@ -55,7 +55,7 @@ package object ftp { def upload[R]( path: String, source: ZStream[R, Throwable, Byte] - ): ZIO[R & Scope with Ftp, IOException, Unit] = + ): ZIO[R with Ftp, IOException, Unit] = for { ftp <- ZIO.service[Ftp] _ <- ftp.upload(path, source) @@ -91,7 +91,7 @@ package object ftp { def upload[R]( path: String, source: ZStream[R, Throwable, Byte] - ): ZIO[SFtp with R with Scope, IOException, Unit] = + ): ZIO[SFtp with R, IOException, Unit] = for { ftp <- ZIO.service[SFtp] _ <- ftp.upload(path, source) @@ -127,7 +127,7 @@ package object ftp { def upload[R]( path: String, source: ZStream[R, Throwable, Byte] - ): ZIO[StubFtp with R with Scope, IOException, Unit] = + ): ZIO[StubFtp with R, IOException, Unit] = for { ftp <- ZIO.service[StubFtp] _ <- ftp.upload(path, source) From e23a06dbdf765953f03f19f704e9e0cc6a01df59 Mon Sep 17 00:00:00 2001 From: Matthias Berndt Date: Tue, 1 Aug 2023 20:10:48 +0200 Subject: [PATCH 8/8] tiny refactoring --- README.md | 2 +- docs/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 567e1e5b..6fa27072 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ object ZIOFTPExample extends ZIOAppDefault { .via(ZPipeline.utf8Decode) .runCollect _ <- Console.printLine(s"Content of $path file:") - _ <- Console.printLine(file.fold("")(_ + _)) + _ <- Console.printLine(file.mkString) } yield () override def run = myApp.provideSomeLayer(unsecure(settings)) diff --git a/docs/index.md b/docs/index.md index c07e610e..11cc53ad 100644 --- a/docs/index.md +++ b/docs/index.md @@ -93,7 +93,7 @@ object ZIOFTPExample extends ZIOAppDefault { .via(ZPipeline.utf8Decode) .runCollect _ <- Console.printLine(s"Content of $path file:") - _ <- Console.printLine(file.fold("")(_ + _)) + _ <- Console.printLine(file.mkString) } yield () override def run = myApp.provideSomeLayer(unsecure(settings))