[Libreoffice-commits] core.git: ucb/qa ucb/source

Giuseppe Castagno giuseppe.castagno at acca-esse.eu
Fri Jul 29 16:38:40 UTC 2016


 ucb/qa/cppunit/webdav/webdav_options.cxx     |    8 ++++++++
 ucb/source/ucp/webdav-neon/DAVTypes.cxx      |    3 +++
 ucb/source/ucp/webdav-neon/DAVTypes.hxx      |    7 +++++++
 ucb/source/ucp/webdav-neon/NeonSession.cxx   |   12 ++++++++++++
 ucb/source/ucp/webdav-neon/webdavcontent.cxx |   26 +++++++++++++++++++++++++-
 5 files changed, 55 insertions(+), 1 deletion(-)

New commits:
commit dfb714183f31d8a235797ef1ad3c517966ed4985
Author: Giuseppe Castagno <giuseppe.castagno at acca-esse.eu>
Date:   Sun Jul 24 12:12:35 2016 +0200

    tdf#101094 (13) OPTIONS: Options cache removal: LOCK, UNLOCK
    
    Change-Id: Ib5e52973252b3af7b0fbe440806eb1e669670299
    Reviewed-on: https://gerrit.libreoffice.org/27686
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Giuseppe Castagno <giuseppe.castagno at acca-esse.eu>

diff --git a/ucb/qa/cppunit/webdav/webdav_options.cxx b/ucb/qa/cppunit/webdav/webdav_options.cxx
index 7c0ec7b..6c89623 100644
--- a/ucb/qa/cppunit/webdav/webdav_options.cxx
+++ b/ucb/qa/cppunit/webdav/webdav_options.cxx
@@ -58,6 +58,7 @@ namespace
         CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass1() );
         CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass2() );
         CPPUNIT_ASSERT_EQUAL( false, aDavType.isClass3() );
+        CPPUNIT_ASSERT_EQUAL( false, aDavType.isLocked() );
         CPPUNIT_ASSERT_EQUAL( true, aDavType.getAllowedMethods().isEmpty() );
         CPPUNIT_ASSERT_EQUAL( false, aDavType.isLockAllowed() );
         CPPUNIT_ASSERT_EQUAL( true, aDavType.getURL().isEmpty() );
@@ -191,6 +192,7 @@ namespace
         CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass1() );
         CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass2() );
         CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isClass3() );
+        CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLocked() );
         CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getAllowedMethods().isEmpty() );
         CPPUNIT_ASSERT_EQUAL( false, aDavOpt.isLockAllowed() );
         CPPUNIT_ASSERT_EQUAL( true, aDavOpt.getURL().isEmpty() );
@@ -204,6 +206,7 @@ namespace
         aDavOpt.setClass1();
         aDavOpt.setClass2();
         aDavOpt.setClass3();
+        aDavOpt.setLocked();
         aDavOpt.setAllowedMethods( aAllowedMethods );
         aDavOpt.setStaleTime( 1234567 );
         aDavOpt.setURL( aURL );
@@ -230,6 +233,11 @@ namespace
         aDavOpt.setClass3( false );
         CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget );
 
+        aDavOpt.setLocked();
+        CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget );
+        aDavOpt.setLocked( false );
+        CPPUNIT_ASSERT_EQUAL( true , aDavOpt == aDavOptTarget );
+
         aDavOpt.setResourceFound();
         CPPUNIT_ASSERT_EQUAL( false , aDavOpt == aDavOptTarget );
         aDavOpt.setResourceFound( false );
diff --git a/ucb/source/ucp/webdav-neon/DAVTypes.cxx b/ucb/source/ucp/webdav-neon/DAVTypes.cxx
index c0eb4ea..2f4feb3 100644
--- a/ucb/source/ucp/webdav-neon/DAVTypes.cxx
+++ b/ucb/source/ucp/webdav-neon/DAVTypes.cxx
@@ -24,6 +24,7 @@ DAVOptions::DAVOptions() :
     m_isClass1( false ),
     m_isClass2( false ),
     m_isClass3( false ),
+    m_isLocked( false ),
     m_aAllowedMethods(),
     m_nStaleTime( 0 ),
     m_sURL(),
@@ -37,6 +38,7 @@ DAVOptions::DAVOptions( const DAVOptions & rOther ) :
     m_isClass1( rOther.m_isClass1 ),
     m_isClass2( rOther.m_isClass2 ),
     m_isClass3( rOther.m_isClass3 ),
+    m_isLocked( rOther.m_isLocked ),
     m_aAllowedMethods( rOther.m_aAllowedMethods ),
     m_nStaleTime( rOther.m_nStaleTime ),
     m_sURL( rOther.m_sURL ),
@@ -57,6 +59,7 @@ bool DAVOptions::operator==( const DAVOptions& rOpts ) const
         m_isClass1 == rOpts.m_isClass1 &&
         m_isClass2 == rOpts.m_isClass2 &&
         m_isClass3 == rOpts.m_isClass3 &&
+        m_isLocked == rOpts.m_isLocked &&
         m_aAllowedMethods == rOpts.m_aAllowedMethods &&
         m_nStaleTime == rOpts.m_nStaleTime &&
         m_sURL == rOpts.m_sURL &&
diff --git a/ucb/source/ucp/webdav-neon/DAVTypes.hxx b/ucb/source/ucp/webdav-neon/DAVTypes.hxx
index f9bbb1f..6dbdd20 100644
--- a/ucb/source/ucp/webdav-neon/DAVTypes.hxx
+++ b/ucb/source/ucp/webdav-neon/DAVTypes.hxx
@@ -81,6 +81,9 @@ namespace webdav_ucp
         bool    m_isClass1;
         bool    m_isClass2;
         bool    m_isClass3;
+        // Internally used to maintain locked stated of the resource, only
+        // if it's a Class 2 resource
+        bool    m_isLocked;
         // contains the methods allowed on this resource
         OUString    m_aAllowedMethods;
 
@@ -122,11 +125,15 @@ namespace webdav_ucp
         bool isLockAllowed() { return ( m_aAllowedMethods.indexOf( "LOCK" ) != -1 ); };
         bool isUnlockAllowed() { return ( m_aAllowedMethods.indexOf( "UNLOCK" ) != -1 ); };
 
+        void setLocked( bool locked = true ) { m_isLocked = locked; } ;
+        bool isLocked() { return m_isLocked; };
+
         void reset() {
             m_isResourceFound = false;
             m_isClass1 = false;
             m_isClass2 = false;
             m_isClass3 = false;
+            m_isLocked = false;
             m_aAllowedMethods.clear();
             m_nStaleTime = 0;
             m_sURL.clear();
diff --git a/ucb/source/ucp/webdav-neon/NeonSession.cxx b/ucb/source/ucp/webdav-neon/NeonSession.cxx
index 9d9741b..084e5da 100644
--- a/ucb/source/ucp/webdav-neon/NeonSession.cxx
+++ b/ucb/source/ucp/webdav-neon/NeonSession.cxx
@@ -939,6 +939,18 @@ void NeonSession::OPTIONS( const OUString & inPath,
             }
         }
         rOptions.setResourceFound();
+        // if applicable, check for lock state:
+        if( rOptions.isClass2() || rOptions.isClass3() )
+        {
+            //dav with lock possible, check for locked state
+            if ( m_aNeonLockStore.findByUri(
+                     makeAbsoluteURL( inPath ) ) != nullptr )
+            {
+                // we own a lock for this URL,
+                // set locked state
+                rOptions.setLocked();
+            }
+        }
     }
 
     ne_request_destroy(req);
diff --git a/ucb/source/ucp/webdav-neon/webdavcontent.cxx b/ucb/source/ucp/webdav-neon/webdavcontent.cxx
index 78a09b9..81c015c 100644
--- a/ucb/source/ucp/webdav-neon/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-neon/webdavcontent.cxx
@@ -3035,6 +3035,8 @@ void Content::lock(
         aURL = m_xIdentifier->getContentIdentifier();
     }
 
+    OUString    aTargetUrl = aURL;
+
     try
     {
         std::unique_ptr< DAVResourceAccess > xResAccess;
@@ -3056,7 +3058,12 @@ void Content::lock(
             //-1, // infinite lock
             uno::Sequence< OUString >() );
 
+        //  update the URL
+        aTargetUrl = xResAccess->getURL();
+
         xResAccess->LOCK( aLock, Environment );
+        // OPTIONS may have changed as a consequence of the lock operation
+        aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl );
 
         {
             osl::Guard< osl::Mutex > aGuard( m_aMutex );
@@ -3065,6 +3072,7 @@ void Content::lock(
     }
     catch ( DAVException const & e )
     {
+        aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl );
         // check if the exception thrown is 'already locked'
         // this exception is mapped directly to the ucb correct one, without
         // going into the cancelCommandExecution() user interaction
@@ -3161,6 +3169,9 @@ void Content::unlock(
         const uno::Reference< ucb::XCommandEnvironment >& Environment )
     throw( uno::Exception, std::exception )
 {
+    // save the URL to clean cache
+    OUString    aTargetUrl = m_xIdentifier->getContentIdentifier();
+
     try
     {
         std::unique_ptr< DAVResourceAccess > xResAccess;
@@ -3169,7 +3180,12 @@ void Content::unlock(
             xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
         }
 
+        // update the URL
+        aTargetUrl = xResAccess->getURL();
         xResAccess->UNLOCK( Environment );
+        // remove options from cache, unlock may change it
+        // it will be refreshed when needed
+        aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl );
 
         {
             osl::Guard< osl::Mutex > aGuard( m_aMutex );
@@ -3208,6 +3224,9 @@ void Content::unlock(
                 }
                 break;
             default:
+                // remove options from cache,
+                // it will be refreshed when needed
+                aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl );
                 //fallthrough
                 ;
         }
@@ -3714,7 +3733,12 @@ void Content::getResourceOptions(
                                      rDAVOptions.isClass3() ) ?
                 m_nOptsCacheLifeDAV : // a WebDAV site
                 m_nOptsCacheLifeImplWeb;  // a site implementing OPTIONS but
-                                             // it's not DAV
+                                          // it's not DAV
+            // if resource is locked, will use a
+            // different lifetime
+            if( rDAVOptions.isLocked() )
+                nLifeTime = m_nOptsCacheLifeDAVLocked;
+
             // check if redirected
             aRedirURL = rResAccess->getURL();
             if( aRedirURL == aTargetURL)


More information about the Libreoffice-commits mailing list