Line data Source code
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 : 17 : //! @cond Doxygen_Suppress 18 : 19 : #ifndef _ 20 : #define _(x) (x) 21 : #endif 22 : 23 : /************************************************************************/ 24 : /* GDALVSIMoveAlgorithm::GDALVSIMoveAlgorithm() */ 25 : /************************************************************************/ 26 : 27 4 : GDALVSIMoveAlgorithm::GDALVSIMoveAlgorithm() 28 4 : : GDALAlgorithm(NAME, DESCRIPTION, HELP_URL) 29 : { 30 4 : AddProgressArg(); 31 : { 32 : auto &arg = 33 8 : AddArg("source", 0, _("Source file or directory name"), &m_source) 34 4 : .SetPositional() 35 4 : .SetMinCharCount(1) 36 4 : .SetRequired(); 37 4 : SetAutoCompleteFunctionForFilename(arg, 0); 38 : } 39 : { 40 : auto &arg = 41 : AddArg("destination", 0, _("Destination file or directory name"), 42 8 : &m_destination) 43 4 : .SetPositional() 44 4 : .SetMinCharCount(1) 45 4 : .SetRequired(); 46 4 : SetAutoCompleteFunctionForFilename(arg, 0); 47 : } 48 4 : } 49 : 50 : /************************************************************************/ 51 : /* GDALVSIMoveAlgorithm::RunImpl() */ 52 : /************************************************************************/ 53 : 54 3 : bool GDALVSIMoveAlgorithm::RunImpl(GDALProgressFunc pfnProgress, 55 : void *pProgressData) 56 : { 57 3 : if (VSIMove(m_source.c_str(), m_destination.c_str(), nullptr, pfnProgress, 58 3 : pProgressData) != 0) 59 : { 60 : VSIStatBufL statBufSrc; 61 : const bool srcExists = 62 2 : VSIStatExL(m_source.c_str(), &statBufSrc, 63 2 : VSI_STAT_EXISTS_FLAG | VSI_STAT_NATURE_FLAG) == 0; 64 2 : if (!srcExists) 65 : { 66 1 : ReportError(CE_Failure, CPLE_FileIO, "%s does not exist", 67 : m_source.c_str()); 68 : } 69 : else 70 : { 71 1 : ReportError(CE_Failure, CPLE_FileIO, "%s could not be moved to %s", 72 : m_source.c_str(), m_destination.c_str()); 73 : } 74 2 : return false; 75 : } 76 1 : return true; 77 : } 78 : 79 : //! @endcond