diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 08abe141f4169f98d671fe22fc3be1151b48daa0..8b1c727b3399bfa0ea32f32fe0435c12f7be38c2 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -1707,7 +1707,9 @@ BeginCopyTo(Relation rel, errmsg("could not open file \"%s\" for writing: %m", cstate->filename))); - fstat(fileno(cstate->copy_file), &st); + if (fstat(fileno(cstate->copy_file), &st)) + elog(ERROR, "could not stat file \"%s\": %m", cstate->filename); + if (S_ISDIR(st.st_mode)) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), @@ -2718,7 +2720,9 @@ BeginCopyFrom(Relation rel, errmsg("could not open file \"%s\" for reading: %m", cstate->filename))); - fstat(fileno(cstate->copy_file), &st); + if (fstat(fileno(cstate->copy_file), &st)) + elog(ERROR, "could not stat file \"%s\": %m", cstate->filename); + if (S_ISDIR(st.st_mode)) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),