commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r826182 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/ native/include/ native/os/unix/ native/os/win32/
Date Sat, 17 Oct 2009 07:08:30 GMT
Author: mturk
Date: Sat Oct 17 07:08:29 2009
New Revision: 826182

URL: http://svn.apache.org/viewvc?rev=826182&view=rev
Log:
Fix directory and file info

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInfo.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_file.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/dir.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java?rev=826182&r1=826181&r2=826182&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java
Sat Oct 17 07:08:29 2009
@@ -40,6 +40,7 @@
     /* Directory descriptor object
      */
     private Descriptor dd;
+    private String     path;
 
     /**
      * Close this file.
@@ -60,15 +61,35 @@
     public Directory(File path)
         throws FileNotFoundException, IOException, SecurityException
     {
-        dd = open0(path.getPath());
+        this.path = path.getPath();
+        dd = open0(this.path);
     }
 
     private static native FileInfo read1(Descriptor dd)
         throws IOException;
+
+    /**
+     * Read directory entry.
+     */
+    public FileInfo read(boolean resolve)
+        throws IOException
+    {
+        FileInfo info = read1(dd);
+        if (info != null) {
+            info.Path = path;
+            if (resolve)
+                info.update();
+        }
+        return info;
+    }
+
+    /**
+     * Read directory entry.
+     */
     public FileInfo read()
         throws IOException
     {
-        return read1(dd);
+        return read(false);
     }
 
     private static native void rewind0(Descriptor dd);

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=826182&r1=826181&r2=826182&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
Sat Oct 17 07:08:29 2009
@@ -34,10 +34,10 @@
         setType(ftype);
     }
 
-    private FileInfo(String Name, int ftype)
+    private FileInfo(String name)
     {
-        this.Name = Name;
-        setType(ftype);
+        Name = name;
+        Type = FileType.NOFILE;
     }
 
     private void setType(int ftype)
@@ -45,14 +45,19 @@
         Type = FileType.valueOf(ftype);
     }
 
-    private native int stat0(boolean link);
+    private native int stat0(String fname);
     /**
      * Update FileInfo
      */
     public void update()
         throws IOException
     {
-        int rc = stat0(Type == Type.LNK);
+        String fname;
+        if (Path != null)
+            fname = Path + File.pathSeparator + Name;
+        else
+            fname = Name;
+        int rc = stat0(fname);
         if (rc != 0) {
             throw new IOException(Status.describe(rc));
         }
@@ -99,11 +104,11 @@
     /**
      * The pathname of the file (possibly unrooted)
      */
-    public String   Name;
+    public String   Path;
     /**
      * The file's name (no path) in filesystem case
      */
-    public String   BaseName;
+    public String   Name;
      /**
       * The inode of the file.
       */

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=826182&r1=826181&r2=826182&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 Sat Oct 17 07:08:29 2009
@@ -293,16 +293,17 @@
  */
 ACR_DECLARE(const acr_pchar_t *) ACR_FileNameGet(JNIEnv *env, int fd);
 
-/** Create new FileInfo object.
+/** Create new FileInfo object. Ansi version.
  * @param env JNI environment to use.
  * @param fname FileInfo.Name field.
- * @param type  FileInfo.Type field.
  */
-ACR_DECLARE(jobject) ACR_NewFileInfoObjectA(JNIEnv *env,
-                                            const char *fname, int type);
+ACR_DECLARE(jobject) ACR_NewFileInfoObjectA(JNIEnv *env, const char *fname);
 
-ACR_DECLARE(jobject) ACR_NewFileInfoObjectW(JNIEnv *env,
-                                            const wchar_t *fname, int type);
+/** Create new FileInfo object. Unicode version.
+ * @param env JNI environment to use.
+ * @param fname FileInfo.Name field.
+ */
+ACR_DECLARE(jobject) ACR_NewFileInfoObjectW(JNIEnv *env, const wchar_t *fname);
 
 #ifdef __cplusplus
 }

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=826182&r1=826181&r2=826182&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 Sat Oct 17 07:08:29 2009
@@ -122,7 +122,6 @@
         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'))) {
@@ -130,28 +129,7 @@
                          */
                         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_NewFileInfoObjectA(_E, dp->d_name, type);
+                    rv = ACR_NewFileInfoObjectA(_E, dp->d_name);
                 }
                 else
                     break;

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=826182&r1=826181&r2=826182&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 Sat Oct 17 07:08:29 2009
@@ -94,13 +94,13 @@
 
 J_DECLARE_F_ID(0009) = {
     NULL,
-    "Name",
+    "Path",
     "Ljava/lang/String;"
 };
 
 J_DECLARE_F_ID(0010) = {
     NULL,
-    "BaseName",
+    "Name",
     "Ljava/lang/String;"
 };
 
@@ -125,7 +125,7 @@
 J_DECLARE_M_ID(0001) = {
     NULL,
     "<init>",
-    "(Ljava/lang/String;I)V"
+    "(Ljava/lang/String;)V"
 };
 
 J_DECLARE_M_ID(0002) = {
@@ -165,22 +165,20 @@
     ACR_UnloadClass(_E, &_clazzn);
 }
 
-ACR_DECLARE(jobject) ACR_NewFileInfoObjectA(JNIEnv *_E, const char *fname,
-                                            int type)
+ACR_DECLARE(jobject) ACR_NewFileInfoObjectA(JNIEnv *_E, const char *fname)
 {
     jstring name;
     if ((name = ACR_NewJavaStringA(_E, fname)))
-        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), type);
+        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001));
     else
         return NULL;
 }
 
-ACR_DECLARE(jobject) ACR_NewFileInfoObjectW(JNIEnv *_E, const wchar_t *fname,
-                                            int type)
+ACR_DECLARE(jobject) ACR_NewFileInfoObjectW(JNIEnv *_E, const wchar_t *fname)
 {
     jstring name;
     if ((name = ACR_NewJavaStringW(_E, fname)))
-        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), type);
+        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001));
     else
         return NULL;
 }
@@ -275,12 +273,17 @@
         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);
+        char *canon = acr_GetAbsolutePath(_E, fname);
+        if (canon) {
+            char  path[PATH_MAX];
+            char *name;
+
+            name = dirname_r(canon, path, PATH_MAX);
+            SET_IFIELD_S(0009, fi, name);
+            name = basename_r(canon, path, PATH_MAX);
+            SET_IFIELD_S(0010, fi, name);
+        }
+        x_free(canon);
     }
     _fill0(_E, fi, &info, full);
 
@@ -316,7 +319,9 @@
     if (full) {
         char  path[PATH_MAX];
         char *name;
-        SET_IFIELD_S(0009, fi, f->name);
+
+        name = dirname_r(f->name, path, PATH_MAX);
+        SET_IFIELD_S(0009, fi, name);
         name = basename_r(f->name, path, PATH_MAX);
         SET_IFIELD_S(0010, fi, name);
     }
@@ -325,16 +330,13 @@
     return fi;
 }
 
-static int _stat2(ACR_JNISTDARGS, const char *fname, jboolean link)
+static int _stat2(ACR_JNISTDARGS, const char *fname)
 {
     struct_stat_t info;
     int   rc = 0;
     int   type;
 
-    if (link)
-        rc = lstat(fname, &info);
-    else
-        rc =  stat(fname, &info);
+    rc =  stat(fname, &info);
     if (rc < 0)
         return ACR_GET_OS_ERROR();
     type = _ftype0(&info);
@@ -358,12 +360,11 @@
 }
 
 ACR_IO_EXPORT_DECLARE(jint, FileInfo, stat0)(ACR_JNISTDARGS,
-                                             jstring fname,
-                                             jboolean link)
+                                             jstring fname)
 {
     int rc = 0;
     WITH_CSTR(fname) {
-        rc = _stat2(_E, _O, J2S(fname), link);
+        rc = _stat2(_E, _O, J2S(fname));
     } END_WITH_CSTR(fname);
 
     return rc;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c?rev=826182&r1=826181&r2=826182&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c Sat Oct 17 07:08:29 2009
@@ -111,17 +111,7 @@
                          */
                         continue;
                     }
-                    /* Determine the type of the enty
-                     */
-                    if (dp->d_type & FILE_ATTRIBUTE_DIRECTORY)
-                        type = ACR_FT_DIR;
-                    else if (dp->d_type & FILE_ATTRIBUTE_REPARSE_POINT)
-                        type = ACR_FT_LNK;
-                    else if (dp->d_type & FILE_ATTRIBUTE_DEVICE)
-                        type = ACR_FT_CHR;
-                    else
-                        type = ACR_FT_REG;
-                    rv = ACR_NewFileInfoObjectA(_E, dp->d_name, type);
+                    rv = ACR_NewFileInfoObjectA(_E, dp->d_name);
                 }
                 else
                     break;

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=826182&r1=826181&r2=826182&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 Sat Oct 17 07:08:29 2009
@@ -93,13 +93,13 @@
 
 J_DECLARE_F_ID(0009) = {
     NULL,
-    "Name",
+    "Path",
     "Ljava/lang/String;"
 };
 
 J_DECLARE_F_ID(0010) = {
     NULL,
-    "BaseName",
+    "Name",
     "Ljava/lang/String;"
 };
 
@@ -124,7 +124,7 @@
 J_DECLARE_M_ID(0001) = {
     NULL,
     "<init>",
-    "(Ljava/lang/String;I)V"
+    "(Ljava/lang/String;)V"
 };
 
 J_DECLARE_M_ID(0002) = {
@@ -164,22 +164,20 @@
     ACR_UnloadClass(_E, &_clazzn);
 }
 
-ACR_DECLARE(jobject) ACR_NewFileInfoObjectA(JNIEnv *_E, const char *fname,
-                                            int type)
+ACR_DECLARE(jobject) ACR_NewFileInfoObjectA(JNIEnv *_E, const char *fname)
 {
     jstring name;
     if ((name = ACR_NewJavaStringU(_E, fname)))
-        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), type);
+        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001));
     else
         return NULL;
 }
 
-ACR_DECLARE(jobject) ACR_NewFileInfoObjectW(JNIEnv *_E, const wchar_t *fname,
-                                            int type)
+ACR_DECLARE(jobject) ACR_NewFileInfoObjectW(JNIEnv *_E, const wchar_t *fname)
 {
     jstring name;
     if ((name = ACR_NewJavaStringW(_E, fname)))
-        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), type);
+        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001));
     else
         return NULL;
 }
@@ -368,16 +366,16 @@
     if (full) {
         /* Resolve full path name
          */
-        wchar_t *path;
         wchar_t *name = acr_GetAbsolutePath(_E, ih, fname);
-        SET_IFIELD_W(0009, fi, name);
-        if ((path = wcsrchr(name, L'\\')))
-            SET_IFIELD_W(0010, fi, path);
-        else {
-            if ((path = wcsrchr(name, L'/')))
+        if (name) {
+            wchar_t *path;
+            if (!(path = wcsrchr(name, L'\\')))
+                path = wcsrchr(name, L'/');
+            if (path) {
+                *(path++) = L'\0';
+                SET_IFIELD_W(0009, fi, name);
                 SET_IFIELD_W(0010, fi, path);
-            else
-                SET_IFIELD_W(0010, fi, name);
+            }
         }
         x_free(name);
     }
@@ -424,16 +422,18 @@
     if (full) {
         /* Resolve base name
          */
-        wchar_t *path;
-        SET_IFIELD_W(0009, fi, f->name);
-        if ((path = wcsrchr(f->name, L'\\')))
-            SET_IFIELD_W(0010, fi, path + 1);
-        else {
-            if ((path = wcsrchr(f->name, L'/')))
-                SET_IFIELD_W(0010, fi, path + 1);
-            else
-                SET_IFIELD_W(0010, fi, f->name);
+        wchar_t *name = ACR_StrdupW(_E, THROW_NMARK, f->name);
+        if (name) {
+            wchar_t *path;
+            if (!(path = wcsrchr(name, L'\\')))
+                path = wcsrchr(name, L'/');
+            if (path) {
+                *(path++) = L'\0';
+                SET_IFIELD_W(0009, fi, name);
+                SET_IFIELD_W(0010, fi, path);
+            }
         }
+        x_free(name);
     }
     _fill0(_E, fi, &info);
     rc = _fill1(_E, fi, f->fd, info.dwFileAttributes, full);
@@ -446,7 +446,7 @@
     return fi;
 }
 
-static int _stat2(ACR_JNISTDARGS, const wchar_t *fname, jboolean link)
+static int _stat2(ACR_JNISTDARGS, const wchar_t *fname)
 {
     BY_HANDLE_FILE_INFORMATION info;
     HANDLE ih;
@@ -491,12 +491,11 @@
 
 
 ACR_IO_EXPORT_DECLARE(jint, FileInfo, stat0)(ACR_JNISTDARGS,
-                                             jstring fname,
-                                             jboolean link)
+                                             jstring fname)
 {
     int rc = 0;
     WITH_WSTR(fname) {
-        rc = _stat2(_E, _O, J2W(fname), link);
+        rc = _stat2(_E, _O, J2W(fname));
     } END_WITH_WSTR(fname);
 
     return rc;



Mime
View raw message