Skip to content

Commit

Permalink
Fix #53 Unable to delete file on windows (#306)
Browse files Browse the repository at this point in the history
* Fix #53 Unable to delete file on windows

* Fix folder template name

* Fix code style

* Use UUID instead of timestamp Factorize deleteDirectory

* Fix log color

* Revert UUID changes

* Revert UUID changes

* Revert gradle.properties
  • Loading branch information
badoualy authored May 15, 2022
1 parent 656f6a0 commit 957c19e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions core/src/main/scala/com/karumi/shot/Shot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class Shot(
} else {
console.showSuccess("✅ Yeah!!! Your tests are passing.")
}
removeProjectTemporalScreenshotsFolder(shotFolder)
reporter.generateVerificationReport(
appId,
comparison,
Expand All @@ -130,6 +129,7 @@ class Shot(
"🤓 You can review the execution report here: " + shotFolder
.verificationReportFolder() + "index.html"
)
removeProjectTemporalScreenshotsFolder(shotFolder)
comparison
}
}
Expand Down Expand Up @@ -293,9 +293,11 @@ class Shot(
}

private def removeProjectTemporalScreenshotsFolder(shotFolder: ShotFolder): Unit = {
FileUtils.deleteDirectory(new File(shotFolder.pulledScreenshotsFolder()))
FileUtils.deleteDirectory(new File(shotFolder.pulledComposeScreenshotsFolder()))
FileUtils.deleteDirectory(new File(shotFolder.pulledComposeOrchestratedScreenshotsFolder()))
// Fix for https://github.com/pedrovgs/Shot/issues/53
// Avoid crash when directory can't be deleted
safeDeleteDirectory(new File(shotFolder.pulledScreenshotsFolder()))
safeDeleteDirectory(new File(shotFolder.pulledComposeScreenshotsFolder()))
safeDeleteDirectory(new File(shotFolder.pulledComposeOrchestratedScreenshotsFolder()))
}

private def extractPicturesFromBundle(screenshotsFolder: String): Unit = {
Expand All @@ -304,4 +306,12 @@ class Shot(
TinyZip.unzip(bundleFile, screenshotsFolder)
}
}

private def safeDeleteDirectory(file: File): Unit = {
try {
FileUtils.deleteDirectory(file)
} catch {
case e: Throwable => println(Console.YELLOW + s"Failed to delete directory: $e")
}
}
}

0 comments on commit 957c19e

Please sign in to comment.