diff base/src/java/io/File.d @ 120:536e43f63c81

Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661 ===D2=== * added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements used these templates to work with strict type storage rules of dmd-2.053 * com.ibm.icu now also compilable with D2, but not tested yet * small fixes Snippet288 - shared data is in TLS ===Phobos=== * fixed critical bugs in Phobos implemention completely incorrect segfault prone fromStringz (Linux's port ruthless killer) terrible, incorrect StringBuffer realization (StyledText killer) * fixed small bugs as well Snippet72 - misprint in the snippet * implemented missed functionality for Phobos ByteArrayOutputStream implemented (image loading available) formatting correctly works for all DWT's cases As a result, folowing snippets now works with Phobos (Snippet### - what is fixed): Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting Snippet48, 282 - crash on image loading Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText Snippet244 - hang-up ===Tango=== * few changes for the latest Tango trunc-r5661 * few small performance improvments ===General=== * implMissing-s for only one version changed to implMissingInTango/InPhobos * incorrect calls to Format in toString-s fixed * fixed loading \uXXXX characters in ResourceBundle * added good UTF-8 support for StyledText, TextLayout (Win32) and friends UTF functions revised and tested. It is now in java.nonstandard.*Utf modules StyledText and TextLayout (Win32) modules revised for UTF-8 support * removed small diferences in most identical files in *.swt.* folders *.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32 now 179 of 576 (~31%) files in *.swt.* folders are fully identical * Win32: snippets now have right subsystem, pretty icons and native system style controls * small fixes in snippets Snippet44 - it's not Snippet44 Snippet212 - functions work with different images and offsets arrays Win32: Snippet282 - crash on close if the button has an image Snippet293 - setGrayed is commented and others Win32: As a result, folowing snippets now works Snippet68 - color doesn't change Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above) Snippet193 - no tabel headers
author Denis Shelomovskij <verylonglogin.reg@gmail.com>
date Sat, 09 Jul 2011 15:50:20 +0300
parents e944a4cf537b
children
line wrap: on
line diff
--- a/base/src/java/io/File.d	Sun Apr 17 17:58:36 2011 +0200
+++ b/base/src/java/io/File.d	Sat Jul 09 15:50:20 2011 +0300
@@ -11,9 +11,14 @@
     static import tango.io.Path;
     static import tango.io.FileSystem;
     static import tango.sys.Environment;
+    static import tango.sys.Common;
+    static import tango.stdc.stringz; //for toStringz
+    version(Posix) static import tango.stdc.posix.unistd; //for access
 } else { // Phobos
     static import std.file;
     static import std.path;
+    static import std.string; //for toStringz
+    version(Posix) static import core.sys.posix.unistd; //for access
 }
 // Implement this more efficient by using FilePath in Tango 
 public class File {
@@ -32,46 +37,42 @@
             pathSeparator = tango.io.model.IFile.FileConst.SystemPathString;
             pathSeparatorChar = tango.io.model.IFile.FileConst.SystemPathChar;
         } else { // Phobos
-            version(Windows){
-                separator = "\\";
-                separatorChar = '\\';
-                pathSeparator = ";";
-                pathSeparatorChar = ';';
-            }
-            else{
-                separator = "/";
-                separatorChar = '/';
-                pathSeparator = ":";
-                pathSeparatorChar = ':';
-            }
+            separator = std.path.sep;
+            separatorChar = std.path.sep[0];
+            pathSeparator = std.path.pathsep;
+            pathSeparatorChar = std.path.pathsep[0];
         }
     }
 
-    private static String toStd( CString path ){
+    private static String toStd( String path ){
         version(Tango){
-            return tango.io.Path.standard( path._idup() );
+            return tango.io.Path.standard( path.dup );
         } else { // Phobos
-            return path._idup();
+            return path;
         }
     }
-    private static String join( CString path, CString file ){
+    private static String join( String path, String file ){
         version(Tango){
-            return tango.io.Path.join( path._idup(), file._idup() );
+            return tango.io.Path.join( toStd(path), toStd(file) );
         } else { // Phobos
-            return std.path.join( path._idup(), file._idup() );
+            return std.path.join( toStd(path), toStd(file) );
         }
     }
 
-    public this ( CString pathname ){
+    public this ( String pathname ){
         mFilePath = toStd( pathname );
     }
 
-    public this ( CString parent, CString child ){
-        mFilePath = join( toStd(parent), toStd(child) );
+    public this ( String parent, String child ){
+        mFilePath = join( parent, child );
     }
 
-    public this ( java.io.File.File parent, CString child ){
-        mFilePath = join( parent.mFilePath, toStd(child) );
+    public this ( java.io.File.File parent, String child ){
+        version(Tango){
+            mFilePath = tango.io.Path.join( parent.mFilePath, toStd(child) );
+        } else { // Phobos
+            mFilePath = std.path.join( parent.mFilePath, toStd(child) );
+        }
     }
 
     public int getPrefixLength(){
@@ -108,18 +109,12 @@
         version(Tango){
             return (new tango.io.FilePath.FilePath(mFilePath)).absolute(tango.sys.Environment.Environment.cwd).toString;
         } else { // Phobos
-            implMissing( __FILE__, __LINE__ );
-            return "";
+            return std.path.rel2abs(mFilePath);
         }
     }
 
     public java.io.File.File getAbsoluteFile(){
-        version(Tango){
-            return new File( getAbsolutePath() );
-        } else { // Phobos
-            implMissing( __FILE__, __LINE__ );
-            return null;
-        }
+        return new File( getAbsolutePath() );
     }
 
     public String getCanonicalPath(){
@@ -138,20 +133,27 @@
     }
 
     public bool canWrite(){
-        version(Tango){
-            return tango.io.Path.isWritable(mFilePath);
-        } else { // Phobos
-            implMissing( __FILE__, __LINE__ );
-            return false;
-        }
+        version(Windows) { //Windows's ACL isn't supported
+            version(Tango) {
+                return tango.io.Path.isWritable(mFilePath);
+            } else { // Phobos
+                return !(std.file.getAttributes(mFilePath) & 1); //FILE_ATTRIBUTE_READONLY = 1
+            }
+        } else version(Posix) { //workaround Tango's bug (isWritable is always true)
+            version(Tango) {
+                return tango.stdc.posix.unistd.access (tango.stdc.stringz.toStringz(mFilePath), 2) is 0; //W_OK = 2
+            } else { // Phobos
+                return core.sys.posix.unistd.access (std.string.toStringz(mFilePath), 2) is 0; //W_OK = 2
+            }
+        } else
+            static assert(0);
     }
 
     public bool exists(){
         version(Tango){
             return tango.io.Path.exists(mFilePath);
         } else { // Phobos
-            implMissing( __FILE__, __LINE__ );
-            return false;
+            return std.file.exists(mFilePath);
         }
     }
 
@@ -159,8 +161,7 @@
         version(Tango){
             return tango.io.Path.isFolder(mFilePath);
         } else { // Phobos
-            implMissing( __FILE__, __LINE__ );
-            return false;
+            return std.file.isDir(mFilePath);
         }
     }
 
@@ -238,12 +239,12 @@
         return null;
     }
 
-    public static java.io.File.File createTempFile( CString prefix, CString suffix, java.io.File.File directory ){
+    public static java.io.File.File createTempFile( String prefix, String suffix, java.io.File.File directory ){
         implMissing( __FILE__, __LINE__ );
         return null;
     }
 
-    public static java.io.File.File createTempFile( CString prefix, CString suffix ){
+    public static java.io.File.File createTempFile( String prefix, String suffix ){
         implMissing( __FILE__, __LINE__ );
         return null;
     }