Coverage Report

Created: 2026-02-14 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/apps/gdalalg_vsi_move.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  GDAL
4
 * Purpose:  gdal "vsi move" 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_vsi_move.h"
14
15
#include "cpl_vsi.h"
16
#include "cpl_vsi_error.h"
17
18
//! @cond Doxygen_Suppress
19
20
#ifndef _
21
0
#define _(x) (x)
22
#endif
23
24
/************************************************************************/
25
/*             GDALVSIMoveAlgorithm::GDALVSIMoveAlgorithm()             */
26
/************************************************************************/
27
28
GDALVSIMoveAlgorithm::GDALVSIMoveAlgorithm()
29
0
    : GDALAlgorithm(NAME, DESCRIPTION, HELP_URL)
30
0
{
31
0
    AddProgressArg();
32
0
    {
33
0
        auto &arg =
34
0
            AddArg("source", 0, _("Source file or directory name"), &m_source)
35
0
                .SetPositional()
36
0
                .SetMinCharCount(1)
37
0
                .SetRequired();
38
0
        SetAutoCompleteFunctionForFilename(arg, 0);
39
0
    }
40
0
    {
41
0
        auto &arg =
42
0
            AddArg("destination", 0, _("Destination file or directory name"),
43
0
                   &m_destination)
44
0
                .SetPositional()
45
0
                .SetMinCharCount(1)
46
0
                .SetRequired();
47
0
        SetAutoCompleteFunctionForFilename(arg, 0);
48
0
    }
49
0
}
50
51
/************************************************************************/
52
/*                   GDALVSIMoveAlgorithm::RunImpl()                    */
53
/************************************************************************/
54
55
bool GDALVSIMoveAlgorithm::RunImpl(GDALProgressFunc pfnProgress,
56
                                   void *pProgressData)
57
0
{
58
0
    if (VSIMove(m_source.c_str(), m_destination.c_str(), nullptr, pfnProgress,
59
0
                pProgressData) != 0)
60
0
    {
61
0
        VSIStatBufL statBufSrc;
62
0
        VSIErrorReset();
63
0
        const auto nOldErrorNum = VSIGetLastErrorNo();
64
0
        const bool srcExists = VSIStatL(m_source.c_str(), &statBufSrc) == 0;
65
0
        if (!srcExists)
66
0
        {
67
0
            if (nOldErrorNum != VSIGetLastErrorNo())
68
0
            {
69
0
                ReportError(CE_Failure, CPLE_FileIO,
70
0
                            "'%s' cannot be accessed. %s: %s", m_source.c_str(),
71
0
                            VSIErrorNumToString(VSIGetLastErrorNo()),
72
0
                            VSIGetLastErrorMsg());
73
0
            }
74
0
            else
75
0
            {
76
0
                ReportError(CE_Failure, CPLE_FileIO,
77
0
                            "'%s' does not exist or cannot be accessed",
78
0
                            m_source.c_str());
79
0
            }
80
0
        }
81
0
        else
82
0
        {
83
0
            ReportError(CE_Failure, CPLE_FileIO, "%s could not be moved to %s",
84
0
                        m_source.c_str(), m_destination.c_str());
85
0
        }
86
0
        return false;
87
0
    }
88
0
    return true;
89
0
}
90
91
//! @endcond