summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-04-27 11:35:55 +0200
committerCaolán McNamara <caolanm@redhat.com>2015-04-30 08:34:22 +0000
commit9ad420fba51ee539ecf4a6cedc224e1025632f5f (patch)
treed007e6f6b8619a8d2a39b0bc4cdaa0925acf034f
parent08ce53b292066ed732a00212d19893b4be80beb5 (diff)
tdf#65498, tdf#87545: Don't confuse logically r/o doc with physically r/o
b9ecec7c74687ed5a9470cffb7d02e0e6e83107e "Allow for editing of read-only documents" introduced "A new state of 'IsOriginallyReadOnly' needed to be added to the medium, to keep track whether the medium was originally opened r/o (and is thus assumed to be physically r/o), as toggling SID_EDITDOC in the view also changes the open mode of the underlying medium. Instead of trying to fully understand and disentangle that horrible mess, I just added yet another state to the mess..." But that heuristic is apparently too simplistic, as it treats documents originally opened "logically r/o" (via --view command line argument, or by checking the corresponding checkbox in the Open dialog) as "physically r/o" too, which leads to unexpected behavior when such documents are later switched into r/w Edit mode. An approach that hopefully works better overall is to set IsOriginallyReadOnly only if the document originally is r/o as reported by OSL (for a document with a file URL). Change-Id: I32d5ec655d7556a70680aee55feda4c6eea7795f (cherry picked from commit a199cad8376a5470c50125def2738b44b55ec018) Reviewed-on: https://gerrit.libreoffice.org/15549 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sfx2/source/doc/docfile.cxx20
1 files changed, 15 insertions, 5 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 711cbc74d98b..43d822adec60 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -1001,9 +1001,6 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
bContentReadonly = IsReadonlyAccordingACL( aPhysPath.getStr() );
}
#endif
-
- if ( bContentReadonly )
- pImp->m_bOriginallyReadOnly = true;
}
// do further checks only if the file not readonly in fs
@@ -2468,6 +2465,18 @@ void SfxMedium::Init_Impl()
}
SetIsRemote_Impl();
+
+ osl::DirectoryItem item;
+ if (osl::DirectoryItem::get(GetName(), item) == osl::FileBase::E_None) {
+ osl::FileStatus stat(osl_FileStatus_Mask_Attributes);
+ if (item.getFileStatus(stat) == osl::FileBase::E_None
+ && stat.isValid(osl_FileStatus_Mask_Attributes))
+ {
+ if ((stat.getAttributes() & osl_File_Attribute_ReadOnly) != 0) {
+ pImp->m_bOriginallyReadOnly = true;
+ }
+ }
+ }
}
@@ -2865,14 +2874,15 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) :
}
}
+ bool readOnly = false;
SFX_ITEMSET_ARG( pImp->m_pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, false );
if ( pReadOnlyItem && pReadOnlyItem->GetValue() )
- pImp->m_bOriginallyReadOnly = true;
+ readOnly = true;
SFX_ITEMSET_ARG( pImp->m_pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, false );
if (!pFileNameItem) throw uno::RuntimeException();
pImp->m_aLogicName = pFileNameItem->GetValue();
- pImp->m_nStorOpenMode = pImp->m_bOriginallyReadOnly ? SFX_STREAM_READONLY : SFX_STREAM_READWRITE;
+ pImp->m_nStorOpenMode = readOnly ? SFX_STREAM_READONLY : SFX_STREAM_READWRITE;
Init_Impl();
}