[PATCH 7/9] HelpIndexer: use OSL for directory access

Gert van Valkenhoef g.h.m.van.valkenhoef at rug.nl
Sun Feb 19 08:21:19 PST 2012


---
 l10ntools/source/help/HelpIndexer.cxx |   38 ++++++++++++--------------------
 1 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/l10ntools/source/help/HelpIndexer.cxx b/l10ntools/source/help/HelpIndexer.cxx
index 793348b..a3ab752 100644
--- a/l10ntools/source/help/HelpIndexer.cxx
+++ b/l10ntools/source/help/HelpIndexer.cxx
@@ -8,12 +8,7 @@
 #endif
 
 #include <rtl/string.hxx>
-
-#include <unistd.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <errno.h>
-#include <string.h>
+#include <osl/file.hxx>
 
 #include <algorithm>
 
@@ -77,27 +72,20 @@ bool HelpIndexer::scanForFiles() {
 }
 
 bool HelpIndexer::scanForFiles(rtl::OUString const & path) {
-	rtl::OString pathStr;
-	path.convertToString(&pathStr, RTL_TEXTENCODING_ASCII_US, 0);
-	DIR *dir = opendir(pathStr.getStr());
-	if (dir == 0) {
-		d_error = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Error reading directory ")) + path +
-			 rtl::OUString::createFromAscii(strerror(errno));
+	osl::Directory dir(path);
+	if (osl::FileBase::E_None != dir.open()) {
+		d_error = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Error reading directory ")) + path;
 		return true;
 	}
 
-	struct dirent *ent;
-	struct stat info;
-	while ((ent = readdir(dir)) != 0) {
-		rtl::OString entPath(pathStr);
-		entPath += rtl::OString(RTL_CONSTASCII_STRINGPARAM("/")) + rtl::OString(ent->d_name);
-		if (stat(entPath.getStr(), &info) == 0 && S_ISREG(info.st_mode)) {
-			d_files.insert(rtl::OUString::createFromAscii(ent->d_name));
+	osl::DirectoryItem item;
+	osl::FileStatus fileStatus(osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Type);
+	while (dir.getNextItem(item) == osl::FileBase::E_None) {
+		if (fileStatus.getFileType() == osl::FileStatus::Regular) {
+			d_files.insert(fileStatus.getFileName());
 		}
 	}
 
-	closedir(dir);
-
 	return true;
 }
 
@@ -121,9 +109,11 @@ bool HelpIndexer::helpDocument(rtl::OUString const & fileName, Document *doc) {
 }
 
 lucene::util::Reader *HelpIndexer::helpFileReader(rtl::OUString const & path) {
-	rtl::OString pathStr;
-	path.convertToString(&pathStr, RTL_TEXTENCODING_ASCII_US, 0);
-	if (access(pathStr.getStr(), R_OK) == 0) {
+	osl::File file(path);
+	if (osl::FileBase::E_None == file.open(osl_File_OpenFlag_Read)) {
+		file.close();
+		rtl::OString pathStr;
+		path.convertToString(&pathStr, RTL_TEXTENCODING_ASCII_US, 0); // FIXME: path encoding?
 		return new lucene::util::FileReader(pathStr.getStr(), "UTF-8");
 	} else {
 		return new lucene::util::StringReader(L"");
-- 
1.7.0.4


--------------010002010906020500040707
Content-Type: text/x-patch;
 name="0008-Bugfix-resultsetforquery.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0008-Bugfix-resultsetforquery.patch"



More information about the LibreOffice mailing list