diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-08-21 12:27:12 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-08-21 12:39:43 +0200 |
commit | e9febb63db2f62cd2b9505dfc4ceb3accc32aecb (patch) | |
tree | 5c802434402920ab212b132e9a23306dce328ac1 /sal | |
parent | 6a92b406b03e8bbce27fe314b6229644b9fc8b0e (diff) |
Related fdo#46249: FileStatus can have fewer fields than requested
Turns out 608fe962cc649ad62c489811d3a8666e0e06e5e7 "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
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/osl/file.hxx | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/sal/inc/osl/file.hxx b/sal/inc/osl/file.hxx index 431685a5cc1d..3d541a98e539 100644 --- a/sal/inc/osl/file.hxx +++ b/sal/inc/osl/file.hxx @@ -731,8 +731,11 @@ public: */ inline Type getFileType() const { - assert(isValid(osl_FileStatus_Mask_Type)); - return static_cast< Type >(_aStatus.eType); + SAL_INFO_IF( + !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? @@ -785,93 +788,117 @@ public: 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; } /** Get the creation time of this file. @return - The creation time. + The creation time if this information is valid, an uninitialized + TimeValue otherwise. */ 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; } /** Get the file access time. @return - The last access time. + The last access time if this information is valid, an uninitialized + TimeValue otherwise. */ 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; } /** Get the file modification time. @return - The last modified time. + The last modified time if this information is valid, an uninitialized + TimeValue otherwise. */ 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; } /** Get the size of the file. @return - The actual file size. + The actual file size if this information is valid, 0 otherwise. */ 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; } /** Get the file name. @return - The file name. + The file name if this information is valid, an empty string otherwise. */ inline ::rtl::OUString getFileName() const { - assert(isValid(osl_FileStatus_Mask_FileName)); - return rtl::OUString(_aStatus.ustrFileName); + SAL_INFO_IF( + !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. @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 { - assert(isValid(osl_FileStatus_Mask_FileURL)); - return rtl::OUString(_aStatus.ustrFileURL); + SAL_INFO_IF( + !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. @return - The link target URL. + The link target URL if this information is valid, an empty string + otherwise. */ inline ::rtl::OUString getLinkTargetURL() const { - assert(isValid(osl_FileStatus_Mask_LinkTargetURL)); - return rtl::OUString(_aStatus.ustrLinkTargetURL); + SAL_INFO_IF( + !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; |