sal/inc/osl/file.hxx | 47 ++++++++++++++++++++++------------------ tools/source/stream/strmunx.cxx | 4 +-- 2 files changed, 29 insertions(+), 22 deletions(-)
New commits: commit 608fe962cc649ad62c489811d3a8666e0e06e5e7 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Mar 9 11:52:09 2012 +0100 Let osl::FileStatus getters assert programming errors ...instead of arbitrarily returning certain values when the requested information is not available. This reveals a problem in strmunx.cxx that is apparently a regression introduced with 4a086fca7b0a77c20bc9f1c97507966e2861f3da "fix SvStream to not require a custom open or lstat method." diff --git a/sal/inc/osl/file.hxx b/sal/inc/osl/file.hxx index ee3ac1f..2cc43d0 100644 --- a/sal/inc/osl/file.hxx +++ b/sal/inc/osl/file.hxx @@ -29,14 +29,16 @@ #ifndef _OSL_FILE_HXX_ #define _OSL_FILE_HXX_ -#ifdef __cplusplus +#include "sal/config.h" + +#include <cassert> #include <osl/time.h> -# include <rtl/memory.h> -# include <rtl/ustring.hxx> +#include <rtl/memory.h> +#include <rtl/ustring.hxx> #include <osl/file.h> -# include <rtl/byteseq.hxx> +#include <rtl/byteseq.hxx> #include <stdio.h> @@ -723,11 +725,12 @@ public: /** Get the file type. @return - The file type if this information is valid, Unknown otherwise. + The file type. */ inline Type getFileType() const { - return (_aStatus.uValidFields & osl_FileStatus_Mask_Type) ? (Type) _aStatus.eType : Unknown; + assert(isValid(osl_FileStatus_Mask_Type)); + return static_cast< Type >(_aStatus.eType); } /** Is it a file? @@ -796,88 +799,93 @@ public: inline sal_uInt64 getAttributes() const { + assert(isValid(osl_FileStatus_Mask_Attributes)); return _aStatus.uAttributes; } /** Get the creation time of this file. @return - The creation time if this information is valid, - an uninitialized TimeValue otherwise. + The creation time. */ inline TimeValue getCreationTime() const { + assert(isValid(osl_FileStatus_Mask_CreationTime)); return _aStatus.aCreationTime; } /** Get the file access time. @return - The last access time if this information is valid, - an uninitialized TimeValue otherwise. + The last access time. */ inline TimeValue getAccessTime() const { + assert(isValid(osl_FileStatus_Mask_AccessTime)); return _aStatus.aAccessTime; } /** Get the file modification time. @return - The last modified time if this information is valid, - an uninitialized TimeValue otherwise. + The last modified time. */ inline TimeValue getModifyTime() const { + assert(isValid(osl_FileStatus_Mask_ModifyTime)); return _aStatus.aModifyTime; } /** Get the size of the file. @return - The actual file size if this information is valid, 0 otherwise. + The actual file size. */ inline sal_uInt64 getFileSize() const { + assert(isValid(osl_FileStatus_Mask_FileSize)); return _aStatus.uFileSize; } /** Get the file name. @return - The file name if this information is valid, an empty string otherwise. + The file name. */ inline ::rtl::OUString getFileName() const { - return _aStatus.ustrFileName ? ::rtl::OUString(_aStatus.ustrFileName) : ::rtl::OUString(); + assert(isValid(osl_FileStatus_Mask_FileName)); + return rtl::OUString(_aStatus.ustrFileName); } /** Get the URL of the file. @return - The full qualified URL of the file if this information is valid, an empty string otherwise. + The full qualified URL of the file. */ inline ::rtl::OUString getFileURL() const { - return _aStatus.ustrFileURL ? ::rtl::OUString(_aStatus.ustrFileURL) : ::rtl::OUString(); + assert(isValid(osl_FileStatus_Mask_FileURL)); + return rtl::OUString(_aStatus.ustrFileURL); } /** Get the link target URL. @return - The link target URL if this information is valid, an empty string otherwise. + The link target URL. */ inline ::rtl::OUString getLinkTargetURL() const { - return _aStatus.ustrLinkTargetURL ? ::rtl::OUString(_aStatus.ustrLinkTargetURL) : ::rtl::OUString(); + assert(isValid(osl_FileStatus_Mask_LinkTargetURL)); + return rtl::OUString(_aStatus.ustrLinkTargetURL); } friend class DirectoryItem; @@ -1947,7 +1955,6 @@ public: } /* namespace osl */ -#endif /* __cplusplus */ #endif /* _OSL_FILE_HXX_ */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx index cb55ddc..2317120 100644 --- a/tools/source/stream/strmunx.cxx +++ b/tools/source/stream/strmunx.cxx @@ -628,8 +628,8 @@ void SvFileStream::Open( const String& rFilename, StreamMode nOpenMode ) // FIXME: we really need to switch to a pure URL model ... if ( osl::File::getFileURLFromSystemPath( aFilename, aFileURL ) != osl::FileBase::E_None ) aFileURL = aFilename; - bool bStatValid = ( osl::DirectoryItem::get( aFileURL, aItem) != osl::FileBase::E_None && - aItem.getFileStatus( aStatus ) != osl::FileBase::E_None ); + bool bStatValid = ( osl::DirectoryItem::get( aFileURL, aItem) == osl::FileBase::E_None && + aItem.getFileStatus( aStatus ) == osl::FileBase::E_None ); // SvFileStream can't open a directory if( bStatValid && aStatus.getFileType() == osl::FileStatus::Directory ) _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits