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

Allow overwriting of the target #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class FileTransferManager(private val common: CommonExtension) : FileTransfer {
common.prop.string("fileTransfer.domain")?.let { set(it) }
}

val downloadOverwrite = common.obj.boolean {
convention(false)
common.prop.boolean("fileTransfer.downloadOverwrite")?.let { set(it) }
}

val uploadOverwrite = common.obj.boolean {
convention(false)
common.prop.boolean("fileTransfer.uploadOverwrite")?.let { set(it) }
}

val credentials: Pair<String, String>
get() = if (user.orNull.isNullOrBlank() && password.orNull.isNullOrBlank())
user.get() to password.get()
Expand Down Expand Up @@ -133,8 +143,11 @@ class FileTransferManager(private val common: CommonExtension) : FileTransfer {
*/
fun downloadUsing(transfer: FileTransfer, dirUrl: String, fileName: String, target: File) {
if (target.exists()) {
logger.info("Skipping downloading file from URL '$dirUrl/$fileName' to '$target' as of it already exists.")
return
if (!downloadOverwrite.get()) {
logger.info("Skipping downloading file from URL '$dirUrl/$fileName' to '$target' as of it already exists.")
return
}
logger.info("Downloading file from URL '$dirUrl/$fileName' overwrites existing file '$target'.")
}

target.parentFile.mkdirs()
Expand Down Expand Up @@ -172,8 +185,11 @@ class FileTransferManager(private val common: CommonExtension) : FileTransfer {

try {
if (stat(dirUrl, fileName) != null) { // 'stat' may be unsupported
logger.info("Skipping uploading file to URL '$fileUrl' as of it already exists on server.")
return
if (!uploadOverwrite.get()) {
logger.info("Skipping uploading file to URL '$fileUrl' as of it already exists on server.")
return
}
logger.info("Uploading file from '$source' overwrites existing file at URL '$fileUrl'.")
}
} catch (e: FileException) {
logger.debug("Cannot check status of uploaded file at URL '$fileUrl'", e)
Expand Down