Skip to content

Commit 3d174b4

Browse files
committed
Switch off ogr-output streaming mode for non default io contexts (#4858)
1 parent 74f9382 commit 3d174b4

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

mapio.c

+17
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ static msIOContextGroup *msIO_GetContextGroup()
145145
return group;
146146
}
147147

148+
/* returns MS_TRUE if the msIO standard output hasn't been redirected */
149+
int msIO_isStdContext() {
150+
msIOContextGroup *group = io_context_list;
151+
int nThreadId = msGetThreadId();
152+
if(!group || group->thread_id != nThreadId) {
153+
group = msIO_GetContextGroup();
154+
if(!group) {
155+
return MS_FALSE; /* probably a bug */
156+
}
157+
}
158+
if(group->stderr_context.cbData == (void*)stderr &&
159+
group->stdin_context.cbData == (void*)stdin &&
160+
group->stdout_context.cbData == (void*)stdout)
161+
return MS_TRUE;
162+
return MS_FALSE;
163+
}
164+
148165
/************************************************************************/
149166
/* msIO_getHandler() */
150167
/************************************************************************/

mapio.h

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extern "C" {
108108
void MS_DLL_EXPORT msIO_Cleanup(void);
109109
char MS_DLL_EXPORT *msIO_stripStdoutBufferContentType(void);
110110
void MS_DLL_EXPORT msIO_stripStdoutBufferContentHeaders(void);
111+
int MS_DLL_EXPORT msIO_isStdContext(void);
111112

112113
/* this is just for setting normal stdout's to binary mode on windows */
113114

mapogroutput.c

+6
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
536536
/* Determine the output datasource name to use. */
537537
/* ==================================================================== */
538538
storage = msGetOutputFormatOption( format, "STORAGE", "filesystem" );
539+
if( EQUAL(storage,"stream") && !msIO_isStdContext() ) {
540+
/* bug #4858, streaming output won't work if standard output has been
541+
* redirected, we switch to memory output in this case
542+
*/
543+
storage = "memory";
544+
}
539545

540546
/* -------------------------------------------------------------------- */
541547
/* Where are we putting stuff? */

0 commit comments

Comments
 (0)