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

Fix #53 Unable to delete file on windows #306

Merged
merged 8 commits into from
May 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -123,7 +123,6 @@ class Shot(
} else {
console.showSuccess("✅ Yeah!!! Your tests are passing.")
}
removeProjectTemporalScreenshotsFolder(shotFolder)
reporter.generateVerificationReport(
appId,
comparison,
Expand All @@ -134,6 +133,7 @@ class Shot(
"🤓 You can review the execution report here: " + shotFolder
.verificationReportFolder() + "index.html"
)
removeProjectTemporalScreenshotsFolder(shotFolder)
comparison
}
}
Expand Down Expand Up @@ -297,9 +297,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 @@ -308,4 +310,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")
}
}
}