Skip to content

Commit 3d61afa

Browse files
authored
Merge pull request #13415 from rouault/fix_13400
gdal raster convert: avoid error message when outputing to /vsistdout/
2 parents ccbfa7b + 92c5c0f commit 3d61afa

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

apps/gdal_translate_lib.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,8 @@ GDALDatasetH GDALTranslate(const char *pszDest, GDALDatasetH hSrcDataset,
11201120
"@QUIET_DELETE_ON_CREATE_COPY", "NO");
11211121
}
11221122

1123-
if (psOptions->bNoOverwrite && !EQUAL(pszDest, ""))
1123+
if (psOptions->bNoOverwrite && !EQUAL(pszDest, "") &&
1124+
!EQUAL(pszDest, "/vsistdout/"))
11241125
{
11251126
VSIStatBufL sStat;
11261127
if (VSIStatL(pszDest, &sStat) == 0)
@@ -1131,13 +1132,23 @@ GDALDatasetH GDALTranslate(const char *pszDest, GDALDatasetH hSrcDataset,
11311132
pszDest);
11321133
return nullptr;
11331134
}
1134-
else if (std::unique_ptr<GDALDataset>(GDALDataset::Open(pszDest)))
1135+
else
11351136
{
1136-
CPLError(CE_Failure, CPLE_AppDefined,
1137-
"Dataset '%s' already exists. Specify the --overwrite "
1138-
"option to overwrite it.",
1139-
pszDest);
1140-
return nullptr;
1137+
bool bExists;
1138+
{
1139+
CPLErrorStateBackuper oBackuper(CPLQuietErrorHandler);
1140+
bExists = std::unique_ptr<GDALDataset>(
1141+
GDALDataset::Open(pszDest)) != nullptr;
1142+
}
1143+
if (bExists)
1144+
{
1145+
CPLError(
1146+
CE_Failure, CPLE_AppDefined,
1147+
"Dataset '%s' already exists. Specify the --overwrite "
1148+
"option to overwrite it.",
1149+
pszDest);
1150+
return nullptr;
1151+
}
11411152
}
11421153
}
11431154

autotest/utilities/test_gdalalg_raster_convert.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,19 @@ def test_gdalalg_raster_convert_comma_in_filename(tmp_vsimem):
102102

103103
convert = get_convert_alg()
104104
assert convert.ParseRunAndFinalize([tmp_vsimem / "a,b.tif", out_filename])
105+
106+
107+
@pytest.mark.require_driver("XYZ")
108+
def test_gdalalg_raster_convert_to_vsistdout(tmp_vsimem):
109+
import gdaltest
110+
import test_cli_utilities
111+
112+
gdal_path = test_cli_utilities.get_gdal_path()
113+
if gdal_path is None:
114+
pytest.skip("gdal binary missing")
115+
out, err = gdaltest.runexternal_out_and_err(
116+
f"{gdal_path} raster convert --of XYZ ../gcore/data/byte.tif /vsistdout/"
117+
)
118+
gdal.FileFromMemBuffer(tmp_vsimem / "test.xyz", out)
119+
assert gdal.Open(tmp_vsimem / "test.xyz")
120+
assert err == ""

0 commit comments

Comments
 (0)