Mercurial > hg > octave-nkf
changeset 17595:4b65355a31f2
avoid some code duplication in url-transfer ftp methods
* url-transfer.cc (url_transfer::ftp_file_or_dir_action):
New function.
(url_transfer::cwd, url_transfer::del, url_transfer::rmdir,
url_transfer::mkdir): Call ftp_file_or_dir_action.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 07 Oct 2013 21:23:51 -0400 |
parents | f957fa0d2748 |
children | 43b9181340fb |
files | liboctave/util/url-transfer.cc |
diffstat | 1 files changed, 27 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/util/url-transfer.cc +++ b/liboctave/util/url-transfer.cc @@ -401,74 +401,22 @@ void cwd (const std::string& path) { - struct curl_slist *slist = 0; - - unwind_protect frame; - frame.add_fcn (curl_slist_free_all, slist); - - std::string cmd = "cwd " + path; - slist = curl_slist_append (slist, cmd.c_str ()); - SETOPT (CURLOPT_POSTQUOTE, slist); - - perform (); - if (! good ()) - return; - - SETOPT (CURLOPT_POSTQUOTE, 0); + ftp_file_or_dir_action (path, "cwd"); } void del (const std::string& file) { - struct curl_slist *slist = 0; - - unwind_protect frame; - frame.add_fcn (curl_slist_free_all, slist); - - std::string cmd = "dele " + file; - slist = curl_slist_append (slist, cmd.c_str ()); - SETOPT (CURLOPT_POSTQUOTE, slist); - - perform (); - if (! good ()) - return; - - SETOPT (CURLOPT_POSTQUOTE, 0); + ftp_file_or_dir_action (file, "dele"); } void rmdir (const std::string& path) { - struct curl_slist *slist = 0; - - unwind_protect frame; - frame.add_fcn (curl_slist_free_all, slist); - - std::string cmd = "rmd " + path; - slist = curl_slist_append (slist, cmd.c_str ()); - SETOPT (CURLOPT_POSTQUOTE, slist); - - perform (); - if (! good ()) - return; - - SETOPT (CURLOPT_POSTQUOTE, 0); + ftp_file_or_dir_action (path, "rmd"); } void mkdir (const std::string& path) { - struct curl_slist *slist = 0; - - unwind_protect frame; - frame.add_fcn (curl_slist_free_all, slist); - - std::string cmd = "mkd " + path; - slist = curl_slist_append (slist, cmd.c_str ()); - SETOPT (CURLOPT_POSTQUOTE, slist); - - perform (); - if (! good ()) - return; - - SETOPT (CURLOPT_POSTQUOTE, 0); + ftp_file_or_dir_action (path, "mkd"); } void rename (const std::string& oldname, const std::string& newname) @@ -750,6 +698,29 @@ return query.str (); } + + void ftp_file_or_dir_action (const std::string& file_or_dir, + const std::string& action) + { + struct curl_slist *slist = 0; + + unwind_protect frame; + + frame.add_fcn (curl_slist_free_all, slist); + + std::string cmd = action + " " + file_or_dir; + + slist = curl_slist_append (slist, cmd.c_str ()); + + SETOPT (CURLOPT_POSTQUOTE, slist); + + perform (); + + if (! good ()) + return; + + SETOPT (CURLOPT_POSTQUOTE, 0); + } }; #undef SETOPT