LCOV - code coverage report
Current view: top level - include/salhelper - linkhelper.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 16 19 84.2 %
Date: 2014-11-03 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #ifndef INCLUDED_SALHELPER_LINKHELPER_HXX
      11             : #define INCLUDED_SALHELPER_LINKHELPER_HXX
      12             : 
      13             : #include <rtl/ustring.hxx>
      14             : #include <osl/file.hxx>
      15             : 
      16             : namespace salhelper
      17             : {
      18       31604 :     class LinkResolver
      19             :     {
      20             :     public:
      21             :         osl::FileStatus m_aStatus;
      22             : 
      23       31604 :         LinkResolver(sal_uInt32 nMask)
      24             :             : m_aStatus(nMask |
      25             :                         osl_FileStatus_Mask_FileURL |
      26             :                         osl_FileStatus_Mask_Type |
      27       31604 :                         osl_FileStatus_Mask_LinkTargetURL)
      28             :         {
      29       31604 :         }
      30             : 
      31             :         /** Resolve a file url if it's a symbolic link, to a maximum depth of
      32             :          *  nDepth and fill in m_aStatus with the requested ctor flags
      33             :          *
      34             :          *  @return osl::FileBase::E_None on success
      35             :          *
      36             :          *  @see DirectoryItem::getFileStatus
      37             :          */
      38       31604 :         osl::FileBase::RC fetchFileStatus(const rtl::OUString &rURL,
      39             :             int nDepth = 128)
      40             :         {
      41             :             //In an ideal world this wouldn't be inline, but I want to use this
      42             :             //in jvmfwk hence salhelper, but salhelper is .map controlled and
      43             :             //getting all the mangled names right is a misery, moving it over
      44             :             //to visibility markup would drop per-symbol versioning
      45             :             osl::FileBase::RC eReturn;
      46             : 
      47       31604 :             osl::DirectoryItem item;
      48       63208 :             rtl::OUString sURL(rURL);
      49       63558 :             while ((eReturn = osl::DirectoryItem::get(sURL, item))
      50             :                   == osl::File::E_None)
      51             :             {
      52        9862 :                 if (--nDepth == 0)
      53             :                 {
      54           0 :                     eReturn = osl::FileBase::E_MULTIHOP;
      55           0 :                     break;
      56             :                 }
      57        9862 :                 eReturn = item.getFileStatus(m_aStatus);
      58        9862 :                 if (eReturn != osl::File::E_None)
      59           0 :                     break;
      60        9862 :                 if (m_aStatus.getFileType() != osl::FileStatus::Link)
      61             :                 {
      62        9512 :                     eReturn = osl::FileBase::E_None;
      63        9512 :                     break;
      64             :                 }
      65         350 :                 sURL = m_aStatus.getLinkTargetURL();
      66             :             }
      67             : 
      68       63208 :             return eReturn;
      69             :         }
      70             :     };
      71             : }
      72             : 
      73             : #endif
      74             : 
      75             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10