Skip to content

Commit ff4ee3f

Browse files
committed
Fix delete file if exists
1 parent c7fb37c commit ff4ee3f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
- docker
77

88
jdk:
9-
- openjdk11
9+
- oraclejdk8
1010

1111
addons:
1212
apt:

src/main/scala/nz/co/bottech/sbt/gpg/gpgArgument.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ final case class FileOption(option: String, delete: Boolean) extends (File => Gp
5858
override def apply(file: File): GpgOption = GpgOption(option, prepare(file))
5959

6060
private def prepare(file: File): () => String = () => {
61-
if (delete) {//} && file.canWrite) {
62-
println(s"***** File '${file.getPath}' exists ${file.exists()} canWrite ${file.canWrite}")
63-
val _ = Files.deleteIfExists(file.toPath)
61+
if (delete && file.exists()) {
62+
// Files.deleteIfExists throws AccessDeniedException if the file does not exist.
63+
// See 9a548050a7cef741aa1bb71d918bc57cb3ec18f2 and https://travis-ci.org/BotTech/sbt-gpg/jobs/457153754
64+
val _ = Files.delete(file.toPath)
6465
}
6566
file.getPath
6667
}

0 commit comments

Comments
 (0)