commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r824034 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/ native/include/ native/include/arch/unix/ native/os/unix/ native/os/win32/ native/shared/
Date Sun, 11 Oct 2009 07:29:58 GMT
Author: mturk
Date: Sun Oct 11 07:29:57 2009
New Revision: 824034

URL: http://svn.apache.org/viewvc?rev=824034&view=rev
Log:
Implement posix FileInfo and Directory

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInfo.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Sun
Oct 11 07:29:57 2009
@@ -63,7 +63,9 @@
                                         throws IOException, SecurityException;
     private static native String    tmpdir1(String srchpath)
                                         throws SecurityException;
-
+    private static native FileInfo  stat0(String pathname, boolean link,
+                                          boolean full)
+                                        throws IOException, SecurityException;
     // Cached FileType Enum integer value.
     private int fileType = -1;
 
@@ -612,5 +614,33 @@
         return inode0(getPath());
     }
 
+    /**
+     * Create new FileInfo object from this abstract {@code File} path.
+     * <p>
+     * If this abstract {@code File} points to a symbolic link the
+     * returned {@code FiInfo} object constains information about
+     * that symbolic link rather then to the actual file. If the file
+     * type for this abstract {@code File} wasn't determined jet, the
+     * returned {@code FileInfo} object will always contain information
+     * about symbolic link if this file points to symbolic link.
+     * <p>
+     *
+     * @return mew {@code FileInfo} object.
+     * @throws SecurityException if search permission is denied for a
+     *         component of this abstract {@code File} pathname prefix.
+     * @throws IOException if some other I/O error occured.
+     * @see FileInfo
+     */
+    public FileInfo stat()
+        throws IOException, SecurityException
+    {
+        boolean link = false;
+        /* #6 is ACR_FT_LNK declared inside acr_file.h
+         * Make sure those values are in sync
+         */
+        if (fileType == -1 || fileType == 6)
+            link = true;
+        return stat0(getPath(), link, true);
+    }
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInfo.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInfo.java?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInfo.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInfo.java
Sun Oct 11 07:29:57 2009
@@ -16,6 +16,7 @@
 
 package org.apache.commons.runtime.io;
 
+import java.io.IOException;
 import java.util.EnumSet;
 import org.apache.commons.runtime.Descriptor;
 import org.apache.commons.runtime.Group;
@@ -28,15 +29,35 @@
 public final class FileInfo
 {
 
-    private FileInfo()
+    private FileInfo(int ftype)
     {
-        // Created from native
+        setType(ftype);
     }
+
+    private FileInfo(String Name, int ftype)
+    {
+        this.Name = Name;
+        setType(ftype);
+    }
+
     private void setType(int ftype)
     {
         Type = FileType.valueOf(ftype);
     }
 
+    private native int stat0(boolean link);
+    /**
+     * Update FileInfo
+     */
+    public void update()
+        throws IOException
+    {
+        int rc = stat0(Type == Type.LNK);
+        if (rc != 0) {
+            throw new IOException(Status.describe(rc));
+        }
+    }
+
     /** The access permissions of the file.  Mimics Unix access rights. */
     public int      Protection;
     /**

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java
Sun Oct 11 07:29:57 2009
@@ -139,6 +139,19 @@
         return FileType.valueOf(ftype0(fd.fd()));
     }
 
+    private static native FileInfo stat0(int fd, boolean full)
+        throws IOException, SecurityException;
+    /**
+     * Return new {@link FileInfo} object.
+     */
+    private static FileInfo stat(Descriptor fd)
+        throws IOException, SecurityException
+    {
+        if (!fd.valid())
+            throw new ClosedDescriptorException();
+        return stat0(fd.fd(), true);
+    }
+
     private static native Descriptor open0(String path, int mode)
         throws FileNotFoundException, IOException, SecurityException;
     /**

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h Sun Oct 11 07:29:57
2009
@@ -42,6 +42,7 @@
 #define ACR_DT_DSO              0x00000008
 #define ACR_DT_SEMAPHORE        0x00000009
 #define ACR_DT_MMAP             0x0000000A
+#define ACR_DT_DIR              0x0000000B
 #define ACR_DT_MASK             0x000000FF
 
 typedef enum {

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h Sun Oct 11 07:29:57 2009
@@ -293,6 +293,13 @@
  */
 ACR_DECLARE(const acr_pchar_t *) ACR_FileNameGet(JNIEnv *env, int fd);
 
+/** Create new FileInfo object.
+ * @param env JNI environment to use.
+ * @param fname FileInfo.Name field.
+ * @param type  FileInfo.Type field.
+ */
+ACR_DECLARE(jobject) ACR_NewFileInfoObject(JNIEnv *env,
+                                           const acr_pchar_t *fname, int type);
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Sun Oct 11
07:29:57 2009
@@ -248,6 +248,11 @@
  */
 char *acr_GetAbsolutePath(JNIEnv *env, const char *path);
 
+/**
+ * Translate mode_t to ACR flags
+ */
+int     ACR_UnixModeToPerms(mode_t);
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c Sun Oct 11 07:29:57 2009
@@ -24,9 +24,278 @@
 #include "acr_file.h"
 #include "acr_port.h"
 
+#include <sys/types.h>
+#include <dirent.h>
+
 /**
- * Posix file info functions
+ * Posix directory functions
  *
  */
-extern mode_t acr_default_umask;
-extern mode_t acr_default_perms;
+
+static int descriptor_cleanup(ACR_JNISTDARGS,
+                              acr_descriptor_cb_type_e cm,
+                              acr_descriptor_cb_t *dp)
+{
+    int rc = ACR_SUCCESS;
+    switch (cm) {
+        case ACR_DESC_FINALIZE:
+        case ACR_DESC_CLOSE:
+            if (dp->dp != NULL) {
+                if (closedir((DIR *)dp->dp))
+                    rc = ACR_GET_OS_ERROR();
+            }
+            else
+                rc = ACR_EBADF;
+        break;
+        default:
+            rc = ACR_ENOTIMPL;
+        break;
+    }
+    return rc;
+}
+
+ACR_IO_EXPORT_DECLARE(jobject, Directory, open0)(ACR_JNISTDARGS, jstring name)
+{
+    DIR     *dir;
+    jobject  dd = NULL;
+    int      rc = 0;
+
+    WITH_CSTR(name) {
+        if ((dir = opendir(J2S(name)))) {
+            dd = ACR_DescriptorCreate(_E, ACR_DT_DIR, -1, dir,
+                                      descriptor_cleanup);
+        }
+        else
+            rc = ACR_GET_OS_ERROR();
+    } END_WITH_CSTR(name);
+    ACR_THROW_IO_IF_ERR(rc);
+    return dd;
+}
+
+ACR_IO_EXPORT_DECLARE(jstring, Directory, read0)(ACR_JNISTDARGS, jobject dd)
+{
+    DIR     *dir;
+    int      rc = 0;
+    jstring  rv = NULL;
+
+    dir = (DIR *)ACR_DescriptorGetPtr(_E, dd);
+    if (dir) {
+        struct dirent  ds;
+        struct dirent *dp;
+        for (;;) {
+            if (!readdir_r(dir, &ds, &dp)) {
+                if (dp) {
+                    if (*(dp->d_name) == '.' && (*(dp->d_name + 1) == '\0'
||
+                                                (*(dp->d_name + 1) == '.'  &&
+                                                 *(dp->d_name + 2) == '\0'))) {
+                        /* Skip . and .. directory entires
+                         */
+                        continue;
+                    }
+                    /* Not at end of dir */
+                    rv = ACR_NewJavaStringA(_E, dp->d_name);
+                }
+                else
+                    break;
+            }
+            else {
+                /* readdir_r failed */
+                rc = ACR_GET_OS_ERROR();
+                break;
+            }
+        }
+    }
+    ACR_THROW_IO_IF_ERR(rc);
+    return rv;
+}
+
+ACR_IO_EXPORT_DECLARE(jobject, Directory, read1)(ACR_JNISTDARGS, jobject dd)
+{
+    DIR     *dir;
+    int      rc = 0;
+    jobject  rv = NULL;
+
+    dir = (DIR *)ACR_DescriptorGetPtr(_E, dd);
+    if (dir) {
+        struct dirent  ds;
+        struct dirent *dp;
+        for (;;) {
+            if (!readdir_r(dir, &ds, &dp)) {
+                if (dp) {
+                    int type;
+                    if (*(dp->d_name) == '.' && (*(dp->d_name + 1) == '\0'
||
+                                                (*(dp->d_name + 1) == '.'  &&
+                                                 *(dp->d_name + 2) == '\0'))) {
+                        /* Skip . and .. directory entires
+                         */
+                        continue;
+                    }
+                    /* Determine the type of the enty
+                     */
+                    switch (dp->d_type) {
+                        case DT_BLK:
+                            type = ACR_FT_BLK;   break;
+                        case DT_CHR:
+                            type = ACR_FT_CHR;   break;
+                        case DT_DIR:
+                            type = ACR_FT_BLK;   break;
+                        case DT_FIFO:
+                            type = ACR_FT_PIPE;  break;
+                        case DT_LNK:
+                            type = ACR_FT_LNK;   break;
+                        case DT_REG:
+                            type = ACR_FT_REG;   break;
+                        case DT_SOCK:
+                            type = ACR_FT_SOCK;  break;
+                        default:
+                            type = ACR_FT_UNKFILE;
+                        break;
+                    }
+                    rv = ACR_NewFileInfoObject(_E, dp->d_name, type);
+                }
+                else
+                    break;
+            }
+            else {
+                /* readdir_r failed */
+                rc = ACR_GET_OS_ERROR();
+                break;
+            }
+        }
+    }
+    ACR_THROW_IO_IF_ERR(rc);
+    return rv;
+}
+
+ACR_IO_EXPORT_DECLARE(void, Directory, rewind0)(ACR_JNISTDARGS, jobject dd)
+{
+    DIR     *dir;
+    if (( dir = (DIR *)ACR_DescriptorGetPtr(_E, dd))) {
+        rewinddir(dir);
+    }
+}
+
+ACR_IO_EXPORT_DECLARE(jlong, Directory, tell0)(ACR_JNISTDARGS, jobject dd)
+{
+    DIR     *dir;
+    off_t    pos = -1;
+    int      rc  =  0;
+
+    if (( dir = (DIR *)ACR_DescriptorGetPtr(_E, dd))) {
+        pos = telldir(dir);
+        if (pos == -1)
+            rc = ACR_GET_OS_ERROR();
+    }
+    else
+        rc = ACR_EBADF;
+    ACR_THROW_IO_IF_ERR(rc);
+    return (jlong)pos;
+}
+
+ACR_IO_EXPORT_DECLARE(void, Directory, seek0)(ACR_JNISTDARGS, jobject dd,
+                                              jlong off)
+{
+    DIR     *dir;
+
+    if (( dir = (DIR *)ACR_DescriptorGetPtr(_E, dd))) {
+        seekdir(dir, (off_t)off);
+    }
+}
+
+static int _mkdir0(const char *name, int perms)
+{
+    if (mkdir(name, ACR_UnixPermsToMode(perms)) == 0)
+        return 0;
+    else
+        return ACR_GET_OS_ERROR();
+}
+
+static int _mkdir1(const char *name, int perms)
+{
+    int rc;
+
+    rc = _mkdir0(name, perms);
+    if (rc == ACR_EEXIST)
+        return 0;
+    if (rc == ACR_ENOENT) {  /* Missing an intermediate dir */
+        char *pos;
+        char *dir = ACR_StrdupA(INVALID_HANDLE_VALUE, THROW_NMARK, name);
+        if (!dir)
+            return ACR_ENOMEM;
+        if ((pos = strrchr(dir, '/'))) {
+            *pos = '\0';
+            if (*dir) {
+                rc = _mkdir1(dir, perms);
+            }
+        }
+        x_free(dir);
+    }
+    return rc;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, Directory, mkdir0)(ACR_JNISTDARGS, jstring name,
+                                               jint perms)
+{
+    int      rc = 0;
+
+    WITH_CSTR(name) {
+        rc = _mkdir0(J2S(name), perms);
+    } END_WITH_CSTR(name);
+    return rc;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, Directory, mkdir1)(ACR_JNISTDARGS, jstring name,
+                                               jint perms)
+{
+    int      rc = 0;
+
+    WITH_CSTR(name) {
+        rc = _mkdir1(J2S(name), perms);
+    } END_WITH_CSTR(name);
+    return rc;
+}
+
+ACR_IO_EXPORT_DECLARE(jstring, Directory, tmpdir0)(ACR_JNISTDARGS, jstring path,
+                                                   jstring prefix)
+{
+    int   rc   = 0;
+    char *tmpd = NULL;
+
+    UNREFERENCED_O;
+
+    WITH_ZCSTR(path) {
+    WITH_ZCSTR(prefix) {
+        /* Provide INVALID_HANDLE_VALUE for JNIEnv
+         * so that in case of failure, exception doesn't get thrown
+         */
+        tmpd = ACR_TempDirMake(INVALID_HANDLE_VALUE, J2S(path), J2S(prefix));
+        if (!tmpd)
+            rc = ACR_GET_OS_ERROR();
+    } END_WITH_CSTR(prefix);
+    } END_WITH_CSTR(path);
+    if (rc) {
+        ACR_THROW_IO_IF_ERR(rc);
+        return NULL;
+    }
+    else {
+        jstring rv = ACR_NewJavaStringA(_E, tmpd);
+        x_free(tmpd);
+        return rv;
+    }
+}
+
+ACR_IO_EXPORT_DECLARE(jstring, Directory, tmpdir1)(ACR_JNISTDARGS,
+                                                   jstring paths)
+{
+    const char *tmpd = NULL;
+
+    UNREFERENCED_O;
+
+    WITH_ZCSTR(paths) {
+        tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2S(paths));
+    } END_WITH_CSTR(paths);
+    if (tmpd)
+        return ACR_NewJavaStringA(_E, tmpd);
+    else
+        return NULL;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c Sun Oct 11 07:29:57 2009
@@ -17,12 +17,13 @@
 #include "acr.h"
 #include "acr_private.h"
 #include "acr_arch.h"
+#include "acr_clazz.h"
+#include "acr_descriptor.h"
 #include "acr_port.h"
 #include "acr_error.h"
 #include "acr_string.h"
-#include "acr_descriptor.h"
+#include "acr_users.h"
 #include "acr_file.h"
-#include "acr_port.h"
 
 /**
  * Posix file info functions
@@ -30,3 +31,337 @@
  */
 extern mode_t acr_default_umask;
 extern mode_t acr_default_perms;
+
+J_DECLARE_CLAZZ = {
+    NULL,
+    NULL,
+    ACR_IO_CLASS_PATH "FileInfo"
+};
+
+J_DECLARE_F_ID(0000) = {
+    NULL,
+    "Protection",
+    "I"
+};
+
+J_DECLARE_F_ID(0001) = {
+    NULL,
+    "User",
+    "L" ACR_CLASS_PATH "User;"
+};
+
+J_DECLARE_F_ID(0002) = {
+    NULL,
+    "Group",
+    "L" ACR_CLASS_PATH "Group;"
+};
+
+J_DECLARE_F_ID(0003) = {
+    NULL,
+    "NumLinks",
+    "I"
+};
+
+J_DECLARE_F_ID(0004) = {
+    NULL,
+    "Size",
+    "J"
+};
+
+J_DECLARE_F_ID(0005) = {
+    NULL,
+    "StorageSize",
+    "J"
+};
+
+J_DECLARE_F_ID(0006) = {
+    NULL,
+    "LastAccessTime",
+    "J"
+};
+
+J_DECLARE_F_ID(0007) = {
+    NULL,
+    "ModifiedTime",
+    "J"
+};
+
+J_DECLARE_F_ID(0008) = {
+    NULL,
+    "CreatedTime",
+    "J"
+};
+
+J_DECLARE_F_ID(0009) = {
+    NULL,
+    "Name",
+    "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0010) = {
+    NULL,
+    "BaseName",
+    "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0011) = {
+    NULL,
+    "InodeId",
+    "J"
+};
+
+J_DECLARE_F_ID(0012) = {
+    NULL,
+    "DeviceId",
+    "J"
+};
+
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "<init>",
+    "(I)V"
+};
+
+J_DECLARE_M_ID(0001) = {
+    NULL,
+    "<init>",
+    "(Ljava/lang/String;I)V"
+};
+
+J_DECLARE_M_ID(0002) = {
+    NULL,
+    "setType",
+    "(I)V"
+};
+
+ACR_CLASS_LDEF(io_FileInfo)
+{
+    int rv;
+
+    if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+        return rv;
+    J_LOAD_IFIELD(0000);
+    J_LOAD_IFIELD(0001);
+    J_LOAD_IFIELD(0002);
+    J_LOAD_IFIELD(0003);
+    J_LOAD_IFIELD(0004);
+    J_LOAD_IFIELD(0005);
+    J_LOAD_IFIELD(0006);
+    J_LOAD_IFIELD(0007);
+    J_LOAD_IFIELD(0008);
+    J_LOAD_IFIELD(0009);
+    J_LOAD_IFIELD(0010);
+    J_LOAD_IFIELD(0011);
+    J_LOAD_IFIELD(0012);
+    J_LOAD_METHOD(0000);
+    J_LOAD_METHOD(0001);
+    J_LOAD_METHOD(0002);
+
+    return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(io_FileInfo)
+{
+    ACR_UnloadClass(_E, &_clazzn);
+}
+
+ACR_DECLARE(jobject) ACR_NewFileInfoObject(JNIEnv *_E, const char *fname,
+                                           int type)
+{
+    jstring name;
+    if ((name = ACR_NewJavaStringA(_E, fname)))
+        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), type);
+    else
+        return NULL;
+}
+
+static void _fill0(ACR_JNISTDARGS, struct_stat_t *info, jboolean full)
+{
+    SET_IFIELD_I(0000, _O, ACR_UnixModeToPerms(info->st_mode));
+    if (full) {
+        SET_IFIELD_O(0001, _O, ACR_UserObjectCreateFromId(_E,  info->st_uid));
+        SET_IFIELD_O(0002, _O, ACR_GroupObjectCreateFromId(_E, info->st_gid));
+    }
+    SET_IFIELD_I(0003, _O, info->st_nlink);
+    SET_IFIELD_J(0004, _O, info->st_size);
+    /* TODO: Some platforms lack the st_blocks member
+     */
+#ifdef DEV_BSIZE
+    SET_IFIELD_J(0005, _O, (info->st_blocks * (jlong)DEV_BSIZE));
+#else
+    SET_IFIELD_J(0005, _O, (info->st_blocks * (jlong)512));
+#endif
+    SET_IFIELD_J(0006, _O, info->st_atime);
+    SET_IFIELD_J(0007, _O, info->st_mtime);
+    SET_IFIELD_J(0008, _O, info->st_ctime);
+    SET_IFIELD_J(0011, _O, info->st_ino);
+    SET_IFIELD_J(0012, _O, info->st_dev);
+}
+
+static int _ftype0(struct_stat_t *info)
+{
+    int type = 0;
+    switch (info->st_mode & S_IFMT) {
+        case S_IFREG:
+            type = ACR_FT_REG;  break;
+        case S_IFDIR:
+            type = ACR_FT_DIR;  break;
+        case S_IFLNK:
+            type = ACR_FT_LNK;  break;
+        case S_IFCHR:
+            type = ACR_FT_CHR;  break;
+        case S_IFBLK:
+            type = ACR_FT_BLK;  break;
+#if defined(S_IFFIFO)
+        case S_IFFIFO:
+            type = ACR_FT_PIPE; break;
+#endif
+#if defined(S_IFSOCK)
+        case S_IFSOCK:
+            type = ACR_FT_SOCK; break;
+#endif
+
+        default:
+        /* Work around missing S_IFxxx values above
+            * for Linux et al.
+            */
+#if !defined(S_IFFIFO) && defined(S_ISFIFO)
+            if (S_ISFIFO(info->st_mode)) {
+                type = ACR_FT_PIPE;
+            } else
+#endif
+#if !defined(S_IFSOCK) && defined(S_ISSOCK)
+            if (S_ISSOCK(info->st_mode)) {
+                type = ACR_FT_SOCK;
+            } else
+#endif
+            type = ACR_FT_UNKFILE;
+        break;
+    }
+    return type;
+}
+
+static jobject _stat0(JNIEnv *_E, const char *fname,
+                      jboolean link, jboolean full)
+{
+    jobject fi;
+    struct_stat_t info;
+    int   rc = 0;
+    int   type;
+
+    if (link)
+        rc = lstat(fname, &info);
+    else
+        rc =  stat(fname, &info);
+    if (rc < 0) {
+        ACR_THROW_IO_ERRNO();
+        return NULL;
+    }
+    type = _ftype0(&info);
+
+    fi = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), type);
+    if (!fi) {
+
+        return NULL;
+    }
+    if (full) {
+        char  path[PATH_MAX];
+        char *name = acr_GetAbsolutePath(_E, fname);
+        SET_IFIELD_S(0009, fi, name);
+        x_free(name);
+        name = basename_r(fname, path, PATH_MAX);
+        SET_IFIELD_S(0010, fi, name);
+    }
+    _fill0(_E, fi, &info, full);
+
+    return fi;
+}
+
+static jobject _stat1(JNIEnv *_E, int file, jboolean full)
+{
+    jobject fi;
+    struct_stat_t info;
+    int   type;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_IO_IF_ERR(ACR_EFTYPE);
+        return NULL;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_IO_IF_ERR(ACR_EBADF);
+        return NULL;
+    }
+    if (fstat(f->fd, &info) < 0) {
+        ACR_THROW_IO_ERRNO();
+        return NULL;
+    }
+    type = _ftype0(&info);
+
+    fi = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), type);
+    if (!fi) {
+
+        return NULL;
+    }
+    if (full) {
+        char  path[PATH_MAX];
+        char *name;
+        SET_IFIELD_S(0009, fi, f->name);
+        name = basename_r(f->name, path, PATH_MAX);
+        SET_IFIELD_S(0010, fi, name);
+    }
+    _fill0(_E, fi, &info, full);
+
+    return fi;
+}
+
+static int _stat2(ACR_JNISTDARGS, const char *fname, jboolean link)
+{
+    struct_stat_t info;
+    int   rc = 0;
+    int   type;
+
+    if (link)
+        rc = lstat(fname, &info);
+    else
+        rc =  stat(fname, &info);
+    if (rc < 0)
+        return ACR_GET_OS_ERROR();
+    type = _ftype0(&info);
+    CALL_VMETHOD1(0002, _O, type);
+    _fill0(_E, _O, &info, JNI_TRUE);
+
+    return 0;
+}
+
+ACR_IO_EXPORT_DECLARE(jobject, File, stat0)(ACR_JNISTDARGS,
+                                            jstring fname,
+                                            jboolean link,
+                                            jboolean full)
+{
+    jobject fi = NULL;
+    WITH_CSTR(fname) {
+        fi = _stat0(_E, J2S(fname), link, full);
+    } END_WITH_CSTR(fname);
+
+    return fi;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileInfo, stat0)(ACR_JNISTDARGS,
+                                             jstring fname,
+                                             jboolean link)
+{
+    int rc = 0;
+    WITH_CSTR(fname) {
+        rc = _stat2(_E, _O, J2S(fname), link);
+    } END_WITH_CSTR(fname);
+
+    return rc;
+}
+
+ACR_IO_EXPORT_DECLARE(jobject, FileWrapper, stat0)(ACR_JNISTDARGS,
+                                                   jint fd,
+                                                   jboolean full)
+{
+    return  _stat1(_E, fd, full);
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c Sun Oct 11 07:29:57 2009
@@ -28,3 +28,129 @@
  * Windows file info functions
  *
  */
+
+J_DECLARE_CLAZZ = {
+    NULL,
+    NULL,
+    ACR_IO_CLASS_PATH "FileInfo"
+};
+
+J_DECLARE_F_ID(0000) = {
+    NULL,
+    "Protection",
+    "I"
+};
+
+J_DECLARE_F_ID(0001) = {
+    NULL,
+    "User",
+    "L" ACR_CLASS_PATH "User;"
+};
+
+J_DECLARE_F_ID(0002) = {
+    NULL,
+    "Group",
+    "L" ACR_CLASS_PATH "Group;"
+};
+
+J_DECLARE_F_ID(0003) = {
+    NULL,
+    "NumLinks",
+    "I"
+};
+
+J_DECLARE_F_ID(0004) = {
+    NULL,
+    "Size",
+    "J"
+};
+
+J_DECLARE_F_ID(0005) = {
+    NULL,
+    "StorageSize",
+    "J"
+};
+
+J_DECLARE_F_ID(0006) = {
+    NULL,
+    "LastAccessTime",
+    "J"
+};
+
+J_DECLARE_F_ID(0007) = {
+    NULL,
+    "ModifiedTime",
+    "J"
+};
+
+J_DECLARE_F_ID(0008) = {
+    NULL,
+    "CreatedTime",
+    "J"
+};
+
+J_DECLARE_F_ID(0009) = {
+    NULL,
+    "Name",
+    "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0010) = {
+    NULL,
+    "BaseName",
+    "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0011) = {
+    NULL,
+    "InodeId",
+    "J"
+};
+
+J_DECLARE_F_ID(0012) = {
+    NULL,
+    "DeviceId",
+    "J"
+};
+
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "<init>",
+    "(I)V"
+};
+
+J_DECLARE_M_ID(0001) = {
+    NULL,
+    "setType",
+    "(I)V"
+};
+
+ACR_CLASS_LDEF(io_FileInfo)
+{
+    int rv;
+
+    if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+        return rv;
+    J_LOAD_IFIELD(0000);
+    J_LOAD_IFIELD(0001);
+    J_LOAD_IFIELD(0002);
+    J_LOAD_IFIELD(0003);
+    J_LOAD_IFIELD(0004);
+    J_LOAD_IFIELD(0005);
+    J_LOAD_IFIELD(0006);
+    J_LOAD_IFIELD(0007);
+    J_LOAD_IFIELD(0008);
+    J_LOAD_IFIELD(0009);
+    J_LOAD_IFIELD(0010);
+    J_LOAD_IFIELD(0011);
+    J_LOAD_IFIELD(0012);
+    J_LOAD_METHOD(0000);
+    J_LOAD_METHOD(0001);
+
+    return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(io_FileInfo)
+{
+    ACR_UnloadClass(_E, &_clazzn);
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=824034&r1=824033&r2=824034&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Sun Oct 11 07:29:57 2009
@@ -386,6 +386,7 @@
 ACR_CLASS_LDEC(Semaphore);
 ACR_CLASS_LDEC(SharedMemory);
 ACR_CLASS_LDEC(io_File);
+ACR_CLASS_LDEC(io_FileInfo);
 ACR_CLASS_LDEC(io_MemoryMapProvider);
 
 ACR_DECLARE(int) ACR_LoadRuntimeClasses(JNIEnv *_E)
@@ -403,6 +404,7 @@
     ACR_CLASS_LRUN(Semaphore);
     ACR_CLASS_LRUN(SharedMemory);
     ACR_CLASS_LRUN(io_File);
+    ACR_CLASS_LRUN(io_FileInfo);
     ACR_CLASS_LRUN(io_MemoryMapProvider);
 #ifdef WIN32
 
@@ -426,6 +428,7 @@
     ACR_CLASS_URUN(Semaphore);
     ACR_CLASS_URUN(SharedMemory);
     ACR_CLASS_URUN(io_File);
+    ACR_CLASS_URUN(io_FileInfo);
     ACR_CLASS_URUN(io_MemoryMapProvider);
 #ifdef WIN32
 



Mime
View raw message