Kaydet (Commit) 608fe962 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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 4a086fca "fix SvStream to not require a
custom open or lstat method."
üst f3f6c9be
...@@ -29,14 +29,16 @@ ...@@ -29,14 +29,16 @@
#ifndef _OSL_FILE_HXX_ #ifndef _OSL_FILE_HXX_
#define _OSL_FILE_HXX_ #define _OSL_FILE_HXX_
#ifdef __cplusplus #include "sal/config.h"
#include <cassert>
#include <osl/time.h> #include <osl/time.h>
# include <rtl/memory.h> #include <rtl/memory.h>
# include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <osl/file.h> #include <osl/file.h>
# include <rtl/byteseq.hxx> #include <rtl/byteseq.hxx>
#include <stdio.h> #include <stdio.h>
...@@ -723,11 +725,12 @@ public: ...@@ -723,11 +725,12 @@ public:
/** Get the file type. /** Get the file type.
@return @return
The file type if this information is valid, Unknown otherwise. The file type.
*/ */
inline Type getFileType() const 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? /** Is it a file?
...@@ -796,88 +799,93 @@ public: ...@@ -796,88 +799,93 @@ public:
inline sal_uInt64 getAttributes() const inline sal_uInt64 getAttributes() const
{ {
assert(isValid(osl_FileStatus_Mask_Attributes));
return _aStatus.uAttributes; return _aStatus.uAttributes;
} }
/** Get the creation time of this file. /** Get the creation time of this file.
@return @return
The creation time if this information is valid, The creation time.
an uninitialized TimeValue otherwise.
*/ */
inline TimeValue getCreationTime() const inline TimeValue getCreationTime() const
{ {
assert(isValid(osl_FileStatus_Mask_CreationTime));
return _aStatus.aCreationTime; return _aStatus.aCreationTime;
} }
/** Get the file access time. /** Get the file access time.
@return @return
The last access time if this information is valid, The last access time.
an uninitialized TimeValue otherwise.
*/ */
inline TimeValue getAccessTime() const inline TimeValue getAccessTime() const
{ {
assert(isValid(osl_FileStatus_Mask_AccessTime));
return _aStatus.aAccessTime; return _aStatus.aAccessTime;
} }
/** Get the file modification time. /** Get the file modification time.
@return @return
The last modified time if this information is valid, The last modified time.
an uninitialized TimeValue otherwise.
*/ */
inline TimeValue getModifyTime() const inline TimeValue getModifyTime() const
{ {
assert(isValid(osl_FileStatus_Mask_ModifyTime));
return _aStatus.aModifyTime; return _aStatus.aModifyTime;
} }
/** Get the size of the file. /** Get the size of the file.
@return @return
The actual file size if this information is valid, 0 otherwise. The actual file size.
*/ */
inline sal_uInt64 getFileSize() const inline sal_uInt64 getFileSize() const
{ {
assert(isValid(osl_FileStatus_Mask_FileSize));
return _aStatus.uFileSize; return _aStatus.uFileSize;
} }
/** Get the file name. /** Get the file name.
@return @return
The file name if this information is valid, an empty string otherwise. The file name.
*/ */
inline ::rtl::OUString getFileName() const 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. /** Get the URL of the file.
@return @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 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. /** Get the link target URL.
@return @return
The link target URL if this information is valid, an empty string otherwise. The link target URL.
*/ */
inline ::rtl::OUString getLinkTargetURL() const 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; friend class DirectoryItem;
...@@ -1947,7 +1955,6 @@ public: ...@@ -1947,7 +1955,6 @@ public:
} /* namespace osl */ } /* namespace osl */
#endif /* __cplusplus */
#endif /* _OSL_FILE_HXX_ */ #endif /* _OSL_FILE_HXX_ */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -628,8 +628,8 @@ void SvFileStream::Open( const String& rFilename, StreamMode nOpenMode ) ...@@ -628,8 +628,8 @@ void SvFileStream::Open( const String& rFilename, StreamMode nOpenMode )
// FIXME: we really need to switch to a pure URL model ... // FIXME: we really need to switch to a pure URL model ...
if ( osl::File::getFileURLFromSystemPath( aFilename, aFileURL ) != osl::FileBase::E_None ) if ( osl::File::getFileURLFromSystemPath( aFilename, aFileURL ) != osl::FileBase::E_None )
aFileURL = aFilename; aFileURL = aFilename;
bool bStatValid = ( osl::DirectoryItem::get( aFileURL, aItem) != osl::FileBase::E_None && bool bStatValid = ( osl::DirectoryItem::get( aFileURL, aItem) == osl::FileBase::E_None &&
aItem.getFileStatus( aStatus ) != osl::FileBase::E_None ); aItem.getFileStatus( aStatus ) == osl::FileBase::E_None );
// SvFileStream can't open a directory // SvFileStream can't open a directory
if( bStatValid && aStatus.getFileType() == osl::FileStatus::Directory ) if( bStatValid && aStatus.getFileType() == osl::FileStatus::Directory )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment