Skip to content

Commit

Permalink
Add ensureExecutable to FileAlg
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Stewart committed Mar 29, 2021
1 parent 98a386c commit 952ed26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/core/src/main/scala/org/scalasteward/core/io/FileAlg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.http4s.Uri
import org.http4s.implicits.http4sLiteralsSyntax
import org.typelevel.log4cats.Logger
import scala.io.Source
import java.nio.file.attribute.PosixFilePermission

trait FileAlg[F[_]] {
def deleteForce(file: File): F[Unit]
Expand All @@ -50,6 +51,8 @@ trait FileAlg[F[_]] {

def writeFile(file: File, content: String): F[Unit]

def ensureExecutable(file: File): F[Unit]

final def createTemporarily[A, E](file: File, content: String)(
fa: F[A]
)(implicit F: Bracket[F, E]): F[A] = {
Expand Down Expand Up @@ -147,5 +150,16 @@ object FileAlg {
logger.debug(s"Write $file") >>
file.parentOption.fold(F.unit)(ensureExists(_).void) >>
F.delay(file.write(content)).void

override def ensureExecutable(file: File): F[Unit] =
F.delay(
file.setPermissions(
file.permissions ++ Set(
PosixFilePermission.OWNER_EXECUTE,
PosixFilePermission.GROUP_EXECUTE,
PosixFilePermission.OTHERS_EXECUTE
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ class MockFileAlg extends FileAlg[MockEff] {
StateT.modifyF[IO, MockState](
_.exec(List("write", file.pathAsString)).addFiles(file -> content)
)

override def ensureExecutable(file: File): MockEff[Unit] =
StateT.modify[IO, MockState](
_.exec(List("chmod", "u+x,g+x,o+x", file.pathAsString))
) >> StateT.liftF(ioFileAlg.ensureExecutable(file))
}

0 comments on commit 952ed26

Please sign in to comment.