diff options
author | Michael Meeks <michael.meeks@suse.com> | 2012-03-19 16:31:36 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-03-19 16:31:36 +0100 |
commit | c6e22c0fc0cc4ce1508f8401c4b0c14fc89df942 (patch) | |
tree | 9bbb51ad374dc1e8754f85f8024436d24179f115 | |
parent | b234cf6e5478120bc1e8c66b2b91de0387774b0c (diff) |
fdo#40607 - osl_syncFile having written, and avoid doing that on start
Combinded cherry-pick of master d3192948fe968fc4d6a8ec0e6fda232f265b3c4c
plus subsequent fixes bee742eb7a0d5dfe23e61d9ee49a29286de90256 "Fix sense
of r/o detection code, and clean up" and
61eeb689d7605a23c3e71c652b57ee65cf5b28dc "fix smoketest - need to check
read-only-ness of non-existent paths."
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | desktop/source/deployment/manager/dp_manager.cxx | 84 | ||||
-rw-r--r-- | ucb/source/ucp/file/shell.cxx | 4 |
2 files changed, 48 insertions, 40 deletions
diff --git a/desktop/source/deployment/manager/dp_manager.cxx b/desktop/source/deployment/manager/dp_manager.cxx index 508d6bb45707..19117ab2b15e 100644 --- a/desktop/source/deployment/manager/dp_manager.cxx +++ b/desktop/source/deployment/manager/dp_manager.cxx @@ -32,6 +32,7 @@ #include "dp_platform.hxx" #include "dp_manager.h" #include "dp_identifier.hxx" +#include "rtl/oustringostreaminserter.hxx" #include "rtl/ustrbuf.hxx" #include "rtl/string.hxx" #include "rtl/uri.hxx" @@ -312,6 +313,42 @@ void PackageManagerImpl::initRegistryBackends() m_xComponentContext ) ); } +// this overcomes previous rumours that the sal API is misleading +// as to whether a directory is truly read-only or not +static bool isMacroURLReadOnly( const OUString &rMacro ) +{ + rtl::OUString aDirURL( rMacro ); + ::rtl::Bootstrap::expandMacros( aDirURL ); + + ::osl::FileBase::RC aErr = ::osl::Directory::create( aDirURL ); + if ( aErr == ::osl::FileBase::E_None ) + return false; // it will be writeable + if ( aErr != ::osl::FileBase::E_EXIST ) + return true; // some serious problem creating it + + bool bError; + sal_uInt64 nWritten = 0; + rtl::OUString aFileURL( + aDirURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/stamp.sys")) ); + ::osl::File aFile( aFileURL ); + + bError = aFile.open( osl_File_OpenFlag_Read | + osl_File_OpenFlag_Write | + osl_File_OpenFlag_Create ) != ::osl::FileBase::E_None; + if (!bError) + bError = aFile.write( "1", 1, nWritten ) != ::osl::FileBase::E_None; + if (aFile.close() != ::osl::FileBase::E_None) + bError = true; + if (osl::File::remove( aFileURL ) != ::osl::FileBase::E_None) + bError = true; + + SAL_INFO( + "desktop.deployment", + "local url '" << rMacro << "' -> '" << aFileURL << "' " + << (bError ? "is" : "is not") << " readonly\n"); + return bError; +} + //______________________________________________________________________________ Reference<deployment::XPackageManager> PackageManagerImpl::create( Reference<XComponentContext> const & xComponentContext, @@ -321,7 +358,7 @@ Reference<deployment::XPackageManager> PackageManagerImpl::create( xComponentContext, context ); Reference<deployment::XPackageManager> xPackageManager( that ); - OUString packages, logFile, stampURL; + OUString packages, logFile, stamp; if (context.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("user") )) { that->m_activePackages = OUSTR( "vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages"); @@ -342,8 +379,7 @@ Reference<deployment::XPackageManager> PackageManagerImpl::create( //using virtualization it appears that he/she can. Then a shared extension can //be installed but is only visible for the user (because the extension is in //the virtual store). - stampURL = OUSTR( - "vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/stamp.sys"); + stamp = OUSTR("$UNO_USER_PACKAGES_CACHE"); } else if (context.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("shared") )) { that->m_activePackages = OUSTR( @@ -354,8 +390,7 @@ Reference<deployment::XPackageManager> PackageManagerImpl::create( "vnd.sun.star.expand:$SHARED_EXTENSIONS_USER/registry"); logFile = OUSTR( "vnd.sun.star.expand:$SHARED_EXTENSIONS_USER/log.txt"); - stampURL = OUSTR( - "vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE/stamp.sys"); + stamp = OUSTR("$UNO_SHARED_PACKAGES_CACHE"); } else if (context.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bundled") )) { that->m_activePackages = OUSTR( @@ -394,8 +429,7 @@ Reference<deployment::XPackageManager> PackageManagerImpl::create( "vnd.sun.star.expand:$TMP_EXTENSIONS"); that->m_registryCache = OUSTR( "vnd.sun.star.expand:$TMP_EXTENSIONS/registry"); - stampURL = OUSTR( - "vnd.sun.star.expand:$TMP_EXTENSIONS/stamp.sys"); + stamp = OUSTR("$TMP_EXTENSIONS"); } else if (! context.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.tdoc:/") )) { @@ -407,39 +441,9 @@ Reference<deployment::XPackageManager> PackageManagerImpl::create( Reference<XCommandEnvironment> xCmdEnv; try { - //There is no stampURL for the bundled folder - if (stampURL.getLength() > 0) - { -#define CURRENT_STAMP "1" - try { - //The osl file API does not allow to find out if one can write - //into a folder. Therefore we try to write a file. Then we delete - //it, so that it does not hinder uninstallation of OOo - // probe writing: - ::ucbhelper::Content ucbStamp( stampURL, xCmdEnv ); - ::rtl::OString stamp( - RTL_CONSTASCII_STRINGPARAM(CURRENT_STAMP) ); - Reference<io::XInputStream> xData( - ::xmlscript::createInputStream( - ::rtl::ByteSequence( - reinterpret_cast<sal_Int8 const *>(stamp.getStr()), - stamp.getLength() ) ) ); - ucbStamp.writeStream( xData, true /* replace existing */ ); - that->m_readOnly = false; - erase_path( stampURL, xCmdEnv ); - } - catch (const RuntimeException &) { - try { - erase_path( stampURL, xCmdEnv ); - } catch (...) - { - } - throw; - } - catch (const Exception &) { - that->m_readOnly = true; - } - } + // There is no stamp for the bundled folder: + if (!stamp.isEmpty()) + that->m_readOnly = isMacroURLReadOnly( stamp ); if (!that->m_readOnly && logFile.getLength() > 0) { diff --git a/ucb/source/ucp/file/shell.cxx b/ucb/source/ucp/file/shell.cxx index fcc238be7623..1cd150535f60 100644 --- a/ucb/source/ucp/file/shell.cxx +++ b/ucb/source/ucp/file/shell.cxx @@ -1913,6 +1913,10 @@ shell::write( sal_Int32 CommandId, } } while( nReadBytes == nRequestedBytes ); + aFile.sync(); // fsync / flush it to disk. + OSL_TRACE( "fsync'd file '%s'\n", + rtl::OUStringToOString( aUnqPath, RTL_TEXTENCODING_UTF8 ).getStr() ); + err = aFile.close(); if( err != osl::FileBase::E_None ) { |