You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/20 15:54:53 UTC

svn commit: r766694 - in /commons/sandbox/runtime/trunk/src: main/native/configure main/native/include/arch/windows/acr_arch.h main/native/include/arch/windows/acr_arch_private.h main/native/os/win32/file.c test/org/apache/commons/runtime/TestFile.java

Author: mturk
Date: Mon Apr 20 13:54:52 2009
New Revision: 766694

URL: http://svn.apache.org/viewvc?rev=766694&view=rev
Log:
Implement windows file symlink api

Modified:
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=766694&r1=766693&r2=766694&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Mon Apr 20 13:54:52 2009
@@ -392,6 +392,7 @@
     printf "Checking for %-32s" "<$1.h>" 1>&2
     cat > $test.c << EOF
 #include <stdlib.h>
+$2
 #include <$1.h>
 int main() {return 0;}
 EOF
@@ -472,6 +473,8 @@
     exit 1
 fi
 
+have_fileextd="`have_include fileextd '#include <windows.h>'`"
+
 # Generate configuration header file
 #
 cat > $topdir/include/ccconfig.h << EOF
@@ -489,6 +492,7 @@
 #define HAVE_STRING_H         `have_include string`
 #define HAVE_STRINGS_H        `have_include strings`
 #define HAVE_WINDOWS_H        `have_include windows`
+#define HAVE_FILEEXTD_H       $have_fileextd
 #define HAVE_INTTYPES_H       `have_include inttypes`
 #define HAVE_DLFCN_H          `have_include dlfcn`
 #define HAVE_LINK_H           `have_include link`
@@ -561,6 +565,9 @@
     else
         echo "not found"
     fi
+    if [ $have_fileextd = 1 ]; then
+        varadds ldflags "fileextd.lib"
+    fi
 fi
 
 sed -e "s;=@cc@;=$cc;g" \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=766694&r1=766693&r2=766694&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Mon Apr 20 13:54:52 2009
@@ -426,6 +426,17 @@
 #undef  JVM_DumpAllStacks
 #define JVM_DumpAllStacks acr_winapi_JVM_DumpAllStacks
 
+#if HAVE_FILEEXTD_H
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
+                          WINAPI, GetFileInformationByHandleEx, 0, (
+    IN  HANDLE hFile,
+    IN  FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
+    IN LPVOID lpFileInformation,
+    IN  DWORD dwBufferSize),
+    (hFile, FileInformationClass, lpFileInformation, dwBufferSize))
+#define rGetFileInformationByHandleEx acr_winapi_GetFileInformationByHandleEx
+#endif
+
 #undef ACR_WANT_LATE_DLL
 #endif /* ACR_WANT_LATE_DLL */
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=766694&r1=766693&r2=766694&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Mon Apr 20 13:54:52 2009
@@ -28,6 +28,18 @@
 #include <userenv.h>
 #include <shellapi.h>
 
+
+#if HAVE_FILEEXTD_H
+#if !defined (NTDDI_VISTA)
+#include <fileextd.h>
+#define HAVE_FILEEXTD_LIB   1
+#endif
+#elif defined (NTDDI_VISTA)
+#undef HAVE_FILEEXTD_H
+#define HAVE_FILEEXTD_H     1
+#define HAVE_FILEEXTD_LIB   0
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=766694&r1=766693&r2=766694&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Mon Apr 20 13:54:52 2009
@@ -16,11 +16,13 @@
 
 #include "acr.h"
 #include "acr_private.h"
-#include "acr_arch.h"
 #include "acr_error.h"
 #include "acr_string.h"
 #include "acr_file.h"
 
+#define ACR_WANT_LATE_DLL
+#include "acr_arch.h"
+
 /**
  * Win32 file functions
  *
@@ -98,3 +100,58 @@
 
     return type;
 }
+
+ACR_JNI_EXPORT_DECLARE(jboolean, io_File, mkslink0)(ACR_JNISTDARGS,
+                                                    jstring target,
+                                                    jstring lnkname)
+{
+    jboolean rc = JNI_FALSE;
+
+    UNREFERENCED_O;
+    if (!ACR_HAVE_LATE_DLL_FUNC(CreateSymbolicLinkW)) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTIMPL, 0);
+        return JNI_FALSE;
+    }
+    WITH_WSTR(target) {
+    WITH_WSTR(lnkname) {
+        DWORD dwFlags = 0;
+        if (J2W(target)[wcslen(J2W(target))] == L'\\')
+            dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORORY;
+        if (CreateSymbolicLinkW(J2W(lnkname), J2W(target), dwFlags)) {
+            int err = ACR_GET_OS_ERROR();
+            if (ACR_STATUS_IS_EACCES(err))
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+            else if (!ACR_STATUS_IS_EEXIST(err)) {
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, err);
+            }
+        }
+        else
+            rc = JNI_TRUE;
+    } END_WITH_WSTR(lnkname);
+    } END_WITH_WSTR(target);
+
+    return rc;
+}
+
+ACR_JNI_EXPORT_DECLARE(jstring, io_File, target0)(ACR_JNISTDARGS,
+                                                  jstring lnkname)
+{
+    jstring rv = NULL;
+    int slib = 0;
+    UNREFERENCED_O;
+#if HAVE_FILEEXTD_H
+    if (!ACR_HAVE_LATE_DLL_FUNC(GetFileInformationByHandleEx)) {
+#if HAVE_FILEEXTD_LIB
+        slib = 1;
+#else
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTIMPL, 0);
+#endif
+    }
+    WITH_WSTR(lnkname) {
+
+    } END_WITH_WSTR(lnkname);
+#else
+    ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTIMPL, 0);
+#endif
+    return rv;
+}

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java?rev=766694&r1=766693&r2=766694&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Mon Apr 20 13:54:52 2009
@@ -71,61 +71,77 @@
     public void testMakeSymlink()
         throws Exception
     {
-        File target = new File("foo");
-        File symlnk = target.createSymbolicLink("bar");
-        FileType t = symlnk.getFileType();
-        assertEquals("Name", "bar", symlnk.getPath());
-        assertEquals("Type", FileType.LNK, t);
-        symlnk.delete();
+        try {
+            File target = new File("foo");
+            File symlnk = target.createSymbolicLink("bar");
+            FileType t = symlnk.getFileType();
+            assertEquals("Name", "bar", symlnk.getPath());
+            assertEquals("Type", FileType.LNK, t);
+            symlnk.delete();
+        } catch (UnsupportedOperationException u) {
+            // fail("Unsupported Operating system");
+        }
     }
 
     public void testReadSymlink()
         throws Exception
     {
-        File target = new File("foo");
-        File symlnk = target.createSymbolicLink("bar");
-        FileType t = symlnk.getFileType();
-        assertEquals("Name", "bar", symlnk.getPath());
-        assertEquals("Type", FileType.LNK, t);
-        File second = new File("foo");
-        File link2 = second.createSymbolicLink("bar");
-        assertEquals("Name", "bar", link2.getPath());
-
-        symlnk.delete();
+        try {
+            File target = new File("foo");
+            File symlnk = target.createSymbolicLink("bar");
+            FileType t = symlnk.getFileType();
+            assertEquals("Name", "bar", symlnk.getPath());
+            assertEquals("Type", FileType.LNK, t);
+            File second = new File("foo");
+            File link2 = second.createSymbolicLink("bar");
+            assertEquals("Name", "bar", link2.getPath());
+    
+            symlnk.delete();
+        } catch (UnsupportedOperationException u) {
+            // fail("Unsupported Operating system");            
+        }
 
     }
 
     public void testReadSymlinkExists()
         throws Exception
     {
-        File target = new File("foo");
-        File symlnk = target.createSymbolicLink("bar");
-        FileType t = symlnk.getFileType();
-        assertEquals("Name", "bar", symlnk.getPath());
-        assertEquals("Type", FileType.LNK, t);
-        File second = new File("foo2");
         try {
-            File link2 = second.createSymbolicLink("bar");
-            fail("Exception not thrown");
-        } catch (Exception ex) {
-            // This is expected 
-        } finally {        
-            symlnk.delete();
+            File target = new File("foo");
+            File symlnk = target.createSymbolicLink("bar");
+            FileType t = symlnk.getFileType();
+            assertEquals("Name", "bar", symlnk.getPath());
+            assertEquals("Type", FileType.LNK, t);
+            File second = new File("foo2");
+            try {
+                File link2 = second.createSymbolicLink("bar");
+                fail("Exception not thrown");
+            } catch (Exception ex) {
+                // This is expected 
+            } finally {        
+                symlnk.delete();
+            }
+        } catch (UnsupportedOperationException u) {
+            // fail("Unsupported Operating system");            
         }
     }
 
     public void testGetTarget()
         throws Exception
     {
-        File source = new File("foo");
-        File symlnk = source.createSymbolicLink("bar");
-        FileType t = symlnk.getFileType();
-        assertEquals("Name", "bar", symlnk.getPath());
-        assertEquals("Type", FileType.LNK, t);
-        File target = symlnk.getTargetFile();
-        assertEquals("Target", source.getPath(), target.getPath());
-
-        symlnk.delete();
+        try {
+            File source = new File("foo");
+            File symlnk = source.createSymbolicLink("bar");
+            FileType t = symlnk.getFileType();
+            assertEquals("Name", "bar", symlnk.getPath());
+            assertEquals("Type", FileType.LNK, t);
+            File target = symlnk.getTargetFile();
+            assertEquals("Target", source.getPath(), target.getPath());
+    
+            symlnk.delete();
+        } catch (UnsupportedOperationException u) {
+            // fail("Unsupported Operating system");            
+        }
 
     }