Index: src/port/open.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/port/open.c,v retrieving revision 1.22 diff -c -r1.22 open.c *** src/port/open.c 30 Nov 2007 11:16:43 -0000 1.22 --- src/port/open.c 19 Dec 2007 12:42:05 -0000 *************** *** 58,65 **** pgwin32_open(const char *fileName, int fileFlags,...) { int fd; ! HANDLE h; SECURITY_ATTRIBUTES sa; /* Check that we can handle the request */ assert((fileFlags & ((O_RDONLY | O_WRONLY | O_RDWR) | O_APPEND | --- 58,66 ---- pgwin32_open(const char *fileName, int fileFlags,...) { int fd; ! HANDLE h = INVALID_HANDLE_VALUE; SECURITY_ATTRIBUTES sa; + int loops = 0; /* Check that we can handle the request */ assert((fileFlags & ((O_RDONLY | O_WRONLY | O_RDWR) | O_APPEND | *************** *** 71,77 **** sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; ! if ((h = CreateFile(fileName, /* cannot use O_RDONLY, as it == 0 */ (fileFlags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) : ((fileFlags & O_WRONLY) ? GENERIC_WRITE : GENERIC_READ), --- 72,78 ---- sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; ! while ((h = CreateFile(fileName, /* cannot use O_RDONLY, as it == 0 */ (fileFlags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) : ((fileFlags & O_WRONLY) ? GENERIC_WRITE : GENERIC_READ), *************** *** 88,93 **** --- 89,108 ---- ((fileFlags & O_DSYNC) ? FILE_FLAG_WRITE_THROUGH : 0), NULL)) == INVALID_HANDLE_VALUE) { + /* + * Sharing violation or locking error can indicate antivirus, backup + * or similar software that's locking the file. Try again for 30 seconds + * before giving up. + */ + if (GetLastError() == ERROR_SHARING_VIOLATION || + GetLastError() == ERROR_LOCK_VIOLATION) + { + pg_usleep(100000); + loops++; + if (loops < 30) + continue; + } + _dosmaperr(GetLastError()); return -1; }