LCOV - code coverage report
Current view: top level - store/source - stordir.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 72 87.5 %
Date: 2012-08-25 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 61 112 54.5 %

           Branch data     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                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include "stordir.hxx"
      22                 :            : 
      23                 :            : #include <sal/types.h>
      24                 :            : 
      25                 :            : #include <rtl/textcvt.h>
      26                 :            : #include <rtl/ref.hxx>
      27                 :            : 
      28                 :            : #include <osl/mutex.hxx>
      29                 :            : 
      30                 :            : #include "store/types.h"
      31                 :            : #include "object.hxx"
      32                 :            : 
      33                 :            : #include "storbase.hxx"
      34                 :            : #include "stordata.hxx"
      35                 :            : #include "storpage.hxx"
      36                 :            : 
      37                 :            : using namespace store;
      38                 :            : 
      39                 :            : /*========================================================================
      40                 :            :  *
      41                 :            :  * OStore... internals.
      42                 :            :  *
      43                 :            :  *======================================================================*/
      44                 :            : /*
      45                 :            :  * __store_convertTextToUnicode.
      46                 :            :  */
      47                 :     314886 : inline sal_Size __store_convertTextToUnicode (
      48                 :            :     rtl_TextToUnicodeConverter  hConverter,
      49                 :            :     const sal_Char *pSrcBuffer, sal_Size nSrcLength,
      50                 :            :     sal_Unicode    *pDstBuffer, sal_Size nDstLength)
      51                 :            : {
      52                 :     314886 :     sal_uInt32 nCvtInfo = 0;
      53                 :     314886 :     sal_Size nCvtBytes = 0;
      54                 :            :     return rtl_convertTextToUnicode (
      55                 :            :         hConverter, 0,
      56                 :            :         pSrcBuffer, nSrcLength,
      57                 :            :         pDstBuffer, nDstLength,
      58                 :            :         OSTRING_TO_OUSTRING_CVTFLAGS,
      59         [ +  - ]:     314886 :         &nCvtInfo, &nCvtBytes);
      60                 :            : }
      61                 :            : 
      62                 :            : /*========================================================================
      63                 :            :  *
      64                 :            :  * OStoreDirectory_Impl implementation.
      65                 :            :  *
      66                 :            :  *======================================================================*/
      67                 :            : const sal_uInt32 OStoreDirectory_Impl::m_nTypeId = sal_uInt32(0x89191107);
      68                 :            : 
      69                 :            : /*
      70                 :            :  * OStoreDirectory_Impl.
      71                 :            :  */
      72                 :    1253445 : OStoreDirectory_Impl::OStoreDirectory_Impl (void)
      73                 :            :     : m_xManager (),
      74                 :            :       m_aDescr   (0, 0, 0),
      75                 :            :       m_nPath    (0),
      76                 :    1253445 :       m_hTextCvt (NULL)
      77                 :    1253445 : {}
      78                 :            : 
      79                 :            : /*
      80                 :            :  * ~OStoreDirectory_Impl.
      81                 :            :  */
      82         [ +  - ]:    1253445 : OStoreDirectory_Impl::~OStoreDirectory_Impl (void)
      83                 :            : {
      84         [ +  + ]:    1253445 :     if (m_xManager.is())
      85                 :            :     {
      86         [ +  - ]:     559413 :         if (m_aDescr.m_nAddr != STORE_PAGE_NULL)
      87         [ +  - ]:     559413 :             m_xManager->releasePage (m_aDescr);
      88                 :            :     }
      89         [ +  - ]:    1253445 :     rtl_destroyTextToUnicodeConverter (m_hTextCvt);
      90         [ -  + ]:    2506890 : }
      91                 :            : 
      92                 :            : /*
      93                 :            :  * isKindOf.
      94                 :            :  */
      95                 :     480957 : sal_Bool SAL_CALL OStoreDirectory_Impl::isKindOf (sal_uInt32 nTypeId)
      96                 :            : {
      97                 :     480957 :     return (nTypeId == m_nTypeId);
      98                 :            : }
      99                 :            : 
     100                 :            : /*
     101                 :            :  * create.
     102                 :            :  */
     103                 :    1253445 : storeError OStoreDirectory_Impl::create (
     104                 :            :     OStorePageManager *pManager,
     105                 :            :     rtl_String        *pPath,
     106                 :            :     rtl_String        *pName,
     107                 :            :     storeAccessMode    eMode)
     108                 :            : {
     109         [ +  - ]:    1253445 :     rtl::Reference<OStorePageManager> xManager (pManager);
     110         [ -  + ]:    1253445 :     if (!xManager.is())
     111                 :          0 :         return store_E_InvalidAccess;
     112                 :            : 
     113 [ +  - ][ -  + ]:    1253445 :     if (!(pPath && pName))
     114                 :          0 :         return store_E_InvalidParameter;
     115                 :            : 
     116 [ +  - ][ +  - ]:    1253445 :     OStoreDirectoryPageObject aPage;
         [ +  - ][ +  - ]
     117                 :            :     storeError eErrCode = xManager->iget (
     118                 :            :         aPage, STORE_ATTRIB_ISDIR,
     119         [ +  - ]:    1253445 :         pPath, pName, eMode);
     120         [ +  + ]:    1253445 :     if (eErrCode != store_E_None)
     121                 :     694032 :         return eErrCode;
     122                 :            : 
     123 [ +  - ][ -  + ]:     559413 :     if (!(aPage.attrib() & STORE_ATTRIB_ISDIR))
     124                 :          0 :         return store_E_NotDirectory;
     125                 :            : 
     126         [ +  - ]:     559413 :     inode_holder_type xNode (aPage.get());
     127 [ +  - ][ +  - ]:     559413 :     eErrCode = xManager->acquirePage (xNode->m_aDescr, store_AccessReadOnly);
     128         [ -  + ]:     559413 :     if (eErrCode != store_E_None)
     129                 :          0 :         return eErrCode;
     130                 :            : 
     131                 :            :     // Evaluate iteration path.
     132         [ +  - ]:     559413 :     m_nPath = aPage.path();
     133                 :     559413 :     m_nPath = rtl_crc32 (m_nPath, "/", 1);
     134                 :            : 
     135                 :            :     // Save page manager, and descriptor.
     136         [ +  - ]:     559413 :     m_xManager = xManager;
     137         [ +  - ]:     559413 :     m_aDescr   = xNode->m_aDescr;
     138                 :            : 
     139 [ +  - ][ +  - ]:    1253445 :     return store_E_None;
                 [ +  - ]
     140                 :            : }
     141                 :            : 
     142                 :            : /*
     143                 :            :  * iterate.
     144                 :            :  */
     145                 :     480957 : storeError OStoreDirectory_Impl::iterate (storeFindData &rFindData)
     146                 :            : {
     147         [ -  + ]:     480957 :     if (!m_xManager.is())
     148                 :          0 :         return store_E_InvalidAccess;
     149                 :            : 
     150                 :     480957 :     storeError eErrCode = store_E_NoMoreFiles;
     151         [ -  + ]:     480957 :     if (!rFindData.m_nReserved)
     152                 :          0 :         return eErrCode;
     153                 :            : 
     154                 :            :     // Acquire exclusive access.
     155         [ +  - ]:     480957 :     osl::MutexGuard aGuard (*m_xManager);
     156                 :            : 
     157                 :            :     // Check TextConverter.
     158         [ +  + ]:     480957 :     if (m_hTextCvt == NULL)
     159         [ +  - ]:     166071 :         m_hTextCvt = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF8);
     160                 :            : 
     161                 :            :     // Setup iteration key.
     162                 :     480957 :     OStorePageKey aKey (rFindData.m_nReserved, m_nPath);
     163                 :            : 
     164                 :            :     // Iterate.
     165                 :          0 :     for (;;)
     166                 :            :     {
     167                 :     480957 :         OStorePageLink aLink;
     168         [ +  - ]:     480957 :         eErrCode = m_xManager->iterate (aKey, aLink, rFindData.m_nAttrib);
     169 [ +  - ][ +  + ]:     480957 :         if (!((eErrCode == store_E_None) && (aKey.m_nHigh == store::htonl(m_nPath))))
                 [ +  + ]
     170                 :            :             break;
     171                 :            : 
     172         [ +  - ]:     314886 :         if (!(rFindData.m_nAttrib & STORE_ATTRIB_ISLINK))
     173                 :            :         {
     174                 :            :             // Load page.
     175 [ +  - ][ +  - ]:     314886 :             OStoreDirectoryPageObject aPage;
         [ +  - ][ +  - ]
     176         [ +  - ]:     314886 :             eErrCode = m_xManager->loadObjectAt (aPage, aLink.location());
     177         [ +  - ]:     314886 :             if (eErrCode == store_E_None)
     178                 :            :             {
     179         [ +  - ]:     314886 :                 inode_holder_type xNode (aPage.get());
     180                 :            : 
     181                 :            :                 // Setup FindData.
     182         [ +  - ]:     314886 :                 sal_Char *p = xNode->m_aNameBlock.m_pData;
     183                 :     314886 :                 sal_Size  n = rtl_str_getLength (p);
     184                 :     314886 :                 sal_Size  k = rFindData.m_nLength;
     185                 :            : 
     186                 :            :                 n = __store_convertTextToUnicode (
     187                 :            :                     m_hTextCvt, p, n,
     188         [ +  - ]:     314886 :                     rFindData.m_pszName, STORE_MAXIMUM_NAMESIZE - 1);
     189         [ +  + ]:     314886 :                 if (k > n)
     190                 :            :                 {
     191                 :      61485 :                     k = (k - n) * sizeof(sal_Unicode);
     192                 :      61485 :                     memset (&rFindData.m_pszName[n], 0, k);
     193                 :            :                 }
     194                 :            : 
     195                 :     314886 :                 rFindData.m_nLength  = n;
     196         [ +  - ]:     314886 :                 rFindData.m_nAttrib |= aPage.attrib();
     197         [ +  - ]:     314886 :                 rFindData.m_nSize    = aPage.dataLength();
     198                 :            : 
     199                 :            :                 // Leave.
     200                 :     314886 :                 rFindData.m_nReserved = store::ntohl(aKey.m_nLow);
     201         [ +  - ]:     314886 :                 return store_E_None;
     202 [ +  - ][ -  + ]:     314886 :             }
     203                 :            :         }
     204                 :            : 
     205         [ #  # ]:          0 :         if (aKey.m_nLow == 0)
     206                 :            :             break;
     207                 :          0 :         aKey.m_nLow = store::htonl(store::ntohl(aKey.m_nLow) - 1);
     208                 :            :     }
     209                 :            : 
     210                 :            :     // Finished.
     211                 :     166071 :     memset (&rFindData, 0, sizeof (storeFindData));
     212         [ +  - ]:     480957 :     return store_E_NoMoreFiles;
     213                 :            : }
     214                 :            : 
     215                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10