[Libreoffice-commits] core.git: vcl/source

Tobias Lippert drtl at fastmail.fm
Mon Jul 21 01:13:22 PDT 2014


 vcl/source/app/IconThemeScanner.cxx |   68 ++++++++++++++++++++++--------------
 1 file changed, 43 insertions(+), 25 deletions(-)

New commits:
commit 60954a8a96a66ff11e06b850838f3d16e8e1625f
Author: Tobias Lippert <drtl at fastmail.fm>
Date:   Sat Jul 19 13:39:21 2014 +0200

    fdo#81532 Handle symlinks to icon themes correctly
    
    - added logging for icon theme scanning.
    
    Change-Id: I799c5fc09879411020142f7808da0d9f2f63dc17
    Reviewed-on: https://gerrit.libreoffice.org/10406
    Tested-by: Rene Engelhard <rene at debian.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/app/IconThemeScanner.cxx b/vcl/source/app/IconThemeScanner.cxx
index 9684bb6..29d3cd7 100644
--- a/vcl/source/app/IconThemeScanner.cxx
+++ b/vcl/source/app/IconThemeScanner.cxx
@@ -12,6 +12,7 @@
 #include <config_folders.h>
 #include <osl/file.hxx>
 #include <rtl/bootstrap.hxx>
+#include <salhelper/linkhelper.hxx>
 
 #include <vcl/svapp.hxx>
 #include <vcl/IconThemeInfo.hxx>
@@ -20,24 +21,34 @@ namespace vcl {
 
 namespace {
 
-bool
-search_path_is_valid(const OUString& dir)
+const char *LOG_AREA = "vcl.app";
+
+// set the status of a file. Returns false if the status could not be determined.
+bool set_file_status(osl::FileStatus& status, const OUString& file)
 {
     osl::DirectoryItem dirItem;
-    osl::FileBase::RC retvalGet = osl::DirectoryItem::get(dir, dirItem);
+    osl::FileBase::RC retvalGet = osl::DirectoryItem::get(file, dirItem);
     if (retvalGet != osl::FileBase::E_None) {
+        SAL_WARN(LOG_AREA, "Could not determine status for file '" << file << "'.");
         return false;
     }
-    osl::FileStatus fileStatus(osl_FileStatus_Mask_Type);
-    osl::FileBase::RC retvalStatus = dirItem.getFileStatus(fileStatus);
+    osl::FileBase::RC retvalStatus = dirItem.getFileStatus(status);
     if (retvalStatus != osl::FileBase::E_None) {
+        SAL_WARN(LOG_AREA, "Could not determine status for file '" << file << "'.");
         return false;
     }
+    return true;
+}
 
-    if (!fileStatus.isDirectory()) {
-        return false;
+OUString convert_to_absolute_path(const OUString& path)
+{
+    salhelper::LinkResolver resolver(0);
+    osl::FileBase::RC rc = resolver.fetchFileStatus(path);
+    if (rc != osl::FileBase::E_None) {
+        SAL_WARN(LOG_AREA, "Could not resolve path '" << path << "' to search for icon themes.");
+        throw std::runtime_error("Provided a recursive symlink to a icon theme directory that could not be resolved.");
     }
-    return true;
+    return resolver.m_aStatus.getFileURL();
 }
 
 }
@@ -48,12 +59,20 @@ IconThemeScanner::IconThemeScanner()
 bool
 IconThemeScanner::ScanDirectoryForIconThemes(const OUString& path)
 {
-    bool pathIsValid = search_path_is_valid(path);
-    if (!pathIsValid) {
+    osl::FileStatus fileStatus(osl_FileStatus_Mask_Type);
+    bool couldSetFileStatus = set_file_status(fileStatus, path);
+    if (!couldSetFileStatus) {
+        return false;
+    }
+
+    if (!fileStatus.isDirectory()) {
+        SAL_INFO(LOG_AREA, "Cannot search for icon themes in '"<< path << "'. It is not a directory.");
         return false;
     }
+
     std::vector<OUString> iconThemePaths = ReadIconThemesFromPath(path);
     if (iconThemePaths.empty()) {
+        SAL_WARN(LOG_AREA, "Could not find any icon themes in the provided directory ('" <<path<<"'.");
         return false;
     }
     mFoundIconThemes.clear();
@@ -70,8 +89,11 @@ IconThemeScanner::AddIconThemeByPath(const OUString &url)
     if (!IconThemeInfo::UrlCanBeParsed(url)) {
         return false;
     }
+    SAL_INFO(LOG_AREA, "Found a file that seems to be an icon theme: '" << url << "'" );
     IconThemeInfo newTheme(url);
     mFoundIconThemes.push_back(newTheme);
+    SAL_INFO(LOG_AREA, "Adding the file as '" << newTheme.GetDisplayName() <<
+            "' with id '" << newTheme.GetThemeId() << "'.");
     return true;
 }
 
@@ -79,6 +101,7 @@ IconThemeScanner::AddIconThemeByPath(const OUString &url)
 IconThemeScanner::ReadIconThemesFromPath(const OUString& dir)
 {
     std::vector<OUString> found;
+    SAL_INFO(LOG_AREA, "Scanning directory '" << dir << " for icon themes.");
 
     osl::Directory dirToScan(dir);
     osl::FileBase::RC retvalOpen = dirToScan.open();
@@ -93,15 +116,12 @@ IconThemeScanner::ReadIconThemesFromPath(const OUString& dir)
         if (retvalStatus != osl::FileBase::E_None) {
             continue;
         }
-        if (!status.isRegular()) {
-            continue;
-        }
-        if (!FileIsValidIconTheme(status.getFileURL())) {
+
+        OUString filename = convert_to_absolute_path(status.getFileURL());
+        if (!FileIsValidIconTheme(filename)) {
             continue;
         }
-        OUString entry;
-        entry = status.getFileURL();
-        found.push_back(entry);
+        found.push_back(filename);
     }
     return found;
 }
@@ -111,20 +131,16 @@ IconThemeScanner::FileIsValidIconTheme(const OUString& filename)
 {
     // check whether we can construct a IconThemeInfo from it
     if (!IconThemeInfo::UrlCanBeParsed(filename)) {
+        SAL_INFO(LOG_AREA, "File '" << filename << "' does not seem to be an icon theme.");
         return false;
     }
 
-    // check whether the file is a regular file
-    osl::DirectoryItem dirItem;
-    osl::FileBase::RC retvalGet = osl::DirectoryItem::get(filename, dirItem);
-    if (retvalGet != osl::FileBase::E_None) {
-        return false;
-    }
     osl::FileStatus fileStatus(osl_FileStatus_Mask_Type);
-    osl::FileBase::RC retvalStatus = dirItem.getFileStatus(fileStatus);
-    if (retvalStatus != osl::FileBase::E_None) {
+    bool couldSetFileStatus = set_file_status(fileStatus, filename);
+    if (!couldSetFileStatus) {
         return false;
     }
+
     if (!fileStatus.isRegular()) {
         return false;
     }
@@ -178,6 +194,8 @@ IconThemeScanner::GetIconThemeInfo(const OUString& themeId)
     std::vector<IconThemeInfo>::iterator info = std::find_if(mFoundIconThemes.begin(), mFoundIconThemes.end(),
         SameTheme(themeId));
     if (info == mFoundIconThemes.end()) {
+        SAL_WARN(LOG_AREA, "Requested information for icon theme with id '" << themeId
+                << "' which does not exist.");
         throw std::runtime_error("Requested information on not-installed icon theme");
     }
     return *info;


More information about the Libreoffice-commits mailing list