]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Microsoft stat() is broken (always returns nlinks==1), so use GetFileInformationByHan...
authorTim Kientzle <kientzle@gmail.com>
Mon, 7 Sep 2009 07:15:12 +0000 (03:15 -0400)
committerTim Kientzle <kientzle@gmail.com>
Mon, 7 Sep 2009 07:15:12 +0000 (03:15 -0400)
SVN-Revision: 1440

libarchive/test/main.c

index bb506341fa1ce16c467d8e4f2c26c5e306d247ba..f43d5bd683cd13f33053bbf2622d7cc96071fa25 100644 (file)
@@ -955,6 +955,27 @@ int
 assertion_file_nlinks(const char *file, int line,
     const char *pathname, int nlinks)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       HANDLE h;
+       BY_HANDLE_FILE_INFORMATION bhfi;
+       int r;
+
+       assertion_count(file, line);
+       h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL,
+               OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+       if (h == INVALID_HANDLE_VALUE) {
+               failure_start(file, line, "Can't access %s", pathname);
+               failure_finish(NULL);
+               return (0);
+       }
+       r = GetFileInformationByHandle(h, &bhfi);
+       if (r != 0 && bhfi.nNumberOfLinks == nlinks)
+               return (1);
+       failure_start(file, line, "File %s has %d links, expected %d",
+           pathname, bhfi.nNumberOfLinks, nlinks);
+       failure_finish(NULL);
+       return (0);
+#else
        struct stat st;
        int r;
 
@@ -966,6 +987,7 @@ assertion_file_nlinks(const char *file, int line,
            pathname, st.st_nlink, nlinks);
        failure_finish(NULL);
        return (0);
+#endif
 }
 
 /* Verify size of 'pathname'. */