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 20:29:20 +0100
commit748abfdd6104b0023fe545f8ea380f8af4fc892d (patch)
tree6f06b1036ddd085385b15c32e9448f5911f95ed3 /sfx2
parent1dca41d2ff8d5f23738b061fd5f02fec785e21bd (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> (cherry picked from commit e5dc12d37bfea357aeb6f71e876dd4f93833d1c9)
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 d9a090d7c4db..7e2bbc973443 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>
@@ -122,6 +123,8 @@
#include "sfxacldetect.hxx"
#include <officecfg/Office/Common.hxx>
+#include <com/sun/star/io/WrongFormatException.hpp>
+
#include <memory>
using namespace ::com::sun::star;
@@ -844,12 +847,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
@@ -943,6 +946,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)
@@ -1038,7 +1086,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& )
@@ -1179,59 +1227,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
@@ -1239,46 +1262,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& )
@@ -2780,13 +2811,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& )
{}
}