[PATCH V2 RESEND] win32: improve the performance of win32.unlink() over CIFS

Kaz Nishimura kazssym at vx68k.org
Thu Feb 20 21:54:27 CST 2014


I have confirmed with the following test program that exclusive open
actually denies deletion of a hard link to the same file.

This program just (1) creates normal file foo, (2) creates hard link bar
for foo, (3) opens foo for deletion, (4) waits for input, and (5) close the
handle returned in (3).  I checked if I could delete bar at (4).

If I changed the share mode to FILE_SHARE_DELETE, deletion and rename of
bar is not denied.  I am not sure if it is OK with that share mode to
delete a file name immediately.

#include <windows.h>
#include <cstdio>
using namespace std;

//#define SHARE_MODE 0
#define SHARE_MODE FILE_SHARE_DELETE

int main(void) {
    HANDLE fh = CreateFile("foo", GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (fh == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "%s: CreateFile failed (error = %lu)\n", "foo",
                GetLastError());
        return 1;
    }
    CloseHandle(fh);

    if (!CreateHardLink("bar", "foo", NULL)) {
        fprintf(stderr, "%s: CreateHardLink failed (error = %lu)\n", "bar",
                GetLastError());
        return 1;
    }

    fh = CreateFile("foo", DELETE, SHARE_MODE, NULL, OPEN_EXISTING,
            FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_DELETE_ON_CLOSE, NULL);
    if (fh == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "%s: CreateFile failed (error = %lu)\n", "foo",
                GetLastError());
    }

    printf("foo is now open\n");

    char line[80];
    fgets(line, 80, stdin);

    CloseHandle(fh);
    return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20140221/9372dbe0/attachment.html>


More information about the Mercurial-devel mailing list