Anonymous avatar Anonymous committed e9bdd04

mav58: #i114850# handle the medium without URL correctly

Comments (0)

Files changed (1)

sfx2/source/doc/docfile.cxx

     // returns true if the document can be opened for editing ( even if it should be a copy )
     // otherwise the document should be opened readonly
     // if user cancel the loading the ERROR_ABORT is set
-
-    if ( pImp->m_bOwnLockSet && bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
+    sal_Bool bResult = sal_False;
+
+    if ( !GetURLObject().HasError() ) try
     {
-        // if the document is already locked the system locking might be temporarely off after storing
-        // check whether the system file locking should be taken again
-        GetLockingStream_Impl();
-    }
-
-    sal_Bool bResult = pImp->m_bOwnLockSet || pImp->m_bUCBLockSet;
-
-    if ( !bResult )
-    {
-        // no read-write access is necessary on loading if the document is explicitly opened as copy
-        SFX_ITEMSET_ARG( GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
-        bResult = ( bLoading && pTemplateItem && pTemplateItem->GetValue() );
-    }
-
-    if ( !bResult && !IsReadOnly() )
-    {
-        sal_Bool bContentReadonly = sal_False;
-        Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv;
-        ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
-
-        if ( bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
+        if ( pImp->m_bOwnLockSet && bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
         {
-            // let the original document be opened to check the possibility to open it for editing
-            // and to let the writable stream stay open to hold the lock on the document
+            // if the document is already locked the system locking might be temporarely off after storing
+            // check whether the system file locking should be taken again
             GetLockingStream_Impl();
         }
 
-        // "IsReadOnly" property does not allow to detect whether the file is readonly always
-        // so we try always to open the file for editing
-        // the file is readonly only in case the read-write stream can not be opened
-        if ( bLoading && !pImp->m_xLockingStream.is() )
+        bResult = pImp->m_bOwnLockSet || pImp->m_bUCBLockSet;
+
+        if ( !bResult )
         {
-            try
+            // no read-write access is necessary on loading if the document is explicitly opened as copy
+            SFX_ITEMSET_ARG( GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
+            bResult = ( bLoading && pTemplateItem && pTemplateItem->GetValue() );
+        }
+
+        if ( !bResult && !IsReadOnly() )
+        {
+            sal_Bool bContentReadonly = sal_False;
+            Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv;
+            ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
+
+            if ( bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) )
             {
-                // MediaDescriptor does this check also, the duplication should be avoided in future
-                aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bContentReadonly;
+                // let the original document be opened to check the possibility to open it for editing
+                // and to let the writable stream stay open to hold the lock on the document
+                GetLockingStream_Impl();
             }
-            catch( uno::Exception )
-            {}
-
+
+            // "IsReadOnly" property does not allow to detect whether the file is readonly always
+            // so we try always to open the file for editing
+            // the file is readonly only in case the read-write stream can not be opened
+            if ( bLoading && !pImp->m_xLockingStream.is() )
+            {
+                try
+                {
+                    // MediaDescriptor does this check also, the duplication should be avoided in future
+                    aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bContentReadonly;
+                }
+                catch( uno::Exception )
+                {}
+
+                if ( !bContentReadonly )
+                {
+                    // the file is not readonly, check the ACL
+
+                    String aPhysPath;
+                    if ( ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aPhysPath ) )
+                        bContentReadonly = IsReadonlyAccordingACL( aPhysPath.GetBuffer() );
+                }
+            }
+
+            // do further checks only if the file not readonly in fs
             if ( !bContentReadonly )
             {
-                // the file is not readonly, check the ACL
-
-                String aPhysPath;
-                if ( ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aPhysPath ) )
-                    bContentReadonly = IsReadonlyAccordingACL( aPhysPath.GetBuffer() );
-            }
-        }
-
-        // do further checks only if the file not readonly in fs
-        if ( !bContentReadonly )
-        {
-            // the special file locking should be used only for file URLs
-            if ( ::utl::LocalFileHelper::IsLocalFile( aLogicName ) )
-            {
-
-                // in case of storing the document should request the output before locking
-                if ( bLoading )
+                // the special file locking should be used only for file URLs
+                if ( ::utl::LocalFileHelper::IsLocalFile( aLogicName ) )
                 {
-                    // let the stream be opened to check the system file locking
-                    GetMedium_Impl();
+
+                    // in case of storing the document should request the output before locking
+                    if ( bLoading )
+                    {
+                        // let the stream be opened to check the system file locking
+                        GetMedium_Impl();
+                    }
+
+                    sal_Int8 nUIStatus = LOCK_UI_NOLOCK;
+
+                    // check whether system file locking has been used, the default value is false
+                    sal_Bool bUseSystemLock = IsSystemFileLockingUsed();
+
+                    // TODO/LATER: This implementation does not allow to detect the system lock on saving here, actually this is no big problem
+                    // if system lock is used the writeable stream should be available
+                    sal_Bool bHandleSysLocked = ( bLoading && bUseSystemLock && !pImp->xStream.is() && !pOutStream );
+
+                    do
+                    {
+                        nUIStatus = LockIterationImpl( bHandleSysLocked, bUseSystemLock, bLoading, bNoUI );
+                        bHandleSysLocked = sal_False;
+                    } while( !bResult && nUIStatus == LOCK_UI_TRY );
+                    
+                    if ( nUIStatus == LOCK_UI_SUCCEEDED )
+                        bResult = sal_True;
+
+                    pImp->m_bOwnLockSet = bResult;
                 }
-
-                sal_Int8 nUIStatus = LOCK_UI_NOLOCK;
-
-                // check whether system file locking has been used, the default value is false
-                sal_Bool bUseSystemLock = IsSystemFileLockingUsed();
-
-                // TODO/LATER: This implementation does not allow to detect the system lock on saving here, actually this is no big problem
-                // if system lock is used the writeable stream should be available
-                sal_Bool bHandleSysLocked = ( bLoading && bUseSystemLock && !pImp->xStream.is() && !pOutStream );
-
-                do
+                else
                 {
-                    nUIStatus = LockIterationImpl( bHandleSysLocked, bUseSystemLock, bLoading, bNoUI );
-                    bHandleSysLocked = sal_False;
-                } while( !bResult && nUIStatus == LOCK_UI_TRY );
-                
-                if ( nUIStatus == LOCK_UI_SUCCEEDED )
-                    bResult = sal_True;
-
-                pImp->m_bOwnLockSet = bResult;
-            }
-            else
-            {
-                // this is no file URL, check whether the file is readonly
-                bResult = !bContentReadonly;
-                if ( bResult )
-                {
-                    try
+                    // this is no file URL, check whether the file is readonly
+                    bResult = !bContentReadonly;
+                    if ( bResult )
                     {
-                        aContent.executeCommand( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lock" ) ), uno::Any() );
-                        pImp->m_bUCBLockSet = sal_True;
+                        try
+                        {
+                            aContent.executeCommand( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lock" ) ), uno::Any() );
+                            pImp->m_bUCBLockSet = sal_True;
+                        }
+                        catch( ucb::InteractiveLockingLockedException& )
+                        {
+                            bResult = sal_False;
+                            uno::Sequence< ::rtl::OUString > aData;
+
+                            if ( !bNoUI )
+                            {
+                                sal_Int8 nUIStatus = ShowLockedDocumentDialog( aData, bLoading, sal_False );
+                                bResult = ( nUIStatus == LOCK_UI_SUCCEEDED );
+                            }
+                        }
+                        catch( uno::Exception& )
+                        {}
                     }
-                    catch( ucb::InteractiveLockingLockedException& )
-                    {
-                        bResult = sal_False;
-                        uno::Sequence< ::rtl::OUString > aData;
-
-                        if ( !bNoUI )
-                        {
-                            sal_Int8 nUIStatus = ShowLockedDocumentDialog( aData, bLoading, sal_False );
-                            bResult = ( nUIStatus == LOCK_UI_SUCCEEDED );
-                        }
-                    }
-                    catch( uno::Exception& )
-                    {}
                 }
             }
         }
+
+        if ( !bResult && GetError() == ERRCODE_NONE )
+        {
+            // the error should be set in case it is storing process
+            // or the document has been opened for editing explicitly
+
+            SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
+            if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) )
+                SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
+            else
+                GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+        }
+
+        // when the file is locked, get the current file date
+        if ( bResult && DocNeedsFileDateCheck() )
+            GetInitFileDate( sal_True );
     }
-
-    if ( !bResult && GetError() == ERRCODE_NONE )
+    catch( uno::Exception& )
     {
-        // the error should be set in case it is storing process
-        // or the document has been opened for editing explicitly
-
-        SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
-        if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) )
-            SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
-        else
-            GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
+        OSL_ENSURE( sal_False, "Unexpected problem by locking, high probability, that the content could not be created" );
     }
 
-    // when the file is locked, get the current file date
-    if ( bResult && DocNeedsFileDateCheck() )
-        GetInitFileDate( sal_True );
-
     return bResult;
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.