Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb8fd675

Browse files
committed
Allow unlink/rename of files open by another process on Win32, using a
special Win32 open flag FILE_SHARE_DELETE.Claudio Natoli
1 parentd6bc594 commitb8fd675

File tree

6 files changed

+110
-6
lines changed

6 files changed

+110
-6
lines changed

‎configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12079,6 +12079,7 @@ esac
1207912079
case $host_os in mingw*)
1208012080
LIBOBJS="$LIBOBJS copydir.$ac_objext"
1208112081
LIBOBJS="$LIBOBJS gettimeofday.$ac_objext"
12082+
LIBOBJS="$LIBOBJS open.$ac_objext"
1208212083
LIBOBJS="$LIBOBJS pipe.$ac_objext"
1208312084
LIBOBJS="$LIBOBJS rand.$ac_objext" ;;
1208412085
esac

‎configure.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.321 2004/03/20 16:11:22 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.322 2004/03/24 03:54:16 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -907,6 +907,7 @@ esac
907907
case $host_os in mingw*)
908908
AC_LIBOBJ(copydir)
909909
AC_LIBOBJ(gettimeofday)
910+
AC_LIBOBJ(open)
910911
AC_LIBOBJ(pipe)
911912
AC_LIBOBJ(rand) ;;
912913
esac

‎src/include/port.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.22 2004/03/10 21:12:46 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.23 2004/03/24 03:54:16 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -50,6 +50,11 @@ extern intpgunlink(const char *path);
5050
#endif
5151

5252
#ifdefWIN32
53+
54+
/* open() replacement to allow delete of held files */
55+
externintwin32_open(constchar*,int,...);
56+
#defineopen(a,b,...)win32_open(a,b,##__VA_ARGS__)
57+
5358
externintcopydir(char*fromdir,char*todir);
5459

5560
/* Missing rand functions */

‎src/interfaces/libpq/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.99 2004/03/12 04:33:41 momjian Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.100 2004/03/24 03:54:16 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -23,7 +23,7 @@ override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) -DFRONTEND -DSYS
2323
OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o\
2424
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o\
2525
dllist.o md5.o ip.o wchar.o encnames.o\
26-
$(filter crypt.o getaddrinfo.o inet_aton.o noblock.o snprintf.o strerror.o path.o thread.o,$(LIBOBJS))
26+
$(filter crypt.o getaddrinfo.o inet_aton.o noblock.o snprintf.o strerror.oopen.opath.o thread.o,$(LIBOBJS))
2727
ifeq ($(PORTNAME), win32)
2828
OBJS+=win32.o
2929
endif
@@ -52,7 +52,7 @@ backend_src = $(top_srcdir)/src/backend
5252
# For port modules, this only happens if configure decides the module
5353
# is needed (see filter hack in OBJS, above).
5454

55-
crypt.cgetaddrinfo.cinet_aton.cnoblock.csnprintf.cstrerror.cpath.cthread.c:% :$(top_srcdir)/src/port/%
55+
crypt.cgetaddrinfo.cinet_aton.cnoblock.csnprintf.cstrerror.copen.cpath.cthread.c:% :$(top_srcdir)/src/port/%
5656
rm -f$@&&$(LN_S)$<.
5757

5858
md5.cip.c:% :$(backend_src)/libpq/%

‎src/interfaces/libpq/win32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define_strnicmp(a,b,c) strnicmp(a,b,c)
1717
#define_errno errno
1818
#else
19-
#defineopen(a,b,c) _open(a,b,c)
19+
/* open provided elsewhere */
2020
#defineclose(a) _close(a)
2121
#defineread(a,b,c) _read(a,b,c)
2222
#definewrite(a,b,c) _write(a,b,c)

‎src/port/open.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* open.c
4+
* Win32 open() replacement
5+
*
6+
*
7+
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
8+
*
9+
* $PostgreSQL: pgsql/src/port/open.c,v 1.1 2004/03/24 03:54:16 momjian Exp $
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#ifdefWIN32
15+
16+
#include<windows.h>
17+
#include<fcntl.h>
18+
#include<errno.h>
19+
#include<assert.h>
20+
21+
intopenFlagsToCreateFileFlags(intopenFlags)
22+
{
23+
switch (openFlags& (O_CREAT|O_TRUNC|O_EXCL))
24+
{
25+
case0:
26+
caseO_EXCL:returnOPEN_EXISTING;
27+
28+
caseO_CREAT:returnOPEN_ALWAYS;
29+
30+
caseO_TRUNC:
31+
caseO_TRUNC|O_EXCL:returnTRUNCATE_EXISTING;
32+
33+
caseO_CREAT|O_TRUNC:returnCREATE_ALWAYS;
34+
35+
caseO_CREAT|O_EXCL:
36+
caseO_CREAT|O_TRUNC|O_EXCL:returnCREATE_NEW;
37+
}
38+
39+
/* will never get here */
40+
return0;
41+
}
42+
43+
/*
44+
* - file attribute setting, based on fileMode?
45+
* - handle other flags? (eg FILE_FLAG_NO_BUFFERING/FILE_FLAG_WRITE_THROUGH)
46+
*/
47+
intwin32_open(constchar*fileName,intfileFlags, ...)
48+
{
49+
intfd;
50+
HANDLEh;
51+
SECURITY_ATTRIBUTESsa;
52+
53+
/* Check that we can handle the request */
54+
assert((fileFlags& ((O_RDONLY|O_WRONLY|O_RDWR) |O_APPEND|
55+
(O_RANDOM|O_SEQUENTIAL|O_TEMPORARY)|
56+
_O_SHORT_LIVED|
57+
(O_CREAT|O_TRUNC|O_EXCL) | (O_TEXT|O_BINARY)))==fileFlags);
58+
59+
sa.nLength=sizeof(sa);
60+
sa.bInheritHandle=TRUE;
61+
sa.lpSecurityDescriptor=NULL;
62+
63+
if ((h=CreateFile(fileName,
64+
/* cannot use O_RDONLY, as it == 0 */
65+
(fileFlags&O_RDWR) ? (GENERIC_WRITE |GENERIC_READ) :
66+
((fileFlags&O_WRONLY) ?GENERIC_WRITE :GENERIC_READ),
67+
(FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE),
68+
&sa,
69+
openFlagsToCreateFileFlags(fileFlags),
70+
FILE_ATTRIBUTE_NORMAL|
71+
((fileFlags&O_RANDOM)?FILE_FLAG_RANDOM_ACCESS:0) |
72+
((fileFlags&O_SEQUENTIAL)?FILE_FLAG_SEQUENTIAL_SCAN:0) |
73+
((fileFlags&_O_SHORT_LIVED)?FILE_ATTRIBUTE_TEMPORARY:0) |
74+
((fileFlags&O_TEMPORARY)?FILE_FLAG_DELETE_ON_CLOSE:0),
75+
NULL))==INVALID_HANDLE_VALUE)
76+
{
77+
switch (GetLastError())
78+
{
79+
/* EMFILE, ENFILE should not occur from CreateFile. */
80+
caseERROR_PATH_NOT_FOUND:
81+
caseERROR_FILE_NOT_FOUND:errno=ENOENT;break;
82+
caseERROR_FILE_EXISTS:errno=EEXIST;break;
83+
caseERROR_ACCESS_DENIED:errno=EACCES;break;
84+
default:
85+
errno=EINVAL;
86+
}
87+
return-1;
88+
}
89+
90+
/* _open_osfhandle will, on error, set errno accordingly */
91+
if ((fd=_open_osfhandle((long)h,fileFlags&O_APPEND))<0||
92+
(fileFlags&(O_TEXT|O_BINARY)&& (_setmode(fd,fileFlags&(O_TEXT|O_BINARY))<0)))
93+
CloseHandle(h);/* will not affect errno */
94+
returnfd;
95+
}
96+
97+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp