From 423e2b0e817b159aa2b4a9720dd45701029563ae Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Wed, 12 Apr 2023 10:16:23 -0400 Subject: [PATCH] 2023-04-12 Fred Gleason * Added a 'RDUpload::createDestinationDirs()' method. Signed-off-by: Fred Gleason --- ChangeLog | 2 ++ lib/rdupload.cpp | 15 +++++++++++++++ lib/rdupload.h | 2 ++ tests/upload_test.cpp | 8 +++++++- tests/upload_test.h | 5 +++-- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b01c307..3f9a82ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24021,3 +24021,5 @@ * Refactored code in rdrssd(8) to improve reliability. 2023-03-24 Fred Gleason * Incremented the package version to 4.0.0rc2int0. +2023-04-12 Fred Gleason + * Added a 'RDUpload::createDestinationDirs()' method. diff --git a/lib/rdupload.cpp b/lib/rdupload.cpp index 6264ebca..42031be5 100644 --- a/lib/rdupload.cpp +++ b/lib/rdupload.cpp @@ -76,6 +76,7 @@ RDUpload::RDUpload(RDConfig *c,QObject *parent) : RDTransfer(c,parent) { conv_aborting=false; + conv_create_dst_dirs=false; } @@ -106,6 +107,12 @@ void RDUpload::setDestinationUrl(const QString &url) } +void RDUpload::createDestinationDirs(bool state) +{ + conv_create_dst_dirs=state; +} + + int RDUpload::totalSteps() const { return conv_src_size; @@ -178,6 +185,14 @@ RDUpload::ErrorCode RDUpload::runUpload(const QString &username, } curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST,0); // Don't verify host key + // + // Create any needed target directories + // + if(conv_create_dst_dirs) { + curl_easy_setopt(curl,CURLOPT_FTP_CREATE_MISSING_DIRS, + CURLFTP_CREATE_DIR_RETRY); + } + // // Transfer Parameters // diff --git a/lib/rdupload.h b/lib/rdupload.h index f2e68ffa..bc3a5c28 100644 --- a/lib/rdupload.h +++ b/lib/rdupload.h @@ -39,6 +39,7 @@ class RDUpload : public RDTransfer QStringList supportedSchemes() const; void setSourceFile(const QString &filename); void setDestinationUrl(const QString &url); + void createDestinationDirs(bool state); int totalSteps() const; RDUpload::ErrorCode runUpload(const QString &username, const QString &password, @@ -62,6 +63,7 @@ class RDUpload : public RDTransfer double ulnow); QString conv_src_filename; QUrl conv_dst_url; + bool conv_create_dst_dirs; bool conv_aborting; uint conv_src_size; }; diff --git a/tests/upload_test.cpp b/tests/upload_test.cpp index 4b393982..dd113399 100644 --- a/tests/upload_test.cpp +++ b/tests/upload_test.cpp @@ -2,7 +2,7 @@ // // Test Rivendell file uploading. // -// (C) Copyright 2010-2022 Fred Gleason +// (C) Copyright 2010-2023 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -36,6 +36,7 @@ MainObject::MainObject(QObject *parent) password=""; RDUpload::ErrorCode conv_err; use_identity_file=false; + create_dirs=false; // // Open the Database @@ -66,6 +67,10 @@ MainObject::MainObject(QObject *parent) use_identity_file=true; rda->cmdSwitch()->setProcessed(i,true); } + if(rda->cmdSwitch()->key(i)=="--create-dirs") { + create_dirs=true; + rda->cmdSwitch()->setProcessed(i,true); + } if(rda->cmdSwitch()->key(i)=="--source-file") { source_filename=rda->cmdSwitch()->value(i); rda->cmdSwitch()->setProcessed(i,true); @@ -100,6 +105,7 @@ MainObject::MainObject(QObject *parent) RDUpload *conv=new RDUpload(rda->config(),this); conv->setSourceFile(source_filename); conv->setDestinationUrl(destination_url); + conv->createDestinationDirs(create_dirs); printf("Uploading...\n"); conv_err=conv-> runUpload(username,password,ssh_identity_filename,use_identity_file, diff --git a/tests/upload_test.h b/tests/upload_test.h index d2ee99d5..14761255 100644 --- a/tests/upload_test.h +++ b/tests/upload_test.h @@ -2,7 +2,7 @@ // // Test Rivendell file uploading // -// (C) Copyright 2010,2016-2018 Fred Gleason +// (C) Copyright 2010-2023 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -25,7 +25,7 @@ #include -#define UPLOAD_TEST_USAGE "[options]\n\nTest the Rivendell upload routines\n\nOptions are:\n--username=\n\n--password=\n\n--ssh-identity-key=\n\n--use-identity-file=y|n\n\n--source-file=\n\n--destination-url=\n\n" +#define UPLOAD_TEST_USAGE "[options]\n\nTest the Rivendell upload routines\n\nOptions are:\n--username=\n\n--password=\n\n--ssh-identity-key=\n\n--use-identity-file=y|n\n\n--create-dirs\n\n--source-file=\n\n--destination-url=\n\n" class MainObject : public QObject { @@ -35,6 +35,7 @@ class MainObject : public QObject private: QString username; QString password; + bool create_dirs; QString source_filename; QString destination_url; QString ssh_identity_filename;