Coverage Report

Created: 2025-06-09 07:43

/src/gdal/frmts/zarr/vsikerchunk.cpp
Line
Count
Source (jump to first uncovered line)
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
void VSIInstallKerchunkFileSystems()
25
2
{
26
2
    VSIInstallKerchunkJSONRefFileSystem();
27
2
    VSIInstallKerchunkParquetRefFileSystem();
28
2
}
29
30
/************************************************************************/
31
/*                    VSIKerchunkFileSystemsCleanCache()                */
32
/************************************************************************/
33
34
void VSIKerchunkFileSystemsCleanCache()
35
16
{
36
16
    VSIKerchunkParquetRefFileSystemCleanCache();
37
16
}
38
39
/************************************************************************/
40
/*                    VSIKerchunkMorphURIToVSIPath()                    */
41
/************************************************************************/
42
43
std::string VSIKerchunkMorphURIToVSIPath(const std::string &osURI,
44
                                         const std::string &osRootDirname)
45
0
{
46
0
    static const struct
47
0
    {
48
0
        const char *pszFSSpecPrefix;
49
0
        const char *pszVSIPrefix;
50
0
    } substitutions[] = {
51
0
        {"s3://", "/vsis3/"},
52
0
        {"gs://", "/vsigs/"},
53
0
        {"http://", "/vsicurl/http://"},
54
0
        {"https://", "/vsicurl/https://"},
55
0
    };
56
57
0
    for (const auto &substitution : substitutions)
58
0
    {
59
0
        if (STARTS_WITH(osURI.c_str(), substitution.pszFSSpecPrefix))
60
0
        {
61
0
            return std::string(substitution.pszVSIPrefix)
62
0
                .append(osURI.c_str() + strlen(substitution.pszFSSpecPrefix));
63
0
        }
64
0
    }
65
66
0
    if (CPLIsFilenameRelative(osURI.c_str()))
67
0
    {
68
0
        return CPLFormFilenameSafe(osRootDirname.c_str(), osURI.c_str(),
69
0
                                   nullptr);
70
0
    }
71
0
    else if (VSIIsLocal(osURI.c_str()) && !VSIIsLocal(osRootDirname.c_str()))
72
0
    {
73
0
        const char *pszVal = CPLGetConfigOption(
74
0
            "GDAL_ALLOW_REMOTE_RESOURCE_TO_ACCESS_LOCAL_FILE", nullptr);
75
0
        if (pszVal == nullptr)
76
0
        {
77
0
            CPLError(CE_Failure, CPLE_AppDefined,
78
0
                     "Remote resource '%s' tries to access local file '%s'. "
79
0
                     "This is disabled by default. Set the "
80
0
                     "GDAL_ALLOW_REMOTE_RESOURCE_TO_ACCESS_LOCAL_FILE "
81
0
                     "configuration option to YES to allow that.",
82
0
                     osRootDirname.c_str(), osURI.c_str());
83
0
            return std::string();
84
0
        }
85
0
        else if (!CPLTestBool(pszVal))
86
0
        {
87
0
            CPLError(CE_Failure, CPLE_AppDefined,
88
0
                     "Remote resource '%s' tries to access local file '%s'.",
89
0
                     osRootDirname.c_str(), osURI.c_str());
90
0
            return std::string();
91
0
        }
92
0
    }
93
94
0
    return osURI;
95
0
}