File kdump-URLTransfer-complete-target.patch of Package kdump.17334

Date: Wed Jun 14 10:48:33 2017 +0200
From: Petr Tesarik <ptesarik@suse.com>
Subject: Use the complete target URL for URLTransfer
References: FATE#321844
Upstream: v0.8.17
Git-commit: 4540de762995219c19f8feac2f594868595741ea

Append the subdirectory name in the caller and pass around a standard
vector or RootDirURL objects.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>

diff --git a/kdumptool/configuration.cc b/kdumptool/configuration.cc
index 167195d..192dcfd 100644
--- a/kdumptool/configuration.cc
+++ b/kdumptool/configuration.cc
@@ -180,11 +180,13 @@ bool Configuration::needsNetwork()
     if (netconfig != "auto")
 	return true;
 
-    RootDirURLVector urlv(KDUMP_SAVEDIR.value(), "");
-    RootDirURLVector::iterator it;
-    for (it = urlv.begin(); it != urlv.end(); ++it)
-	if (it->getProtocol() != URLParser::PROT_FILE)
+    std::istringstream iss(KDUMP_SAVEDIR.value());
+    string elem;
+    while (iss >> elem) {
+        URLParser url(elem);
+        if (url.getProtocol() != URLParser::PROT_FILE)
 	    return true;
+    }
 
     return !KDUMP_SMTP_SERVER.value().empty() &&
 	!KDUMP_NOTIFICATION_TO.value().empty();
diff --git a/kdumptool/deletedumps.cc b/kdumptool/deletedumps.cc
index 500299e..f19a421 100644
--- a/kdumptool/deletedumps.cc
+++ b/kdumptool/deletedumps.cc
@@ -87,10 +87,12 @@ void DeleteDumps::execute()
         return;
     }
 
-    RootDirURLVector urls(config->KDUMP_SAVEDIR.value(), m_rootdir);
-    RootDirURLVector::const_iterator it;
-    for (it = urls.begin(); it != urls.end(); ++it)
-        delete_one(*it, oldDumps);
+    std::istringstream iss(config->KDUMP_SAVEDIR.value());
+    string elem;
+    while (iss >> elem) {
+        RootDirURL url(elem, m_rootdir);
+        delete_one(url, oldDumps);
+    }
 }
 
 // -----------------------------------------------------------------------------
diff --git a/kdumptool/print_target.cc b/kdumptool/print_target.cc
index 06dbc41..8d3e50d 100644
--- a/kdumptool/print_target.cc
+++ b/kdumptool/print_target.cc
@@ -60,12 +60,16 @@ void PrintTarget::execute()
 
     Configuration *config = Configuration::config();
 
-    RootDirURLVector urlv(config->KDUMP_SAVEDIR.value(), m_rootdir);
-    RootDirURLVector::iterator it;
-    for (it = urlv.begin(); it != urlv.end(); ++it) {
-	if (it != urlv.begin())
+    std::istringstream iss(config->KDUMP_SAVEDIR.value());
+    string elem;
+    bool first = true;
+    while (iss >> elem) {
+        RootDirURL url(elem, m_rootdir);
+        if (first)
+            first = false;
+        else
 	    cout << endl;
-	print_one(*it);
+	print_one(url);
     }
 }
 
diff --git a/kdumptool/rootdirurl.cc b/kdumptool/rootdirurl.cc
index 38e613c..41352e9 100644
--- a/kdumptool/rootdirurl.cc
+++ b/kdumptool/rootdirurl.cc
@@ -44,19 +44,4 @@ RootDirURL::RootDirURL(const std::string &url, const std::string &rootdir)
 
 //}}}
 
-//{{{ RootDirURLVector ---------------------------------------------------------
-
-// -----------------------------------------------------------------------------
-RootDirURLVector::RootDirURLVector(const std::string &urls,
-				   const std::string &rootdir)
-    throw (KError)
-{
-    std::istringstream iss(urls);
-    std::string url;
-    while (iss >> url)
-	push_back(RootDirURL(url, rootdir));
-}
-
-//}}}
-
 // vim: set sw=4 ts=4 fdm=marker et: :collapseFolds=1:
diff --git a/kdumptool/rootdirurl.h b/kdumptool/rootdirurl.h
index c93c825..724d4ab 100644
--- a/kdumptool/rootdirurl.h
+++ b/kdumptool/rootdirurl.h
@@ -59,28 +59,7 @@ class RootDirURL : public URLParser {
 	std::string m_realpath;
 };
 
-//}}}
-
-//{{{ RootDirURLVector ---------------------------------------------------------
-
-/**
- * Parse a list of URLs.
- */
-class RootDirURLVector: public std::vector<RootDirURL> {
-
-    public:
-
-        /**
-         * Creates a new RootDirURLVector.
-         *
-         * @param[in] urls space-separated list of URLs to parse
-         * @param[in] rootdir root directory for local files
-         * @exception KError if any URL from the list cannot be parsed
-         */
-        RootDirURLVector(const std::string &urls, const std::string &rootdir)
-        throw (KError);
-
-};
+typedef std::vector<RootDirURL> RootDirURLVector;
 
 //}}}
 
diff --git a/kdumptool/savedump.cc b/kdumptool/savedump.cc
index eeec24e..9938b6f 100644
--- a/kdumptool/savedump.cc
+++ b/kdumptool/savedump.cc
@@ -110,9 +110,15 @@ void SaveDump::execute()
     // build the transfer object
     // prepend a time stamp to the save dir
     string subdir = Stringutil::formatCurrentTime(ISO_DATETIME);
-    RootDirURLVector urlv(config->KDUMP_SAVEDIR.value(), m_rootdir);
+    RootDirURLVector urlv;
+    std::istringstream iss(config->KDUMP_SAVEDIR.value());
+    FilePath elem;
+    while (iss >> elem) {
+        RootDirURL url(elem.appendPath(subdir), m_rootdir);
+        urlv.push_back(url);
+    }
 
-    m_transfer = getTransfer(urlv, subdir);
+    m_transfer = getTransfer(urlv);
 
     // save the dump
     try {
@@ -120,11 +126,11 @@ void SaveDump::execute()
     } catch (const KError &error) {
         setErrorCode(1);
 
-        sendNotification(true, urlv, subdir);
+        sendNotification(true, urlv);
 
         // run checkAndDelete() in any case
         try {
-            checkAndDelete(urlv, subdir);
+            checkAndDelete(urlv);
         } catch (const KError &error) {
             cout << error.what() << endl;
         }
@@ -136,13 +142,13 @@ void SaveDump::execute()
     }
 
     // send the email afterwards
-    sendNotification(false, urlv, subdir);
+    sendNotification(false, urlv);
 
     // because we don't know the file size in advance, check
     // afterwards if the disk space is not sufficient and delete
     // the dump again
     try {
-        checkAndDelete(urlv, subdir);
+        checkAndDelete(urlv);
     } catch (const KError &error) {
         setErrorCode(1);
         if (config->KDUMP_CONTINUE_ON_ERROR.value())
@@ -594,22 +600,20 @@ string SaveDump::findMapfile()
 }
 
 // -----------------------------------------------------------------------------
-void SaveDump::checkAndDelete(const RootDirURLVector &urlv,
-			      const string &subdir)
+void SaveDump::checkAndDelete(const RootDirURLVector &urlv)
     throw (KError)
 {
     RootDirURLVector::const_iterator it;
     for (it = urlv.begin(); it != urlv.end(); ++it)
-	check_one(*it, subdir);
+	check_one(*it);
 }
 
 // -----------------------------------------------------------------------------
-void SaveDump::check_one(const RootDirURL &parser,
-			 const string &subdir)
+void SaveDump::check_one(const RootDirURL &parser)
     throw (KError)
 {
-    Debug::debug()->trace("SaveDump::check_one(\"%s\", \"%s\")",
-			  parser.getURL().c_str(), subdir.c_str());
+    Debug::debug()->trace("SaveDump::check_one(\"%s\")",
+			  parser.getURL().c_str());
 
     // only do that check for local files
     if (parser.getProtocol() != URLParser::PROT_FILE) {
@@ -618,7 +622,6 @@ void SaveDump::check_one(const RootDirURL &parser,
     }
 
     FilePath path = parser.getRealPath();
-    path.appendPath(subdir);
     Configuration *config = Configuration::config();
 
     unsigned long long freeSize = path.freeDiskSize();
@@ -634,8 +637,7 @@ void SaveDump::check_one(const RootDirURL &parser,
 }
 
 // -----------------------------------------------------------------------------
-void SaveDump::sendNotification(bool failure, const RootDirURLVector &urlv,
-				const string &subdir)
+void SaveDump::sendNotification(bool failure, const RootDirURLVector &urlv)
     throw ()
 {
     Debug::debug()->trace("SaveDump::sendNotification");
@@ -694,10 +696,8 @@ void SaveDump::sendNotification(bool failure, const RootDirURLVector &urlv,
         else {
 	    ss << "Dump has been copied to" << endl;
 	    RootDirURLVector::const_iterator it;
-            for (it = urlv.begin(); it != urlv.end(); ++it) {
-                FilePath fp = it->getURL();
-                ss << fp.appendPath(subdir) << endl;
-            }
+            for (it = urlv.begin(); it != urlv.end(); ++it)
+                ss << it->getURL() << endl;
 	}
 
         email.setBody(ss.str());
@@ -738,12 +738,11 @@ string SaveDump::getKernelReleaseCommandline()
 }
 
 // -----------------------------------------------------------------------------
-Transfer *SaveDump::getTransfer(const RootDirURLVector &urlv,
-				const string &subdir)
+Transfer *SaveDump::getTransfer(const RootDirURLVector &urlv)
     throw (KError)
 {
-    Debug::debug()->trace("SaveDump::getTransfer(%p, \"%s\")",
-			  &urlv, subdir.c_str());
+    Debug::debug()->trace("SaveDump::getTransfer(%p)",
+			  &urlv);
 
     if (urlv.size() == 0)
 	throw KError("No target specified!");
@@ -751,27 +750,27 @@ Transfer *SaveDump::getTransfer(const RootDirURLVector &urlv,
     switch (urlv.begin()->getProtocol()) {
         case URLParser::PROT_FILE:
             Debug::debug()->dbg("Returning FileTransfer");
-            return new FileTransfer(urlv, subdir);
+            return new FileTransfer(urlv);
 
         case URLParser::PROT_FTP:
             Debug::debug()->dbg("Returning FTPTransfer");
-            return new FTPTransfer(urlv, subdir);
+            return new FTPTransfer(urlv);
 
         case URLParser::PROT_SFTP:
             Debug::debug()->dbg("Returning SFTPTransfer");
-            return new SFTPTransfer(urlv, subdir);
+            return new SFTPTransfer(urlv);
 
         case URLParser::PROT_SSH:
 	    Debug::debug()->dbg("Returning SSHTransfer");
-	    return new SSHTransfer(urlv, subdir);
+	    return new SSHTransfer(urlv);
 
         case URLParser::PROT_NFS:
             Debug::debug()->dbg("Returning NFSTransfer");
-            return new NFSTransfer(urlv, subdir);
+            return new NFSTransfer(urlv);
 
         case URLParser::PROT_CIFS:
             Debug::debug()->dbg("Returning CIFSTransfer");
-            return new CIFSTransfer(urlv, subdir);
+            return new CIFSTransfer(urlv);
 
         default:
             throw KError("Unknown protocol.");
diff --git a/kdumptool/savedump.h b/kdumptool/savedump.h
index cd3f70d..cd11177 100644
--- a/kdumptool/savedump.h
+++ b/kdumptool/savedump.h
@@ -86,12 +86,10 @@ class SaveDump : public Subcommand {
         std::string findMapfile()
         throw (KError);
 
-        void checkAndDelete(const RootDirURLVector &urlv,
-			    const std::string &subdir)
+        void checkAndDelete(const RootDirURLVector &urlv)
         throw (KError);
 
-        void sendNotification(bool failure, const RootDirURLVector &urlv,
-			      const std::string &subdir)
+        void sendNotification(bool failure, const RootDirURLVector &urlv)
         throw ();
 
         std::string getKernelReleaseCommandline()
@@ -106,8 +104,7 @@ class SaveDump : public Subcommand {
          * @exception KError if parsing the URL failed or there's no
          *            implementation for that class.
          */
-	Transfer *getTransfer(const RootDirURLVector &urlv,
-			      const std::string &subdir)
+	Transfer *getTransfer(const RootDirURLVector &urlv)
 	throw (KError);
 
     private:
@@ -122,8 +119,7 @@ class SaveDump : public Subcommand {
         std::string m_hostname;
         bool m_nomail;
 
-        void check_one(const RootDirURL &parser,
-		       const std::string &subdir)
+        void check_one(const RootDirURL &parser)
         throw (KError);
 };
 
diff --git a/kdumptool/sshtransfer.cc b/kdumptool/sshtransfer.cc
index 5a036db..12f315d 100644
--- a/kdumptool/sshtransfer.cc
+++ b/kdumptool/sshtransfer.cc
@@ -40,10 +40,9 @@ using std::endl;
 //{{{ SSHTransfer -------------------------------------------------------------
 
 /* -------------------------------------------------------------------------- */
-SSHTransfer::SSHTransfer(const RootDirURLVector &urlv,
-			 const std::string &subdir)
+SSHTransfer::SSHTransfer(const RootDirURLVector &urlv)
     throw (KError)
-    : URLTransfer(urlv, subdir)
+    : URLTransfer(urlv)
 {
     if (urlv.size() > 1)
 	cerr << "WARNING: First dump target used; rest ignored." << endl;
@@ -59,9 +58,7 @@ SSHTransfer::SSHTransfer(const RootDirURLVector &urlv,
 	cerr << "WARNING: Dump target not reachable" << endl;
 
     string remote;
-    FilePath fp = target.getPath();
-    fp.appendPath(getSubDir());
-    remote.assign("mkdir -p ").append(fp);
+    remote.assign("mkdir -p ").append(target.getPath());
 
     SubProcess p;
     p.spawn("ssh", makeArgs(remote));
@@ -96,7 +93,7 @@ void SSHTransfer::perform(DataProvider *dataprovider,
     const RootDirURL &target = urlv.front();
 
     FilePath fp = target.getPath();
-    fp.appendPath(getSubDir()).appendPath(target_files.front());
+    fp.appendPath(target_files.front());
 
     string remote;
     remote.assign("dd of=").append(fp).append("-incomplete");
@@ -357,10 +354,9 @@ ByteVector const &SFTPPacket::update(void)
 //{{{ SFTPTransfer -------------------------------------------------------------
 
 /* -------------------------------------------------------------------------- */
-SFTPTransfer::SFTPTransfer(const RootDirURLVector &urlv,
-			   const std::string &subdir)
+SFTPTransfer::SFTPTransfer(const RootDirURLVector &urlv)
     throw (KError)
-    : URLTransfer(urlv, subdir)
+    : URLTransfer(urlv)
 {
     if (urlv.size() > 1)
 	cerr << "WARNING: First dump target used; rest ignored." << endl;
@@ -394,9 +390,7 @@ SFTPTransfer::SFTPTransfer(const RootDirURLVector &urlv,
     m_proto_ver = initpkt.getInt32();
     Debug::debug()->dbg("Remote SFTP version %lu", m_proto_ver);
 
-    FilePath fp = parser.getPath();
-    fp.appendPath(getSubDir());
-    mkpath(fp);
+    mkpath(parser.getPath());
 }
 
 /* -------------------------------------------------------------------------- */
@@ -433,7 +427,7 @@ void SFTPTransfer::perform(DataProvider *dataprovider,
     const RootDirURL &target = urlv.front();
 
     FilePath fp = target.getPath();
-    fp.appendPath(getSubDir()).appendPath(target_files.front());
+    fp.appendPath(target_files.front());
 
     string handle = createfile(fp);
     try {
diff --git a/kdumptool/sshtransfer.h b/kdumptool/sshtransfer.h
index e90d0c3..8a9081a 100644
--- a/kdumptool/sshtransfer.h
+++ b/kdumptool/sshtransfer.h
@@ -41,7 +41,7 @@ class SSHTransfer : public URLTransfer {
          *
          * @exception KError when initialising the underlying library fails
          */
-        SSHTransfer(const RootDirURLVector &urlv, const std::string &subdir)
+        SSHTransfer(const RootDirURLVector &urlv)
         throw (KError);
 
         /**
@@ -205,7 +205,7 @@ class SFTPTransfer : public URLTransfer {
          *
          * @exception KError when initialising the underlying library fails
          */
-        SFTPTransfer(const RootDirURLVector &urlv, const std::string &subdir)
+        SFTPTransfer(const RootDirURLVector &urlv)
         throw (KError);
 
         /**
diff --git a/kdumptool/transfer.cc b/kdumptool/transfer.cc
index 365055e..4e419ff 100644
--- a/kdumptool/transfer.cc
+++ b/kdumptool/transfer.cc
@@ -64,9 +64,9 @@ void Transfer::perform(DataProvider *dataprovider,
 //{{{ URLTransfer --------------------------------------------------------------
 
 // -----------------------------------------------------------------------------
-URLTransfer::URLTransfer(const RootDirURLVector &urlv, const string &subdir)
+URLTransfer::URLTransfer(const RootDirURLVector &urlv)
     throw (KError)
-    : m_urlVector(urlv), m_subDir(subdir)
+    : m_urlVector(urlv)
 {
 }
 
@@ -74,10 +74,9 @@ URLTransfer::URLTransfer(const RootDirURLVector &urlv, const string &subdir)
 //{{{ FileTransfer -------------------------------------------------------------
 
 // -----------------------------------------------------------------------------
-FileTransfer::FileTransfer(const RootDirURLVector &urlv,
-			   const std::string &subdir)
+FileTransfer::FileTransfer(const RootDirURLVector &urlv)
     throw (KError)
-    : URLTransfer(urlv, subdir), m_bufferSize(0), m_buffer(NULL)
+    : URLTransfer(urlv), m_bufferSize(0), m_buffer(NULL)
 {
     RootDirURLVector::const_iterator it;
     for (it = urlv.begin(); it != urlv.end(); ++it)
@@ -87,7 +86,6 @@ FileTransfer::FileTransfer(const RootDirURLVector &urlv,
     // create directories
     for (it = urlv.begin(); it != urlv.end(); ++it) {
         FilePath dir = it->getRealPath();
-        dir.appendPath(subdir);
         dir.mkdir(true);
     }
 
@@ -130,7 +128,7 @@ void FileTransfer::perform(DataProvider *dataprovider,
     RootDirURLVector::const_iterator itv = urlv.begin();
     for (it = target_files.begin(); it != target_files.end(); ++it) {
         FilePath fp = itv->getRealPath();
-        full_targets.push_back(fp.appendPath(getSubDir()).appendPath(*it));
+        full_targets.push_back(fp.appendPath(*it));
 	if (++itv == urlv.end())
 	    itv = urlv.begin();
     }
@@ -308,10 +306,9 @@ static int curl_debug(CURL *curl, curl_infotype info, char *buffer,
 }
 
 // -----------------------------------------------------------------------------
-FTPTransfer::FTPTransfer(const RootDirURLVector &urlv,
-			 const std::string &subdir)
+FTPTransfer::FTPTransfer(const RootDirURLVector &urlv)
     throw (KError)
-    : URLTransfer(urlv, subdir), m_curl(NULL)
+    : URLTransfer(urlv), m_curl(NULL)
 {
     if (urlv.size() > 1)
 	cerr << "WARNING: First dump target used; rest ignored." << endl;
@@ -425,7 +422,7 @@ void FTPTransfer::open(DataProvider *dataprovider,
 
     // set the URL
     FilePath full_url = parser.getURL();
-    full_url.appendPath(getSubDir()).appendPath(target_file);
+    full_url.appendPath(target_file);
     err = curl_easy_setopt(m_curl, CURLOPT_URL, full_url.c_str());
     if (err != CURLE_OK)
         throw KError(string("CURL error: ") + m_curlError);
@@ -440,16 +437,15 @@ void FTPTransfer::open(DataProvider *dataprovider,
 //{{{ NFSTransfer --------------------------------------------------------------
 
 // -----------------------------------------------------------------------------
-NFSTransfer::NFSTransfer(const RootDirURLVector &urlv,
-			 const std::string &subdir)
+NFSTransfer::NFSTransfer(const RootDirURLVector &urlv)
     throw (KError)
-    : URLTransfer(urlv, subdir), m_mountpoint(""), m_fileTransfer(NULL)
+    : URLTransfer(urlv), m_mountpoint(""), m_fileTransfer(NULL)
 {
-    RootDirURLVector file_urlv("", "");
+    RootDirURLVector file_urlv;
     RootDirURLVector::const_iterator it;
     for (it = urlv.begin(); it != urlv.end(); ++it)
 	file_urlv.push_back(translate(*it));
-    m_fileTransfer = new FileTransfer(file_urlv, subdir);
+    m_fileTransfer = new FileTransfer(file_urlv);
 }
 
 // -----------------------------------------------------------------------------
@@ -521,16 +517,15 @@ void NFSTransfer::close()
 //{{{ CIFSTransfer -------------------------------------------------------------
 
 // -----------------------------------------------------------------------------
-CIFSTransfer::CIFSTransfer(const RootDirURLVector &urlv,
-			   const std::string &subdir)
+CIFSTransfer::CIFSTransfer(const RootDirURLVector &urlv)
     throw (KError)
-    : URLTransfer(urlv, subdir), m_mountpoint(""), m_fileTransfer(NULL)
+    : URLTransfer(urlv), m_mountpoint(""), m_fileTransfer(NULL)
 {
-    RootDirURLVector file_urlv("", "");
+    RootDirURLVector file_urlv;
     RootDirURLVector::const_iterator it;
     for (it = urlv.begin(); it != urlv.end(); ++it)
 	file_urlv.push_back(translate(*it));
-    m_fileTransfer = new FileTransfer(file_urlv, subdir);
+    m_fileTransfer = new FileTransfer(file_urlv);
 }
 
 // -----------------------------------------------------------------------------
diff --git a/kdumptool/transfer.h b/kdumptool/transfer.h
index d81f2d4..a1ecf4f 100644
--- a/kdumptool/transfer.h
+++ b/kdumptool/transfer.h
@@ -102,10 +102,10 @@ class URLTransfer : public Transfer {
         /**
          * Creates a new URLTransfer object.
          *
-         * @param[in] url the URL
+         * @param[in] urlv target URLs
          * @throw KError if parsing the URL failed
          */
-        URLTransfer(const RootDirURLVector &urlv, const std::string &subdir)
+        URLTransfer(const RootDirURLVector &urlv)
         throw (KError);
 
         /**
@@ -117,18 +117,8 @@ class URLTransfer : public Transfer {
         throw ()
 	{ return m_urlVector; }
 
-	/**
-	 * Returns the subdirectory part.
-	 *
-	 * @return reference to the subdirectory.
-	 */
-	const std::string &getSubDir()
-	throw ()
-	{ return m_subDir; }
-
     private:
         RootDirURLVector m_urlVector;
-	std::string m_subDir;
 };
 
 //}}}
@@ -144,10 +134,10 @@ class FileTransfer : public URLTransfer {
         /**
          * Creates a new FileTransfer object.
          *
-         * @param[in] target_url the directory
+         * @param[in] urlv target directories
          * @throw KError if parsing the URL or creating the directory failed
          */
-        FileTransfer(const RootDirURLVector &urlv, const std::string &subdir)
+        FileTransfer(const RootDirURLVector &urlv)
         throw (KError);
 
         /**
@@ -202,7 +192,7 @@ class FTPTransfer : public URLTransfer {
          *
          * @exception KError when initialising the underlying library fails
          */
-        FTPTransfer(const RootDirURLVector &urlv, const std::string &subdir)
+        FTPTransfer(const RootDirURLVector &urlv)
         throw (KError);
 
         /**
@@ -248,7 +238,7 @@ class NFSTransfer : public URLTransfer {
          *
          * @exception KError when mounting the share failes
          */
-        NFSTransfer(const RootDirURLVector &urlv, const std::string &subdir)
+        NFSTransfer(const RootDirURLVector &urlv)
         throw (KError);
 
         /**
@@ -302,7 +292,7 @@ class CIFSTransfer : public URLTransfer {
          *
          * @exception KError when mounting the share failes
          */
-        CIFSTransfer(const RootDirURLVector &urlv, const std::string &subdir)
+        CIFSTransfer(const RootDirURLVector &urlv)
         throw (KError);
 
         /**
openSUSE Build Service is sponsored by