Changeset 539

Show
Ignore:
Timestamp:
08/27/08 13:24:19 (4 months ago)
Author:
chris
Message:

Implement File.setReadOnly().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Mika/trunk/core-vm/java/java/io/File.java

    r418 r539  
    433433  } 
    434434 
    435   public boolean setReadOnly() throws SecurityException { 
    436     return false; 
    437   } 
     435  public native boolean setReadOnly() throws SecurityException; 
    438436 
    439437  public native long length() throws SecurityException; 
  • Mika/trunk/core-vm/src/native/java/io/File.c

    r456 r539  
    22* Parts copyright (c) 2001, 2002, 2003 by Punch Telematix.                * 
    33* All rights reserved.                                                    * 
    4 * Parts copyright (c) 2004 by Chris Gray, /k/ Embedded Java Solutions.    * 
    5 * All rights reserved.                                                    * 
     4* Parts copyright (c) 2004, 2008 by Chris Gray, /k/ Embedded Java         * 
     5* Solutions. All rights reserved.                                         * 
    66*                                                                         * 
    77* Redistribution and use in source and binary forms, with or without      * 
     
    139139} 
    140140 
     141w_boolean File_setReadOnly (JNIEnv *env, w_instance thisFile) { 
     142  char *pathname; 
     143  struct vfs_STAT statbuf; 
     144  jboolean result; 
     145  const int WRITABLE = VFS_S_IWUSR | VFS_S_IWGRP | VFS_S_IWOTH; 
     146   
     147  pathname = getFileName(thisFile);        
     148  result = vfs_stat(pathname, &statbuf) == 0 
     149    && vfs_chmod(pathname, statbuf.st_mode & ~WRITABLE) == 0; 
     150 
     151  freeFileName(pathname); 
     152   
     153  return result; 
     154} 
     155 
    141156w_boolean Java_File_canRead (JNIEnv *env, w_instance thisFile) { 
    142157  struct vfs_STAT statbuf; 
     
    183198    return 0; 
    184199  } 
     200} 
     201 
     202w_boolean File_delete (JNIEnv *env, w_instance thisFile) { 
     203  char      *pathname; 
     204  struct vfs_STAT statbuf; 
     205  w_boolean result; 
     206   
     207  pathname = getFileName(thisFile);        
     208 
     209  result == (vfs_stat(pathname, &statbuf) == 0); 
     210  if (result) { 
     211    if(VFS_S_ISDIR(statbuf.st_mode)) { 
     212      result = (vfs_rmdir(pathname) == 0); 
     213      woempa(9, "%s is a directory, result = %d\n", pathname, result); 
     214      wprintf("%s is a directory, result = %d\n", pathname, result); 
     215    } else { 
     216      result = (vfs_unlink(pathname) == 0); 
     217      woempa(9, "%s is a file, result = %d\n", pathname, result); 
     218      wprintf("%s is a file, result = %d\n", pathname, result); 
     219    } 
     220  } 
     221   
     222  freeFileName(pathname); 
     223 
     224  return result; 
     225 
    185226} 
    186227 
     
    293334} 
    294335 
    295 /* 
    296  * Class:     File 
    297  * Method:    delete 
    298  * Signature: ()Z 
    299  */ 
    300 JNIEXPORT jboolean JNICALL Java_File_delete 
    301   (JNIEnv *env, jobject thisObj) { 
    302  
    303   jboolean        isCopy; 
    304   const char      *pathname; 
    305   jstring         path; 
    306   struct vfs_STAT statbuf; 
    307   jboolean        result = JNI_FALSE; 
    308    
    309   path = (jstring)(*env)->GetObjectField(env, thisObj, absname); 
    310   pathname = (*env)->GetStringUTFChars(env, path, &isCopy);        
    311  
    312   if(vfs_stat((w_ubyte *)pathname, &statbuf) != -1) { 
    313     if(VFS_S_ISDIR(statbuf.st_mode)) { 
    314       if(vfs_rmdir(pathname) == 0) result = JNI_TRUE; 
    315       woempa(9, "%s is a directory, result = %d\n", pathname, result); 
    316     } else { 
    317       if(vfs_unlink(pathname) == 0) result = JNI_TRUE; 
    318       woempa(9, "%s is a file, result = %d\n", pathname, result); 
    319     } 
    320   } 
    321    
    322   if(isCopy == JNI_TRUE) (*env)->ReleaseStringUTFChars(env, path, pathname); 
    323  
    324   return result; 
    325  
    326 } 
    327  
    328336#ifdef __cplusplus 
    329337} 
  • Mika/trunk/core-vm/src/vm/core-classes.in

    r485 r539  
    750750        mkdir                   ()Z                                             Java_File_mkdir 
    751751        rename                  (Ljava/lang/String;Ljava/lang/String;)Z         Java_File_rename 
    752         delete                  ()Z                                             Java_File_delete 
     752        setReadOnly             ()Z     File_setReadOnly 
     753        delete                  ()Z     File_delete 
    753754        get_CWD                 ()Ljava/lang/String;                            Java_File_get_CWD 
    754755        get_fsroot              ()Ljava/lang/String;                            Java_File_get_fsroot 
     
    769770        close                   ()V                                             Java_RandomAccessFile_close 
    770771wonka/vm/ProcessInfo 
    771   wotsit        I 
     772  wotsit        + 
    772773  id            I 
    773774  destroyed     Z