Allow copydir() to be interrupted.
authorRobert Haas <[email protected]>
Thu, 1 Jul 2010 20:13:06 +0000 (20:13 +0000)
committerRobert Haas <[email protected]>
Thu, 1 Jul 2010 20:13:06 +0000 (20:13 +0000)
This makes ALTER DATABASE .. SET TABLESPACE and CREATE DATABASE more
sensitive to interrupts.  Backpatch to 8.4, where ALTER DATABASE .. SET
TABLESPACE was introduced.  We could go back further, but in the absence
of complaints about the CREATE DATABASE case it doesn't seem worth it.

Guillaume Lelarge, with a small correction by me.

src/port/copydir.c

index 56bd3f941babf0e86bff6a3c4edfce5f2a942afd..ee404c8c06e607b17b0ffb5c94638a43cb401cf1 100644 (file)
@@ -11,7 +11,7 @@
  *     as a service.
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/port/copydir.c,v 1.23.2.2 2010/02/16 00:01:35 stark Exp $
+ *       $PostgreSQL: pgsql/src/port/copydir.c,v 1.23.2.3 2010/07/01 20:13:06 rhaas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -23,6 +23,7 @@
 #include <sys/stat.h>
 
 #include "storage/fd.h"
+#include "miscadmin.h"
 
 /*
  *     On Windows, call non-macro versions of palloc; we can't reference
@@ -68,6 +69,9 @@ copydir(char *fromdir, char *todir, bool recurse)
        {
                struct stat fst;
 
+        /* If we got a cancel signal during the copy of the directory, quit */
+        CHECK_FOR_INTERRUPTS();
+
                if (strcmp(xlde->d_name, ".") == 0 ||
                        strcmp(xlde->d_name, "..") == 0)
                        continue;
@@ -130,6 +134,9 @@ copy_file(char *fromfile, char *tofile)
         */
        for (;;)
        {
+        /* If we got a cancel signal during the copy of the file, quit */
+        CHECK_FOR_INTERRUPTS();
+
                nbytes = read(srcfd, buffer, COPY_BUF_SIZE);
                if (nbytes < 0)
                        ereport(ERROR,