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 @@
#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: */
......@@ -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 )
......
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