From f353de243e5b686d02cab04f5de9de7c1f4b112d Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 29 Jul 2018 14:50:39 -0400 Subject: [PATCH] Fixes destination file exists error message Fixes sbt/sbt#3431 Fixes sbt/sbt#4275 https://github.com/sbt/librarymanagement/pull/171 attempted to fix the error message previously, but it was not handling the common cases where the put is delegated to `super.put(...)`. --- .../librarymanagement/ConvertResolver.scala | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/ivy/src/main/scala/sbt/internal/librarymanagement/ConvertResolver.scala b/ivy/src/main/scala/sbt/internal/librarymanagement/ConvertResolver.scala index 47d597660..545a8f9f6 100644 --- a/ivy/src/main/scala/sbt/internal/librarymanagement/ConvertResolver.scala +++ b/ivy/src/main/scala/sbt/internal/librarymanagement/ConvertResolver.scala @@ -362,31 +362,46 @@ private[sbt] object ConvertResolver { override def put(source: File, destination: String, overwrite: Boolean): Unit = { val url = new URL(destination) - if (url.getProtocol != IO.FileScheme) super.put(source, destination, overwrite) - else { - // Here we duplicate the put method for files so we don't just bail on trying ot use Http handler - val resource = getResource(destination) - if (!overwrite && resource.exists()) { - throw new IOException(s"Destination file $destination exists and overwrite == false"); - } - fireTransferInitiated(resource, TransferEvent.REQUEST_PUT); - try { - val totalLength = source.length - if (totalLength > 0) { - progress.setTotalLength(totalLength); + try { + if (url.getProtocol != IO.FileScheme) super.put(source, destination, overwrite) + else { + // Here we duplicate the put method for files so we don't just bail on trying ot use Http handler + val resource = getResource(destination) + if (!overwrite && resource.exists()) { + throw new IOException(s"destination file exists and overwrite == false"); + } + fireTransferInitiated(resource, TransferEvent.REQUEST_PUT); + try { + val totalLength = source.length + if (totalLength > 0) { + progress.setTotalLength(totalLength); + } + FileUtil.copy(source, new java.io.File(url.toURI), progress, overwrite) + () + } catch { + case ex: IOException => + fireTransferError(ex) + throw ex + case ex: RuntimeException => + fireTransferError(ex) + throw ex + } finally { + progress.setTotalLength(null); } - FileUtil.copy(source, new java.io.File(url.toURI), progress, overwrite) - () - } catch { - case ex: IOException => - fireTransferError(ex) - throw ex - case ex: RuntimeException => - fireTransferError(ex) - throw ex - } finally { - progress.setTotalLength(null); } + } catch { + // This error could be thrown either by super.put or the above + case ex: IOException if ex.getMessage.contains("destination file exists") => + throw new IOException( + s"""PUT operation failed because the desitnation file exists and overwriting is disabled: + | source : $source + | destination: $destination + |If you have a staging repository that has failed, drop it and start over. + |Otherwise fix the double publishing, or relax the setting as follows: + | publishConfiguration := publishConfiguration.value.withOverwrite(true) + | publishLocalConfiguration := publishLocalConfiguration.value.withOverwrite(true)""".stripMargin, + ex + ) } } }