summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorJuergen Funk <juergen.funk_ml@cib.de>2017-04-12 11:26:10 +0200
committerAron Budea <aron.budea@collabora.com>2018-02-09 15:43:31 +0100
commite5dc12d37bfea357aeb6f71e876dd4f93833d1c9 (patch)
tree370febacc9fd5343662f7546cf5f24d74ee8a80a /sfx2
parent532e9f751b1ec40588b7edf0de156377eed79287 (diff)
tdf#106942 Wrong message when lock file is empty or corrupt
1. Erase empty or corrupt lockfile, when reading it fails and skip "Locked Document Dialog" in that case 2. Show Dialog (use LockFileIgnoreRequest -> LockFailedQueryBox) when create lock file is not possible. Two Dialogs: "lock file create error" and "empty lockfile is present" Set the document to read-only when creating lockfile is not possible. If lockfile is corrupt or empty, inform the user. They can interrupt loading the document or open it read-only, which also erases the corrupt lock file after closing the document 3. Handling for the two Dialogs Use LockFileIgnoreRequst for create lockfile error and add a new LockFileCorruptRequest, (lock file is corrupt). Change and generate new messages for both dialogs in english Change-Id: I35c377f85b5113e8ffb89d83b9544b8ebc81d89f Reviewed-on: https://gerrit.libreoffice.org/36658 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de> Reviewed-on: https://gerrit.libreoffice.org/49468 Reviewed-by: Aron Budea <aron.budea@collabora.com> Tested-by: Aron Budea <aron.budea@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/docfile.cxx148
1 files changed, 95 insertions, 53 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 68f85eff772c..431f9d2e78dc 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -31,6 +31,7 @@
#include <com/sun/star/document/LockedDocumentRequest.hpp>
#include <com/sun/star/document/OwnLockOnDocumentRequest.hpp>
#include <com/sun/star/document/LockFileIgnoreRequest.hpp>
+#include <com/sun/star/document/LockFileCorruptRequest.hpp>
#include <com/sun/star/document/ChangedByOthersRequest.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
@@ -123,6 +124,8 @@
#include <officecfg/Office/Common.hxx>
#include <comphelper/propertysequence.hxx>
+#include <com/sun/star/io/WrongFormatException.hpp>
+
#include <memory>
using namespace ::com::sun::star;
@@ -846,12 +849,12 @@ void SfxMedium::SetEncryptionDataToStorage_Impl()
// not for some URL scheme belongs in UCB, not here.
-SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEntry& aData, bool bIsLoading, bool bOwnLock )
+SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEntry& aData, bool bIsLoading, bool bOwnLock, bool bHandleSysLocked )
{
ShowLockResult nResult = ShowLockResult::NoLock;
- // tdf#92817: Simple check for empty lock file that needs to be deleted
- if( aData[LockFileComponent::OOOUSERNAME].isEmpty() && aData[LockFileComponent::SYSUSERNAME].isEmpty() )
+ // tdf#92817: Simple check for empty lock file that needs to be deleted, when system locking is enabled
+ if( aData[LockFileComponent::OOOUSERNAME].isEmpty() && aData[LockFileComponent::SYSUSERNAME].isEmpty() && !bHandleSysLocked )
bOwnLock=true;
// show the interaction regarding the document opening
@@ -945,6 +948,51 @@ SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEnt
return nResult;
}
+
+bool SfxMedium::ShowLockFileProblemDialog(MessageDlg nWhichDlg)
+{
+ // system file locking is not active, ask user whether he wants to open the document without any locking
+ uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler();
+
+ if (xHandler.is())
+ {
+ ::rtl::Reference< ::ucbhelper::InteractionRequest > xIgnoreRequestImpl;
+
+ switch (nWhichDlg)
+ {
+ case MessageDlg::LockFileIgnore:
+ xIgnoreRequestImpl = new ::ucbhelper::InteractionRequest(uno::makeAny( document::LockFileIgnoreRequest() ));
+ break;
+ case MessageDlg::LockFileCorrupt:
+ xIgnoreRequestImpl = new ::ucbhelper::InteractionRequest(uno::makeAny( document::LockFileCorruptRequest() ));
+ break;
+ }
+
+ uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations(2);
+ aContinuations[0] = new ::ucbhelper::InteractionAbort(xIgnoreRequestImpl.get());
+ aContinuations[1] = new ::ucbhelper::InteractionApprove(xIgnoreRequestImpl.get());
+ xIgnoreRequestImpl->setContinuations(aContinuations);
+
+ xHandler->handle(xIgnoreRequestImpl.get());
+
+ ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xIgnoreRequestImpl->getSelection();
+ bool bReadOnly = uno::Reference< task::XInteractionApprove >(xSelected.get(), uno::UNO_QUERY).is();
+
+ if (bReadOnly)
+ {
+ GetItemSet()->Put(SfxBoolItem(SID_DOC_READONLY, true));
+ }
+ else
+ {
+ SetError( ERRCODE_ABORT, OSL_LOG_PREFIX );
+ }
+
+ return bReadOnly;
+ }
+
+ return false;
+}
+
namespace
{
bool isSuitableProtocolForLocking(const OUString & rLogicName)
@@ -1040,7 +1088,7 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
if ( !bResult && !bNoUI )
{
- bUIStatus = ShowLockedDocumentDialog( aLockData, bLoading, false );
+ bUIStatus = ShowLockedDocumentDialog( aLockData, bLoading, false , false );
}
}
catch( ucb::InteractiveNetworkWriteException& )
@@ -1181,59 +1229,34 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
try
{
::svt::DocumentLockFile aLockFile( pImpl->m_aLogicName );
- if ( !bHandleSysLocked )
+ bool bIoErr = false;
+
+ if (!bHandleSysLocked)
{
try
{
bResult = aLockFile.CreateOwnLockFile();
}
- catch ( const ucb::InteractiveIOException& e )
+ catch (const ucb::InteractiveIOException&)
{
- // exception means that the lock file can not be successfully accessed
- // in this case it should be ignored if system file locking is anyway active
- if ( bUseSystemLock || !IsOOoLockFileUsed() )
+ if (bLoading && !bNoUI)
{
- bResult = true;
- // take the ownership over the lock file
- aLockFile.OverwriteOwnLockFile();
- }
- else if ( e.Code == IOErrorCode_INVALID_PARAMETER )
- {
- // system file locking is not active, ask user whether he wants to open the document without any locking
- uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler();
-
- if ( xHandler.is() )
- {
- ::rtl::Reference< ::ucbhelper::InteractionRequest > xIgnoreRequestImpl
- = new ::ucbhelper::InteractionRequest( uno::makeAny( document::LockFileIgnoreRequest() ) );
-
- uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 );
- aContinuations[0] = new ::ucbhelper::InteractionAbort( xIgnoreRequestImpl.get() );
- aContinuations[1] = new ::ucbhelper::InteractionApprove( xIgnoreRequestImpl.get() );
- xIgnoreRequestImpl->setContinuations( aContinuations );
-
- xHandler->handle( xIgnoreRequestImpl.get() );
-
- ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xIgnoreRequestImpl->getSelection();
- bResult = uno::Reference< task::XInteractionApprove >( xSelected.get(), uno::UNO_QUERY ).is();
- }
+ bIoErr = true;
+ bResult = ShowLockFileProblemDialog(MessageDlg::LockFileIgnore);
}
}
- catch ( const uno::Exception& )
+ catch (const uno::Exception&)
{
- // exception means that the lock file can not be successfully accessed
- // in this case it should be ignored if system file locking is anyway active
- if ( bUseSystemLock || !IsOOoLockFileUsed() )
+ if (bLoading && !bNoUI)
{
- bResult = true;
- // take the ownership over the lock file
- aLockFile.OverwriteOwnLockFile();
+ bIoErr = true;
+ bResult = ShowLockFileProblemDialog(MessageDlg::LockFileIgnore);
}
}
// in case OOo locking is turned off the lock file is still written if possible
// but it is ignored while deciding whether the document should be opened for editing or not
- if ( !bResult && !IsOOoLockFileUsed() )
+ if (!bResult && !IsOOoLockFileUsed() && !bIoErr)
{
bResult = true;
// take the ownership over the lock file
@@ -1241,46 +1264,54 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
}
}
-
if ( !bResult )
{
LockFileEntry aData;
try
{
- // impossibility to get data is no real problem
aData = aLockFile.GetLockData();
}
+ catch (const io::WrongFormatException&)
+ {
+ // we get empty or corrupt data
+ // info to the user
+ if (!bIoErr && bLoading && !bNoUI )
+ bResult = ShowLockFileProblemDialog(MessageDlg::LockFileCorrupt);
+
+ // not show the Lock Document Dialog
+ bIoErr = true;
+ }
catch( const uno::Exception& )
{
+ // show the Lock Document Dialog, when locked from other app
+ bIoErr = !bHandleSysLocked;
}
bool bOwnLock = false;
- if ( !bHandleSysLocked )
+ if (!bHandleSysLocked)
{
LockFileEntry aOwnData = svt::LockFileCommon::GenerateOwnEntry();
- bOwnLock = aOwnData[LockFileComponent::SYSUSERNAME].equals( aData[LockFileComponent::SYSUSERNAME] );
+ bOwnLock = aOwnData[LockFileComponent::SYSUSERNAME].equals(aData[LockFileComponent::SYSUSERNAME]);
- if ( bOwnLock
- && aOwnData[LockFileComponent::LOCALHOST].equals( aData[LockFileComponent::LOCALHOST] )
- && aOwnData[LockFileComponent::USERURL].equals( aData[LockFileComponent::USERURL] ) )
+ if (bOwnLock
+ && aOwnData[LockFileComponent::LOCALHOST].equals(aData[LockFileComponent::LOCALHOST])
+ && aOwnData[LockFileComponent::USERURL].equals(aData[LockFileComponent::USERURL]))
{
// this is own lock from the same installation, it could remain because of crash
bResult = true;
}
}
- if ( !bResult && !bNoUI )
+ if ( !bResult && !bNoUI && !bIoErr)
{
- bUIStatus = ShowLockedDocumentDialog( aData, bLoading, bOwnLock );
+ bUIStatus = ShowLockedDocumentDialog( aData, bLoading, bOwnLock, bHandleSysLocked );
if ( bUIStatus == ShowLockResult::Succeeded )
{
// take the ownership over the lock file
bResult = aLockFile.OverwriteOwnLockFile();
}
}
-
- bHandleSysLocked = false;
}
}
catch( const uno::Exception& )
@@ -2798,13 +2829,24 @@ void SfxMedium::UnlockFile( bool bReleaseLockStream )
if ( pImpl->m_bLocked )
{
+ ::svt::DocumentLockFile aLockFile( pImpl->m_aLogicName );
+
try
{
pImpl->m_bLocked = false;
- ::svt::DocumentLockFile aLockFile( pImpl->m_aLogicName );
// TODO/LATER: A warning could be shown in case the file is not the own one
aLockFile.RemoveFile();
}
+ catch( const io::WrongFormatException& )
+ {
+ try
+ {
+ // erase the empty or corrupt file
+ aLockFile.RemoveFileDirectly();
+ }
+ catch( const uno::Exception& )
+ {}
+ }
catch( const uno::Exception& )
{}
}