Coverage Report

Created: 2026-07-25 06:50

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
    AddProgressArg(/* hidden = */ true);
31
32
0
    {
33
0
        auto &arg =
34
0
            AddArg("filename", 0, _("File or directory name"), &m_filename)
35
0
                .SetPositional()
36
0
                .SetRequired();
37
0
        SetAutoCompleteFunctionForFilename(arg, 0);
38
0
    }
39
40
0
    {
41
0
        auto &arg =
42
0
            AddArg("format", 'f', _("Dataset format"), &m_format)
43
0
                .AddMetadataItem(GAAMDI_REQUIRED_CAPABILITIES, {GDAL_DCAP_OPEN})
44
0
                .SetCategory(GAAC_ADVANCED);
45
0
        arg.AddValidationAction([this, &arg]()
46
0
                                { return ValidateFormat(arg, false, false); });
47
0
        arg.SetAutoCompleteFunction(
48
0
            [&arg](const std::string &)
49
0
            {
50
0
                return GDALAlgorithm::FormatAutoCompleteFunction(arg, false,
51
0
                                                                 false);
52
0
            });
53
0
    }
54
0
}
55
56
/************************************************************************/
57
/*                GDALDatasetDeleteAlgorithm::RunImpl()                 */
58
/************************************************************************/
59
60
bool GDALDatasetDeleteAlgorithm::RunImpl(GDALProgressFunc, void *)
61
0
{
62
0
    GDALDriverH hDriver = nullptr;
63
0
    if (!m_format.empty())
64
0
        hDriver = GDALGetDriverByName(m_format.c_str());
65
66
0
    bool ret = true;
67
0
    for (const auto &datasetName : m_filename)
68
0
    {
69
0
        ret = ret && GDALDeleteDataset(hDriver, datasetName.c_str()) == CE_None;
70
0
    }
71
72
0
    return ret;
73
0
}
74
75
//! @endcond