mirror of https://github.com/sbt/sbt.git
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(...)`.
This commit is contained in:
parent
99e681225c
commit
f353de243e
|
|
@ -362,31 +362,46 @@ private[sbt] object ConvertResolver {
|
||||||
|
|
||||||
override def put(source: File, destination: String, overwrite: Boolean): Unit = {
|
override def put(source: File, destination: String, overwrite: Boolean): Unit = {
|
||||||
val url = new URL(destination)
|
val url = new URL(destination)
|
||||||
if (url.getProtocol != IO.FileScheme) super.put(source, destination, overwrite)
|
try {
|
||||||
else {
|
if (url.getProtocol != IO.FileScheme) super.put(source, destination, overwrite)
|
||||||
// Here we duplicate the put method for files so we don't just bail on trying ot use Http handler
|
else {
|
||||||
val resource = getResource(destination)
|
// Here we duplicate the put method for files so we don't just bail on trying ot use Http handler
|
||||||
if (!overwrite && resource.exists()) {
|
val resource = getResource(destination)
|
||||||
throw new IOException(s"Destination file $destination exists and overwrite == false");
|
if (!overwrite && resource.exists()) {
|
||||||
}
|
throw new IOException(s"destination file exists and overwrite == false");
|
||||||
fireTransferInitiated(resource, TransferEvent.REQUEST_PUT);
|
}
|
||||||
try {
|
fireTransferInitiated(resource, TransferEvent.REQUEST_PUT);
|
||||||
val totalLength = source.length
|
try {
|
||||||
if (totalLength > 0) {
|
val totalLength = source.length
|
||||||
progress.setTotalLength(totalLength);
|
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
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue