summaryrefslogtreecommitdiff
path: root/ucb
diff options
context:
space:
mode:
authorAndreas Bille <abi@openoffice.org>2002-10-21 12:13:00 +0000
committerAndreas Bille <abi@openoffice.org>2002-10-21 12:13:00 +0000
commitf025f32de9a26a1d266bff0378213225e00e2190 (patch)
tree9f5b54484343cf38f7ab48d67f8d9fbdf139f315 /ucb
parent6c9dc72591ceb79c65b8ce97b589c973892fa9df (diff)
#94588# throwing now exceptions if ReplaceExisting = false and resource exists
Diffstat (limited to 'ucb')
-rw-r--r--ucb/source/ucp/ftp/ftpcontent.cxx82
-rw-r--r--ucb/source/ucp/ftp/ftpcontent.hxx8
-rw-r--r--ucb/source/ucp/ftp/ftpurl.cxx71
-rw-r--r--ucb/source/ucp/ftp/ftpurl.hxx16
-rw-r--r--ucb/source/ucp/ftp/test.py18
5 files changed, 151 insertions, 44 deletions
diff --git a/ucb/source/ucp/ftp/ftpcontent.cxx b/ucb/source/ucp/ftp/ftpcontent.cxx
index 37be547d4c56..d652e0a32d10 100644
--- a/ucb/source/ucp/ftp/ftpcontent.cxx
+++ b/ucb/source/ucp/ftp/ftpcontent.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontent.cxx,v $
*
- * $Revision: 1.11 $
+ * $Revision: 1.12 $
*
- * last change: $Author: abi $ $Date: 2002-10-17 16:28:20 $
+ * last change: $Author: abi $ $Date: 2002-10-21 13:12:59 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -102,6 +102,9 @@
#include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
#include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
#include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
+#include <com/sun/star/ucb/MissingPropertiesException.hpp>
+#include <com/sun/star/ucb/MissingInputStreamException.hpp>
+#include <com/sun/star/ucb/NameClashException.hpp>
#include <com/sun/star/ucb/OpenMode.hpp>
#include <com/sun/star/ucb/IOErrorCode.hpp>
@@ -296,7 +299,9 @@ enum ACTION { NOACTION,
THROWAUTHENTICATIONREQUEST,
THROWACCESSDENIED,
THROWINTERACTIVECONNECT,
- THROWRESOLVENAME };
+ THROWRESOLVENAME,
+ THROWQUOTE,
+ THROWGENERAL };
// virtual
@@ -407,8 +412,16 @@ Any SAL_CALL FTPContent::execute(
ucbhelper::cancelCommandExecution(
aRet,
Environment);
+ } else if(action == THROWQUOTE) {
+
+ } else if(action == THROWGENERAL) {
+ ucbhelper::cancelCommandExecution(
+ IOErrorCode_GENERAL,
+ Sequence<Any>(0),
+ Environment);
}
+
if(aCommand.Name.compareToAscii("getPropertyValues") == 0) {
Sequence<Property> Properties;
if(!(aCommand.Argument >>= Properties))
@@ -445,7 +458,7 @@ Any SAL_CALL FTPContent::execute(
aRet <<= IllegalArgumentException();
ucbhelper::cancelCommandExecution(aRet,Environment);
}
- insert(aInsertArgument);
+ insert(aInsertArgument,Environment);
}
else if(aCommand.Name.compareToAscii( "open" ) == 0) {
OpenCommandArgument2 aOpenCommand;
@@ -522,8 +535,11 @@ Any SAL_CALL FTPContent::execute(
action = THROWAUTHENTICATIONREQUEST;
else if(e.code() == CURLE_FTP_ACCESS_DENIED)
action = THROWACCESSDENIED;
+ else if(e.code() == CURLE_FTP_QUOTE_ERROR)
+ action = THROWQUOTE;
else
- break;
+ // nothing known about the course of the error
+ action = THROWGENERAL;
}
return aRet;
@@ -641,21 +657,53 @@ sal_Int32 InsertData::read(sal_Int8 *dest,sal_Int32 nBytesRequested)
}
-void FTPContent::insert(const InsertCommandArgument& aInsertCommand)
+void FTPContent::insert(const InsertCommandArgument& aInsertCommand,
+ const Reference<XCommandEnvironment>& Env)
{
- if(!m_bInserted || (m_aInfo.Type == FTP_FILE && m_bTitleSet)) {
- InsertData data(aInsertCommand.Data);
- m_aFTPURL.insert(bool(aInsertCommand.ReplaceExisting),&data);
- osl::MutexGuard aGuard(m_aMutex);
- m_bInserted = false;
- } else if(m_bInserted && m_aInfo.Type == FTP_FOLDER && m_bTitleSet ) {
- // todo
- // create a folder
- osl::MutexGuard aGuard(m_aMutex);
- m_bInserted = false;
- } else {
+ osl::MutexGuard aGuard(m_aMutex);
+
+ if(m_bInserted && !m_bTitleSet) {
+ MissingPropertiesException excep;
+ excep.Properties.realloc(1);
+ excep.Properties[0] = rtl::OUString::createFromAscii("Title");
+ Any aAny; aAny <<= excep;
+ ucbhelper::cancelCommandExecution(aAny,Env);
+ }
+
+ if(m_bInserted &&
+ m_aInfo.Type == FTP_FILE &&
+ !aInsertCommand.Data.is())
+ {
+ MissingInputStreamException excep;
+ Any aAny; aAny <<= excep;
+ ucbhelper::cancelCommandExecution(aAny,Env);
+ }
+ try {
+ if(m_aInfo.Type == FTP_FILE) {
+ InsertData data(aInsertCommand.Data);
+ m_aFTPURL.insert(bool(aInsertCommand.ReplaceExisting),
+ &data);
+ } else if(m_aInfo.Type == FTP_FOLDER)
+ m_aFTPURL.mkdir(bool(aInsertCommand.ReplaceExisting));
+ } catch(const curl_exception& e) {
+ if(e.code() == FILE_EXIST_DURING_INSERT) {
+ Any aAny;
+ NameClashException excep;
+ excep.Name = m_aFTPURL.child();
+ ucbhelper::cancelCommandExecution(aAny,Env);
+ } else if(e.code() == FOLDER_EXIST_DURING_INSERT) {
+ Any aAny;
+ NameClashException excep;
+ excep.Name = m_aFTPURL.child();
+ ucbhelper::cancelCommandExecution(aAny,Env);
+ } else
+ throw;
}
+
+ // May not be reached, because both mkdir and insert can throw curl-
+ // exceptions
+ m_bInserted = false;
}
diff --git a/ucb/source/ucp/ftp/ftpcontent.hxx b/ucb/source/ucp/ftp/ftpcontent.hxx
index 0170635ab5d9..d32952d9a895 100644
--- a/ucb/source/ucp/ftp/ftpcontent.hxx
+++ b/ucb/source/ucp/ftp/ftpcontent.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpcontent.hxx,v $
*
- * $Revision: 1.8 $
+ * $Revision: 1.9 $
*
- * last change: $Author: abi $ $Date: 2002-10-17 16:28:20 $
+ * last change: $Author: abi $ $Date: 2002-10-21 13:13:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -215,7 +215,9 @@ namespace ftp
const ::com::sun::star::uno::Sequence<
::com::sun::star::beans::PropertyValue>& seqPropVal);
- void insert(const com::sun::star::ucb::InsertCommandArgument&);
+ void insert(const com::sun::star::ucb::InsertCommandArgument&,
+ const com::sun::star::uno::Reference<
+ com::sun::star::ucb::XCommandEnvironment>&);
};
}
diff --git a/ucb/source/ucp/ftp/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx
index c0109a520aa7..3aa97b1fe317 100644
--- a/ucb/source/ucp/ftp/ftpurl.cxx
+++ b/ucb/source/ucp/ftp/ftpurl.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpurl.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: abi $ $Date: 2002-10-17 16:28:22 $
+ * last change: $Author: abi $ $Date: 2002-10-21 13:13:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -312,7 +312,7 @@ rtl::OUString FTPURL::ident(bool withslash,bool internal) const
}
-rtl::OUString FTPURL::parent() const
+rtl::OUString FTPURL::parent(bool internal) const
{
rtl::OUStringBuffer bff;
@@ -328,7 +328,7 @@ rtl::OUString FTPURL::parent() const
aPassword,
aAccount);
- if(m_bShowPassword && aPassword.getLength())
+ if((internal || m_bShowPassword) && aPassword.getLength())
bff.append(sal_Unicode(':'))
.append(aPassword);
@@ -369,6 +369,15 @@ void FTPURL::child(const rtl::OUString& title)
}
+rtl::OUString FTPURL::child() const
+{
+ return
+ m_aPathSegmentVec.size() ?
+ m_aPathSegmentVec.back() : rtl::OUString();
+}
+
+
+
/** Listing of a directory.
*/
@@ -544,9 +553,6 @@ std::vector<FTPDirentry> FTPURL::list(
p1 = p2 + 1;
}
- if(osKind == int(FTP_UNKNOWN))
- throw curl_exception(FTPCouldNotDetermineSystem);
-
return resvec;
}
@@ -677,6 +683,13 @@ extern "C" {
void FTPURL::insert(bool replaceExisting,void* stream) const
throw(curl_exception)
{
+ if(!replaceExisting) {
+ FTPDirentry aDirentry(direntry());
+ if(aDirentry.m_nMode == INETCOREFTP_FILEMODE_UNKNOWN)
+ throw curl_exception(FILE_EXIST_DURING_INSERT);
+ } // else
+ // overwrite is default in libcurl
+
CURL *curl = m_pFCP->handle();
SET_CONTROL_CONTAINER;
@@ -696,3 +709,47 @@ void FTPURL::insert(bool replaceExisting,void* stream) const
if(err != CURLE_OK)
throw curl_exception(err);
}
+
+
+
+void FTPURL::mkdir(bool ReplaceExisting) const
+ throw(curl_exception)
+{
+ rtl::OString title;
+ if(m_aPathSegmentVec.size())
+ title = rtl::OString(m_aPathSegmentVec.back().getStr(),
+ m_aPathSegmentVec.back().getLength(),
+ RTL_TEXTENCODING_UTF8);
+ else
+ // will give an error
+ title = rtl::OString("/");
+
+ rtl::OString del("del "); del += title;
+ rtl::OString mkd("mkd "); mkd += title;
+
+ struct curl_slist *slist = 0;
+
+ FTPDirentry aDirentry(direntry());
+ if(!ReplaceExisting) {
+ if(aDirentry.m_nMode != INETCOREFTP_FILEMODE_UNKNOWN)
+ throw curl_exception(FOLDER_EXIST_DURING_INSERT);
+ } else if(aDirentry.m_nMode != INETCOREFTP_FILEMODE_UNKNOWN)
+ slist = curl_slist_append(slist,del.getStr());
+
+ slist = curl_slist_append(slist,mkd.getStr());
+
+ CURL *curl = m_pFCP->handle();
+ SET_CONTROL_CONTAINER;
+ curl_easy_setopt(curl,CURLOPT_NOBODY,TRUE); // no data => no transfer
+
+ // post request
+ curl_easy_setopt(curl,CURLOPT_POSTQUOTE,slist);
+
+ rtl::OUString url(parent(true));
+ SET_URL(url);
+
+ CURLcode err = curl_easy_perform(curl);
+ curl_slist_free_all(slist);
+ if(err != CURLE_OK)
+ throw curl_exception(err);
+}
diff --git a/ucb/source/ucp/ftp/ftpurl.hxx b/ucb/source/ucp/ftp/ftpurl.hxx
index d526fa215c5b..9327d454fd60 100644
--- a/ucb/source/ucp/ftp/ftpurl.hxx
+++ b/ucb/source/ucp/ftp/ftpurl.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ftpurl.hxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: abi $ $Date: 2002-10-17 16:28:23 $
+ * last change: $Author: abi $ $Date: 2002-10-21 13:13:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -88,10 +88,8 @@ namespace ftp {
class FTPHandleProvider;
-
- enum FTPErrorCode {
- FTPCouldNotDetermineSystem = CURL_LAST + 1
- };
+ enum FTPErrors { FILE_EXIST_DURING_INSERT = CURL_LAST +1,
+ FOLDER_EXIST_DURING_INSERT };
class malformed_exception { };
@@ -151,10 +149,12 @@ namespace ftp {
/** returns the parent url.
*/
- rtl::OUString parent() const;
+ rtl::OUString parent(bool internal = false) const;
void child(const rtl::OUString& title);
+ rtl::OUString child(void) const;
+
std::vector<FTPDirentry> list(sal_Int16 nMode) const
throw(curl_exception);
@@ -167,6 +167,8 @@ namespace ftp {
void insert(bool ReplaceExisting,void* stream) const
throw(curl_exception);
+ void mkdir(bool ReplaceExisting) const
+ throw(curl_exception);
private:
diff --git a/ucb/source/ucp/ftp/test.py b/ucb/source/ucp/ftp/test.py
index 531ca605e498..931d9a3ec8a5 100644
--- a/ucb/source/ucp/ftp/test.py
+++ b/ucb/source/ucp/ftp/test.py
@@ -12,16 +12,14 @@ def grep(pattern,dirname,names):
print filename
break
-def find(regexp,dirName = "."):
- os.path.walk(dirName,grep,re.compile(regexp))
-
+def find(pattern,directory = "."):
+ os.path.walk(directory,grep,re.compile(pattern))
+
+
if __name__ == "__main__":
import sys
- if len(sys.argv) == 3:
- directory = sys.argv[2]
- else:
- directory = "."
-
- dir(sys)
- os.path.walk(directory,grep,re.compile(sys.argv[1]))
+ if len(sys.argv) == 2:
+ find(sys.argv[1])
+ elif len(sys.argv) == 2:
+ find(sys.argv[2],sys.argv[1])