LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/store/source - stordir.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 74 85.1 %
Date: 2013-07-09 Functions: 7 7 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             :  * 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      100171 : 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      100171 :     sal_uInt32 nCvtInfo = 0;
      53      100171 :     sal_Size nCvtBytes = 0;
      54             :     return rtl_convertTextToUnicode (
      55             :         hConverter, 0,
      56             :         pSrcBuffer, nSrcLength,
      57             :         pDstBuffer, nDstLength,
      58             :         OSTRING_TO_OUSTRING_CVTFLAGS,
      59      100171 :         &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      215608 : OStoreDirectory_Impl::OStoreDirectory_Impl (void)
      73             :     : m_xManager (),
      74             :       m_aDescr   (0, 0, 0),
      75             :       m_nPath    (0),
      76      215608 :       m_hTextCvt (NULL)
      77      215608 : {}
      78             : 
      79             : /*
      80             :  * ~OStoreDirectory_Impl.
      81             :  */
      82      646824 : OStoreDirectory_Impl::~OStoreDirectory_Impl (void)
      83             : {
      84      215608 :     if (m_xManager.is())
      85             :     {
      86      215602 :         if (m_aDescr.m_nAddr != STORE_PAGE_NULL)
      87      215602 :             m_xManager->releasePage (m_aDescr);
      88             :     }
      89      215608 :     rtl_destroyTextToUnicodeConverter (m_hTextCvt);
      90      431216 : }
      91             : 
      92             : /*
      93             :  * isKindOf.
      94             :  */
      95      149841 : sal_Bool SAL_CALL OStoreDirectory_Impl::isKindOf (sal_uInt32 nTypeId)
      96             : {
      97      149841 :     return (nTypeId == m_nTypeId);
      98             : }
      99             : 
     100             : /*
     101             :  * create.
     102             :  */
     103      215608 : storeError OStoreDirectory_Impl::create (
     104             :     OStorePageManager *pManager,
     105             :     rtl_String        *pPath,
     106             :     rtl_String        *pName,
     107             :     storeAccessMode    eMode)
     108             : {
     109      215608 :     rtl::Reference<OStorePageManager> xManager (pManager);
     110      215608 :     if (!xManager.is())
     111           0 :         return store_E_InvalidAccess;
     112             : 
     113      215608 :     if (!(pPath && pName))
     114           0 :         return store_E_InvalidParameter;
     115             : 
     116      431216 :     OStoreDirectoryPageObject aPage;
     117             :     storeError eErrCode = xManager->iget (
     118             :         aPage, STORE_ATTRIB_ISDIR,
     119      215608 :         pPath, pName, eMode);
     120      215608 :     if (eErrCode != store_E_None)
     121           6 :         return eErrCode;
     122             : 
     123      215602 :     if (!(aPage.attrib() & STORE_ATTRIB_ISDIR))
     124           0 :         return store_E_NotDirectory;
     125             : 
     126      431204 :     inode_holder_type xNode (aPage.get());
     127      215602 :     eErrCode = xManager->acquirePage (xNode->m_aDescr, store_AccessReadOnly);
     128      215602 :     if (eErrCode != store_E_None)
     129           0 :         return eErrCode;
     130             : 
     131             :     // Evaluate iteration path.
     132      215602 :     m_nPath = aPage.path();
     133      215602 :     m_nPath = rtl_crc32 (m_nPath, "/", 1);
     134             : 
     135             :     // Save page manager, and descriptor.
     136      215602 :     m_xManager = xManager;
     137      215602 :     m_aDescr   = xNode->m_aDescr;
     138             : 
     139      431210 :     return store_E_None;
     140             : }
     141             : 
     142             : /*
     143             :  * iterate.
     144             :  */
     145      149841 : storeError OStoreDirectory_Impl::iterate (storeFindData &rFindData)
     146             : {
     147      149841 :     if (!m_xManager.is())
     148           0 :         return store_E_InvalidAccess;
     149             : 
     150      149841 :     storeError eErrCode = store_E_NoMoreFiles;
     151      149841 :     if (!rFindData.m_nReserved)
     152           0 :         return eErrCode;
     153             : 
     154             :     // Acquire exclusive access.
     155      149841 :     osl::MutexGuard aGuard (*m_xManager);
     156             : 
     157             :     // Check TextConverter.
     158      149841 :     if (m_hTextCvt == NULL)
     159       49670 :         m_hTextCvt = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF8);
     160             : 
     161             :     // Setup iteration key.
     162      149841 :     OStorePageKey aKey (rFindData.m_nReserved, m_nPath);
     163             : 
     164             :     // Iterate.
     165             :     for (;;)
     166             :     {
     167      149841 :         OStorePageLink aLink;
     168      149841 :         eErrCode = m_xManager->iterate (aKey, aLink, rFindData.m_nAttrib);
     169      149841 :         if (!((eErrCode == store_E_None) && (aKey.m_nHigh == store::htonl(m_nPath))))
     170       99340 :             break;
     171             : 
     172      100171 :         if (!(rFindData.m_nAttrib & STORE_ATTRIB_ISLINK))
     173             :         {
     174             :             // Load page.
     175      100171 :             OStoreDirectoryPageObject aPage;
     176      100171 :             eErrCode = m_xManager->loadObjectAt (aPage, aLink.location());
     177      100171 :             if (eErrCode == store_E_None)
     178             :             {
     179      100171 :                 inode_holder_type xNode (aPage.get());
     180             : 
     181             :                 // Setup FindData.
     182      100171 :                 sal_Char *p = xNode->m_aNameBlock.m_pData;
     183      100171 :                 sal_Size  n = rtl_str_getLength (p);
     184      100171 :                 sal_Size  k = rFindData.m_nLength;
     185             : 
     186             :                 n = __store_convertTextToUnicode (
     187             :                     m_hTextCvt, p, n,
     188      100171 :                     rFindData.m_pszName, STORE_MAXIMUM_NAMESIZE - 1);
     189      100171 :                 if (k > n)
     190             :                 {
     191       19130 :                     k = (k - n) * sizeof(sal_Unicode);
     192       19130 :                     memset (&rFindData.m_pszName[n], 0, k);
     193             :                 }
     194             : 
     195      100171 :                 rFindData.m_nLength  = n;
     196      100171 :                 rFindData.m_nAttrib |= aPage.attrib();
     197      100171 :                 rFindData.m_nSize    = aPage.dataLength();
     198             : 
     199             :                 // Leave.
     200      100171 :                 rFindData.m_nReserved = store::ntohl(aKey.m_nLow);
     201      100171 :                 return store_E_None;
     202           0 :             }
     203             :         }
     204             : 
     205           0 :         if (aKey.m_nLow == 0)
     206           0 :             break;
     207           0 :         aKey.m_nLow = store::htonl(store::ntohl(aKey.m_nLow) - 1);
     208           0 :     }
     209             : 
     210             :     // Finished.
     211       49670 :     memset (&rFindData, 0, sizeof (storeFindData));
     212       49670 :     return store_E_NoMoreFiles;
     213             : }
     214             : 
     215             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10