LCOV - code coverage report
Current view: top level - frmts/zarr - vsikerchunk.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 23 23 100.0 %
Date: 2025-06-19 12:30:01 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  Zarr driver
       5             :  * Author:   Even Rouault <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "vsikerchunk.h"
      14             : 
      15             : #include "cpl_port.h"
      16             : #include "cpl_conv.h"
      17             : #include "cpl_error.h"
      18             : #include "cpl_string.h"
      19             : 
      20             : /************************************************************************/
      21             : /*                    VSIInstallKerchunkFileSystems()                   */
      22             : /************************************************************************/
      23             : 
      24        1629 : void VSIInstallKerchunkFileSystems()
      25             : {
      26        1629 :     VSIInstallKerchunkJSONRefFileSystem();
      27        1629 :     VSIInstallKerchunkParquetRefFileSystem();
      28        1629 : }
      29             : 
      30             : /************************************************************************/
      31             : /*                    VSIKerchunkFileSystemsCleanCache()                */
      32             : /************************************************************************/
      33             : 
      34        1055 : void VSIKerchunkFileSystemsCleanCache()
      35             : {
      36        1055 :     VSIKerchunkParquetRefFileSystemCleanCache();
      37        1055 : }
      38             : 
      39             : /************************************************************************/
      40             : /*                    VSIKerchunkMorphURIToVSIPath()                    */
      41             : /************************************************************************/
      42             : 
      43          40 : std::string VSIKerchunkMorphURIToVSIPath(const std::string &osURI,
      44             :                                          const std::string &osRootDirname)
      45             : {
      46             :     static const struct
      47             :     {
      48             :         const char *pszFSSpecPrefix;
      49             :         const char *pszVSIPrefix;
      50             :     } substitutions[] = {
      51             :         {"s3://", "/vsis3/"},
      52             :         {"gs://", "/vsigs/"},
      53             :         {"http://", "/vsicurl/http://"},
      54             :         {"https://", "/vsicurl/https://"},
      55             :     };
      56             : 
      57         199 :     for (const auto &substitution : substitutions)
      58             :     {
      59         160 :         if (STARTS_WITH(osURI.c_str(), substitution.pszFSSpecPrefix))
      60             :         {
      61           2 :             return std::string(substitution.pszVSIPrefix)
      62           1 :                 .append(osURI.c_str() + strlen(substitution.pszFSSpecPrefix));
      63             :         }
      64             :     }
      65             : 
      66          39 :     if (CPLIsFilenameRelative(osURI.c_str()))
      67             :     {
      68             :         return CPLFormFilenameSafe(osRootDirname.c_str(), osURI.c_str(),
      69          31 :                                    nullptr);
      70             :     }
      71           8 :     else if (VSIIsLocal(osURI.c_str()) && !VSIIsLocal(osRootDirname.c_str()))
      72             :     {
      73           3 :         const char *pszVal = CPLGetConfigOption(
      74             :             "GDAL_ALLOW_REMOTE_RESOURCE_TO_ACCESS_LOCAL_FILE", nullptr);
      75           3 :         if (pszVal == nullptr)
      76             :         {
      77           1 :             CPLError(CE_Failure, CPLE_AppDefined,
      78             :                      "Remote resource '%s' tries to access local file '%s'. "
      79             :                      "This is disabled by default. Set the "
      80             :                      "GDAL_ALLOW_REMOTE_RESOURCE_TO_ACCESS_LOCAL_FILE "
      81             :                      "configuration option to YES to allow that.",
      82             :                      osRootDirname.c_str(), osURI.c_str());
      83           1 :             return std::string();
      84             :         }
      85           2 :         else if (!CPLTestBool(pszVal))
      86             :         {
      87           1 :             CPLError(CE_Failure, CPLE_AppDefined,
      88             :                      "Remote resource '%s' tries to access local file '%s'.",
      89             :                      osRootDirname.c_str(), osURI.c_str());
      90           1 :             return std::string();
      91             :         }
      92             :     }
      93             : 
      94           6 :     return osURI;
      95             : }

Generated by: LCOV version 1.14