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

Related fdo#46249: FileStatus can have fewer fields than requested

Turns out 608fe962 "Let osl::FileStatus getters
assert programming errors" was overly optimistic and misunderstood that
osl_getFileStatus(..., nMask) /can/ return a FileStatus for which isValid(nMask)
is false, esp. for stuff like file names and URLs of Windows drives and servers.
That in turn leads to existing code now calling
rtl::OUString(_aStatus.ustrFileName) etc. with null argument and crashing.

Change-Id: Icd2168e209aa1c7a6df30cd954513d01034923db
üst 6a92b406
...@@ -731,8 +731,11 @@ public: ...@@ -731,8 +731,11 @@ public:
*/ */
inline Type getFileType() const inline Type getFileType() const
{ {
assert(isValid(osl_FileStatus_Mask_Type)); SAL_INFO_IF(
return static_cast< Type >(_aStatus.eType); !isValid(osl_FileStatus_Mask_Type), "sal",
"no FileStatus Type determined");
return isValid(osl_FileStatus_Mask_Type)
? static_cast< Type >(_aStatus.eType) : Unknown;
} }
/** Is it a directory? /** Is it a directory?
...@@ -785,93 +788,117 @@ public: ...@@ -785,93 +788,117 @@ public:
inline sal_uInt64 getAttributes() const inline sal_uInt64 getAttributes() const
{ {
assert(isValid(osl_FileStatus_Mask_Attributes)); SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_Attributes), "sal",
"no FileStatus Attributes determined");
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. The creation time if this information is valid, an uninitialized
TimeValue otherwise.
*/ */
inline TimeValue getCreationTime() const inline TimeValue getCreationTime() const
{ {
assert(isValid(osl_FileStatus_Mask_CreationTime)); SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_CreationTime), "sal",
"no FileStatus CreationTime determined");
return _aStatus.aCreationTime; return _aStatus.aCreationTime;
} }
/** Get the file access time. /** Get the file access time.
@return @return
The last access time. The last access time if this information is valid, an uninitialized
TimeValue otherwise.
*/ */
inline TimeValue getAccessTime() const inline TimeValue getAccessTime() const
{ {
assert(isValid(osl_FileStatus_Mask_AccessTime)); SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_AccessTime), "sal",
"no FileStatus AccessTime determined");
return _aStatus.aAccessTime; return _aStatus.aAccessTime;
} }
/** Get the file modification time. /** Get the file modification time.
@return @return
The last modified time. The last modified time if this information is valid, an uninitialized
TimeValue otherwise.
*/ */
inline TimeValue getModifyTime() const inline TimeValue getModifyTime() const
{ {
assert(isValid(osl_FileStatus_Mask_ModifyTime)); SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_ModifyTime), "sal",
"no FileStatus ModifyTime determined");
return _aStatus.aModifyTime; return _aStatus.aModifyTime;
} }
/** Get the size of the file. /** Get the size of the file.
@return @return
The actual file size. The actual file size if this information is valid, 0 otherwise.
*/ */
inline sal_uInt64 getFileSize() const inline sal_uInt64 getFileSize() const
{ {
assert(isValid(osl_FileStatus_Mask_FileSize)); SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_FileSize), "sal",
"no FileStatus FileSize determined");
return _aStatus.uFileSize; return _aStatus.uFileSize;
} }
/** Get the file name. /** Get the file name.
@return @return
The file name. The file name if this information is valid, an empty string otherwise.
*/ */
inline ::rtl::OUString getFileName() const inline ::rtl::OUString getFileName() const
{ {
assert(isValid(osl_FileStatus_Mask_FileName)); SAL_INFO_IF(
return rtl::OUString(_aStatus.ustrFileName); !isValid(osl_FileStatus_Mask_FileName), "sal",
"no FileStatus FileName determined");
return isValid(osl_FileStatus_Mask_FileName)
? rtl::OUString(_aStatus.ustrFileName) : rtl::OUString();
} }
/** Get the URL of the file. /** Get the URL of the file.
@return @return
The full qualified URL of the file. The full qualified URL of the file if this information is valid, an
empty string otherwise.
*/ */
inline ::rtl::OUString getFileURL() const inline ::rtl::OUString getFileURL() const
{ {
assert(isValid(osl_FileStatus_Mask_FileURL)); SAL_INFO_IF(
return rtl::OUString(_aStatus.ustrFileURL); !isValid(osl_FileStatus_Mask_FileURL), "sal",
"no FileStatus FileURL determined");
return isValid(osl_FileStatus_Mask_FileURL)
? rtl::OUString(_aStatus.ustrFileURL) : rtl::OUString();
} }
/** Get the link target URL. /** Get the link target URL.
@return @return
The link target URL. The link target URL if this information is valid, an empty string
otherwise.
*/ */
inline ::rtl::OUString getLinkTargetURL() const inline ::rtl::OUString getLinkTargetURL() const
{ {
assert(isValid(osl_FileStatus_Mask_LinkTargetURL)); SAL_INFO_IF(
return rtl::OUString(_aStatus.ustrLinkTargetURL); !isValid(osl_FileStatus_Mask_LinkTargetURL), "sal",
"no FileStatus LinkTargetURL determined");
return isValid(osl_FileStatus_Mask_LinkTargetURL)
? rtl::OUString(_aStatus.ustrLinkTargetURL) : rtl::OUString();
} }
friend class DirectoryItem; friend class DirectoryItem;
......
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