From 41747b75076e4446947873b3edc2abe3e3c4ebd1 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 29 Apr 2019 11:45:46 +0200 Subject: tdf#123472: Propagate getGFileInfo failure less aggressively ...from Content::getPropertyValues. ca0308797df86ebece19260f3ca438a0cb437208 "tdf#121337: Fail on GIO error in GIO UCP getPropertyValue" had made Content::getPropertyValues fail for every getGFileInfo failure. However, when saving to a not-yet exisiting file, SfxMedium::Transfer_Impl (sfx2/source/doc/docfile.cxx) requests the properties "Title" and "ObjectId" from the Content representing the not-yet existing file, and apparently expects those requests not to fail. So restructure Content::getPropertyValues to only call getGFileInfo when actually needed (that covers not failing for the unknown- anyway "ObjecdtId" property), and handle "Title" specially by not failing for a non-existing file. (The documentation at offapi/com/sun/star/ucb/Content.idl says for the "getPropertyValues" command that: "The execution will not be aborted, if there are properties requested, that are unknown to the content." But that leaves it somewhat unclear whether failure to obtain a known property should be propagated. It apparently should be in the context of tfd#121337 fixed previously, but apparently not for "Title" here.) Change-Id: I12a9a5bd93d661922ea3b7b19a84a7e73e7e4b50 Reviewed-on: https://gerrit.libreoffice.org/71515 Tested-by: Jenkins Reviewed-by: Stephan Bergmann (cherry picked from commit 6d3dd64391e67e6cfe406dea047e13227ea94c4b) Reviewed-on: https://gerrit.libreoffice.org/71525 Reviewed-by: Michael Stahl --- ucb/source/ucp/gio/gio_content.cxx | 52 +++++++++++++++++++++++++------------- ucb/source/ucp/gio/gio_content.hxx | 9 +++---- 2 files changed, 38 insertions(+), 23 deletions(-) (limited to 'ucb/source') diff --git a/ucb/source/ucp/gio/gio_content.cxx b/ucb/source/ucp/gio/gio_content.cxx index a581c34adb2a..a40576801424 100644 --- a/ucb/source/ucp/gio/gio_content.cxx +++ b/ucb/source/ucp/gio/gio_content.cxx @@ -425,12 +425,11 @@ static util::DateTime getDateFromUnix (time_t t) return util::DateTime(); } -uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo *pInfo, - const uno::Reference< uno::XComponentContext >& rxContext, - const uno::Reference< ucb::XCommandEnvironment > & xEnv, - const uno::Sequence< beans::Property >& rProperties) +uno::Reference< sdbc::XRow > Content::getPropertyValues( + const uno::Sequence< beans::Property >& rProperties, + const uno::Reference< ucb::XCommandEnvironment >& xEnv ) { - rtl::Reference< ::ucbhelper::PropertyValueSet > xRow = new ::ucbhelper::PropertyValueSet( rxContext ); + rtl::Reference< ::ucbhelper::PropertyValueSet > xRow = new ::ucbhelper::PropertyValueSet( m_xContext ); sal_Int32 nProps; const beans::Property* pProps; @@ -438,12 +437,14 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * nProps = rProperties.getLength(); pProps = rProperties.getConstArray(); + GFileInfo *pInfo = nullptr; for( sal_Int32 n = 0; n < nProps; ++n ) { const beans::Property& rProp = pProps[ n ]; if ( rProp.Name == "IsDocument" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE)) xRow->appendBoolean( rProp, ( g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_REGULAR || g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_UNKNOWN ) ); @@ -452,6 +453,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "IsFolder" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE) ) xRow->appendBoolean( rProp, ( g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_DIRECTORY )); else @@ -459,6 +461,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "Title" ) { + getFileInfo(xEnv, &pInfo, false); if (pInfo != nullptr && g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME)) { const char *pName = g_file_info_get_display_name(pInfo); @@ -469,6 +472,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "IsReadOnly" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE ) ) xRow->appendBoolean( rProp, !g_file_info_get_attribute_boolean( pInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) ); else @@ -476,6 +480,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "DateCreated" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_TIME_CREATED ) ) xRow->appendTimestamp( rProp, getDateFromUnix(g_file_info_get_attribute_uint64(pInfo, G_FILE_ATTRIBUTE_TIME_CREATED)) ); else @@ -483,6 +488,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "DateModified" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_TIME_CHANGED ) ) xRow->appendTimestamp( rProp, getDateFromUnix(g_file_info_get_attribute_uint64(pInfo, G_FILE_ATTRIBUTE_TIME_CHANGED)) ); else @@ -490,6 +496,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "Size" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE) ) xRow->appendLong( rProp, ( g_file_info_get_size( pInfo ) )); else @@ -502,6 +509,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "IsCompactDisc" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT ) ) xRow->appendBoolean( rProp, g_file_info_get_attribute_boolean(pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT) ); else @@ -509,6 +517,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "IsRemoveable" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT ) ) xRow->appendBoolean( rProp, g_file_info_get_attribute_boolean(pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT ) ); else @@ -520,6 +529,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * } else if ( rProp.Name == "IsHidden" ) { + getFileInfo(xEnv, &pInfo, true); if (pInfo != nullptr && g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) ) xRow->appendBoolean( rProp, ( g_file_info_get_is_hidden ( pInfo ) ) ); else @@ -540,19 +550,6 @@ uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo * return uno::Reference< sdbc::XRow >( xRow.get() ); } -uno::Reference< sdbc::XRow > Content::getPropertyValues( - const uno::Sequence< beans::Property >& rProperties, - const uno::Reference< ucb::XCommandEnvironment >& xEnv ) -{ - GError * err = nullptr; - GFileInfo *pInfo = getGFileInfo(xEnv, &err); - if (pInfo == nullptr && !mbTransient) { - ucbhelper::cancelCommandExecution(mapGIOError(err), xEnv); - } - assert(err == nullptr); - return getPropertyValuesFromGFileInfo(pInfo, m_xContext, xEnv, rProperties); -} - static lang::IllegalAccessException getReadOnlyException( const uno::Reference< uno::XInterface >& rContext ) { @@ -640,6 +637,25 @@ bool Content::exchangeIdentity( const uno::Reference< ucb::XContentIdentifier >& return false; } +void Content::getFileInfo( + css::uno::Reference const & env, GFileInfo ** info, bool fail) +{ + assert(info != nullptr); + if (*info == nullptr) + { + GError * err = nullptr; + *info = getGFileInfo(env, &err); + if (*info == nullptr && !mbTransient && fail) + { + ucbhelper::cancelCommandExecution(mapGIOError(err), env); + } + else if (err != nullptr) + { + g_error_free(err); + } + } +} + uno::Sequence< uno::Any > Content::setPropertyValues( const uno::Sequence< beans::PropertyValue >& rValues, const uno::Reference< ucb::XCommandEnvironment >& xEnv ) diff --git a/ucb/source/ucp/gio/gio_content.hxx b/ucb/source/ucp/gio/gio_content.hxx index a60ae47a738c..8ba80fc4d53f 100644 --- a/ucb/source/ucp/gio/gio_content.hxx +++ b/ucb/source/ucp/gio/gio_content.hxx @@ -116,6 +116,10 @@ private: bool exchangeIdentity(const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId); + void getFileInfo( + css::uno::Reference const & env, GFileInfo ** info, + bool fail); + public: /// @throws css::ucb::ContentCreationException Content( const css::uno::Reference< @@ -130,11 +134,6 @@ public: virtual ~Content() override; - css::uno::Reference< css::sdbc::XRow > getPropertyValuesFromGFileInfo( - GFileInfo *pInfo, const css::uno::Reference< css::uno::XComponentContext >& rxContext, - const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv, - const css::uno::Sequence< css::beans::Property >& rProperties); - virtual css::uno::Sequence< css::beans::Property > getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override; -- cgit