Coverage Report

Created: 2026-02-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/apps/gdalalg_dataset_delete.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  GDAL
4
 * Purpose:  gdal "dataset delete" subcommand
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 "gdalalg_dataset_delete.h"
14
15
#include "gdal.h"
16
17
//! @cond Doxygen_Suppress
18
19
#ifndef _
20
0
#define _(x) (x)
21
#endif
22
23
/************************************************************************/
24
/*                     GDALDatasetDeleteAlgorithm()                     */
25
/************************************************************************/
26
27
GDALDatasetDeleteAlgorithm::GDALDatasetDeleteAlgorithm()
28
0
    : GDALAlgorithm(NAME, DESCRIPTION, HELP_URL)
29
0
{
30
0
    {
31
0
        auto &arg =
32
0
            AddArg("filename", 0, _("File or directory name"), &m_filename)
33
0
                .SetPositional()
34
0
                .SetRequired();
35
0
        SetAutoCompleteFunctionForFilename(arg, 0);
36
0
    }
37
38
0
    {
39
0
        auto &arg =
40
0
            AddArg("format", 'f', _("Dataset format"), &m_format)
41
0
                .AddMetadataItem(GAAMDI_REQUIRED_CAPABILITIES, {GDAL_DCAP_OPEN})
42
0
                .SetCategory(GAAC_ADVANCED);
43
0
        arg.AddValidationAction([this, &arg]()
44
0
                                { return ValidateFormat(arg, false, false); });
45
0
        arg.SetAutoCompleteFunction(
46
0
            [&arg](const std::string &)
47
0
            {
48
0
                return GDALAlgorithm::FormatAutoCompleteFunction(arg, false,
49
0
                                                                 false);
50
0
            });
51
0
    }
52
0
}
53
54
/************************************************************************/
55
/*                GDALDatasetDeleteAlgorithm::RunImpl()                 */
56
/************************************************************************/
57
58
bool GDALDatasetDeleteAlgorithm::RunImpl(GDALProgressFunc, void *)
59
0
{
60
0
    GDALDriverH hDriver = nullptr;
61
0
    if (!m_format.empty())
62
0
        hDriver = GDALGetDriverByName(m_format.c_str());
63
64
0
    bool ret = true;
65
0
    for (const auto &datasetName : m_filename)
66
0
    {
67
0
        ret = ret && GDALDeleteDataset(hDriver, datasetName.c_str()) == CE_None;
68
0
    }
69
70
0
    return ret;
71
0
}
72
73
//! @endcond