LCOV - code coverage report
Current view: top level - store/source - stordir.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 63 74 85.1 %
Date: 2015-06-13 12:38:46 Functions: 7 9 77.8 %
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             : #include "stordir.hxx"
      21             : 
      22             : #include <sal/types.h>
      23             : 
      24             : #include <rtl/textcvt.h>
      25             : #include <rtl/ref.hxx>
      26             : 
      27             : #include <osl/mutex.hxx>
      28             : 
      29             : #include "store/types.h"
      30             : #include "object.hxx"
      31             : 
      32             : #include "storbase.hxx"
      33             : #include "stordata.hxx"
      34             : #include "storpage.hxx"
      35             : 
      36             : using namespace store;
      37             : 
      38             : /*========================================================================
      39             :  *
      40             :  * OStore... internals.
      41             :  *
      42             :  *======================================================================*/
      43             : /*
      44             :  * __store_convertTextToUnicode.
      45             :  */
      46          41 : inline sal_Size __store_convertTextToUnicode (
      47             :     rtl_TextToUnicodeConverter  hConverter,
      48             :     const sal_Char *pSrcBuffer, sal_Size nSrcLength,
      49             :     sal_Unicode    *pDstBuffer, sal_Size nDstLength)
      50             : {
      51          41 :     sal_uInt32 nCvtInfo = 0;
      52          41 :     sal_Size nCvtBytes = 0;
      53             :     return rtl_convertTextToUnicode (
      54             :         hConverter, 0,
      55             :         pSrcBuffer, nSrcLength,
      56             :         pDstBuffer, nDstLength,
      57             :         OSTRING_TO_OUSTRING_CVTFLAGS,
      58          41 :         &nCvtInfo, &nCvtBytes);
      59             : }
      60             : 
      61             : /*========================================================================
      62             :  *
      63             :  * OStoreDirectory_Impl implementation.
      64             :  *
      65             :  *======================================================================*/
      66             : const sal_uInt32 OStoreDirectory_Impl::m_nTypeId = sal_uInt32(0x89191107);
      67             : 
      68             : /*
      69             :  * OStoreDirectory_Impl.
      70             :  */
      71         915 : OStoreDirectory_Impl::OStoreDirectory_Impl()
      72             :     : m_xManager (),
      73             :       m_aDescr   (0, 0, 0),
      74             :       m_nPath    (0),
      75         915 :       m_hTextCvt (NULL)
      76         915 : {}
      77             : 
      78             : /*
      79             :  * ~OStoreDirectory_Impl.
      80             :  */
      81        3660 : OStoreDirectory_Impl::~OStoreDirectory_Impl()
      82             : {
      83         915 :     if (m_xManager.is())
      84             :     {
      85         909 :         if (m_aDescr.m_nAddr != STORE_PAGE_NULL)
      86         909 :             m_xManager->releasePage (m_aDescr);
      87             :     }
      88         915 :     rtl_destroyTextToUnicodeConverter (m_hTextCvt);
      89        2745 : }
      90             : 
      91             : /*
      92             :  * isKindOf.
      93             :  */
      94          78 : bool OStoreDirectory_Impl::isKindOf (sal_uInt32 nTypeId)
      95             : {
      96          78 :     return (nTypeId == m_nTypeId);
      97             : }
      98             : 
      99             : /*
     100             :  * create.
     101             :  */
     102         915 : storeError OStoreDirectory_Impl::create (
     103             :     OStorePageManager *pManager,
     104             :     rtl_String        *pPath,
     105             :     rtl_String        *pName,
     106             :     storeAccessMode    eMode)
     107             : {
     108         915 :     rtl::Reference<OStorePageManager> xManager (pManager);
     109         915 :     if (!xManager.is())
     110           0 :         return store_E_InvalidAccess;
     111             : 
     112         915 :     if (!(pPath && pName))
     113           0 :         return store_E_InvalidParameter;
     114             : 
     115        1830 :     OStoreDirectoryPageObject aPage;
     116             :     storeError eErrCode = xManager->iget (
     117             :         aPage, STORE_ATTRIB_ISDIR,
     118         915 :         pPath, pName, eMode);
     119         915 :     if (eErrCode != store_E_None)
     120           6 :         return eErrCode;
     121             : 
     122         909 :     if (!(aPage.attrib() & STORE_ATTRIB_ISDIR))
     123           0 :         return store_E_NotDirectory;
     124             : 
     125        1818 :     inode_holder_type xNode (aPage.get());
     126         909 :     eErrCode = xManager->acquirePage (xNode->m_aDescr, store_AccessReadOnly);
     127         909 :     if (eErrCode != store_E_None)
     128           0 :         return eErrCode;
     129             : 
     130             :     // Evaluate iteration path.
     131         909 :     m_nPath = aPage.path();
     132         909 :     m_nPath = rtl_crc32 (m_nPath, "/", 1);
     133             : 
     134             :     // Save page manager, and descriptor.
     135         909 :     m_xManager = xManager;
     136         909 :     m_aDescr   = xNode->m_aDescr;
     137             : 
     138        1824 :     return store_E_None;
     139             : }
     140             : 
     141             : /*
     142             :  * iterate.
     143             :  */
     144          78 : storeError OStoreDirectory_Impl::iterate (storeFindData &rFindData)
     145             : {
     146          78 :     if (!m_xManager.is())
     147           0 :         return store_E_InvalidAccess;
     148             : 
     149          78 :     storeError eErrCode = store_E_NoMoreFiles;
     150          78 :     if (!rFindData.m_nReserved)
     151           0 :         return eErrCode;
     152             : 
     153             :     // Acquire exclusive access.
     154          78 :     osl::MutexGuard aGuard (*m_xManager);
     155             : 
     156             :     // Check TextConverter.
     157          78 :     if (m_hTextCvt == NULL)
     158          37 :         m_hTextCvt = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF8);
     159             : 
     160             :     // Setup iteration key.
     161          78 :     OStorePageKey aKey (rFindData.m_nReserved, m_nPath);
     162             : 
     163             :     // Iterate.
     164             :     for (;;)
     165             :     {
     166          78 :         OStorePageLink aLink;
     167          78 :         eErrCode = m_xManager->iterate (aKey, aLink, rFindData.m_nAttrib);
     168          78 :         if (!((eErrCode == store_E_None) && (aKey.m_nHigh == store::htonl(m_nPath))))
     169          74 :             break;
     170             : 
     171          41 :         if (!(rFindData.m_nAttrib & STORE_ATTRIB_ISLINK))
     172             :         {
     173             :             // Load page.
     174          41 :             OStoreDirectoryPageObject aPage;
     175          41 :             eErrCode = m_xManager->loadObjectAt (aPage, aLink.location());
     176          41 :             if (eErrCode == store_E_None)
     177             :             {
     178          41 :                 inode_holder_type xNode (aPage.get());
     179             : 
     180             :                 // Setup FindData.
     181          41 :                 sal_Char *p = xNode->m_aNameBlock.m_pData;
     182          41 :                 sal_Size  n = rtl_str_getLength (p);
     183          41 :                 sal_Size  k = rFindData.m_nLength;
     184             : 
     185             :                 n = __store_convertTextToUnicode (
     186             :                     m_hTextCvt, p, n,
     187          41 :                     rFindData.m_pszName, STORE_MAXIMUM_NAMESIZE - 1);
     188          41 :                 if (k > n)
     189             :                 {
     190           5 :                     k = (k - n) * sizeof(sal_Unicode);
     191           5 :                     memset (&rFindData.m_pszName[n], 0, k);
     192             :                 }
     193             : 
     194          41 :                 rFindData.m_nLength  = n;
     195          41 :                 rFindData.m_nAttrib |= aPage.attrib();
     196          41 :                 rFindData.m_nSize    = aPage.dataLength();
     197             : 
     198             :                 // Leave.
     199          41 :                 rFindData.m_nReserved = store::ntohl(aKey.m_nLow);
     200          41 :                 return store_E_None;
     201           0 :             }
     202             :         }
     203             : 
     204           0 :         if (aKey.m_nLow == 0)
     205           0 :             break;
     206           0 :         aKey.m_nLow = store::htonl(store::ntohl(aKey.m_nLow) - 1);
     207           0 :     }
     208             : 
     209             :     // Finished.
     210          37 :     memset (&rFindData, 0, sizeof (storeFindData));
     211          37 :     return store_E_NoMoreFiles;
     212             : }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11