Ver código fonte

sys.FileSystem ok

Nicolas Cannasse 13 anos atrás
pai
commit
32baa6ebf2

+ 5 - 5
doc/ImportAll.hx

@@ -26,7 +26,7 @@ import haxe.macro.Context;
 
 class ImportAll {
 
-	public static function run( ?pack ) {	
+	public static function run( ?pack ) {
 		if( pack == null ) {
 			pack = "";
 			haxe.macro.Compiler.define("doc_gen");
@@ -55,14 +55,14 @@ class ImportAll {
 			if( p == "/" )
 				continue;
 			// skip if we have a classpath to haxe
-			if( pack.length == 0 && neko.FileSystem.exists(p+"std") )
+			if( pack.length == 0 && sys.FileSystem.exists(p+"std") )
 				continue;
 			var p = p + pack.split(".").join("/");
 			if( StringTools.endsWith(p,"/") )
 				p = p.substr(0,-1);
-			if( !neko.FileSystem.exists(p) || !neko.FileSystem.isDirectory(p) )
+			if( !sys.FileSystem.exists(p) || !sys.FileSystem.isDirectory(p) )
 				continue;
-			for( file in neko.FileSystem.readDirectory(p) ) {
+			for( file in sys.FileSystem.readDirectory(p) ) {
 				if( file == ".svn" || file == "_std" )
 					continue;
 				var full = (pack == "") ? file : pack + "." + file;
@@ -80,7 +80,7 @@ class ImportAll {
 					case "haxe.remoting.SyncSocketConnection": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue;
 					}
 					Context.getModule(cl);
-				} else if( neko.FileSystem.isDirectory(p + "/" + file) )
+				} else if( sys.FileSystem.isDirectory(p + "/" + file) )
 					run(full);
 			}
 		}

+ 17 - 30
std/cpp/FileSystem.hx → std/cpp/_std/sys/FileSystem.hx

@@ -22,35 +22,22 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package cpp;
+package sys;
 
-typedef FileStat = {
-	var gid : Int;
-	var uid : Int;
-	var atime : Date;
-	var mtime : Date;
-	var ctime : Date;
-	var dev : Int;
-	var ino : Int;
-	var nlink : Int;
-	var rdev : Int;
-	var size : Int;
-	var mode : Int;
-}
-
-enum FileKind {
+private enum FileKind {
 	kdir;
 	kfile;
 	kother( k : String );
 }
 
+@:core_api
 class FileSystem {
 
 	public static function exists( path : String ) : Bool {
 		return sys_exists(path);
 	}
 
-	public static function rename( path : String, newpath : String ) {
+	public static function rename( path : String, newpath : String ) : Void {
 		if (sys_rename(path,newpath)==null)
          throw "Could not rename:" + path + " to " + newpath;
 	}
@@ -69,7 +56,7 @@ class FileSystem {
 		return new String(file_full_path(relpath));
 	}
 
-	public static function kind( path : String ) : FileKind {
+	static function kind( path : String ) : FileKind {
 		var k:String = sys_file_type(path);
 		return switch(k) {
 		case "file": kfile;
@@ -82,17 +69,17 @@ class FileSystem {
 		return kind(path) == kdir;
 	}
 
-	public static function createDirectory( path : String ) {
+	public static function createDirectory( path : String ) : Void {
 		if (sys_create_dir( path, 493 )==null)
          throw "Could not create directory:" + path;
 	}
 
-	public static function deleteFile( path : String ) {
+	public static function deleteFile( path : String ) : Void {
 		if (file_delete(path)==null)
          throw "Could not delete file:" + path;
 	}
 
-	public static function deleteDirectory( path : String ) {
+	public static function deleteDirectory( path : String ) : Void {
 		if (sys_remove_dir(path)==null)
          throw "Could not delete directory:" + path;
 	}
@@ -101,14 +88,14 @@ class FileSystem {
 		return sys_read_dir(path);
 	}
 
-	private static var sys_exists = Lib.load("std","sys_exists",1);
-	private static var file_delete = Lib.load("std","file_delete",1);
-	private static var sys_rename = Lib.load("std","sys_rename",2);
-	private static var sys_stat = Lib.load("std","sys_stat",1);
-	private static var sys_file_type = Lib.load("std","sys_file_type",1);
-	private static var sys_create_dir = Lib.load("std","sys_create_dir",2);
-	private static var sys_remove_dir = Lib.load("std","sys_remove_dir",1);
-	private static var sys_read_dir = Lib.load("std","sys_read_dir",1);
-	private static var file_full_path = Lib.load("std","file_full_path",1);
+	private static var sys_exists = cpp.Lib.load("std","sys_exists",1);
+	private static var file_delete = cpp.Lib.load("std","file_delete",1);
+	private static var sys_rename = cpp.Lib.load("std","sys_rename",2);
+	private static var sys_stat = cpp.Lib.load("std","sys_stat",1);
+	private static var sys_file_type = cpp.Lib.load("std","sys_file_type",1);
+	private static var sys_create_dir = cpp.Lib.load("std","sys_create_dir",2);
+	private static var sys_remove_dir = cpp.Lib.load("std","sys_remove_dir",1);
+	private static var sys_read_dir = cpp.Lib.load("std","sys_read_dir",1);
+	private static var file_full_path = cpp.Lib.load("std","file_full_path",1);
 
 }

+ 6 - 6
std/haxe/macro/Compiler.hx

@@ -90,15 +90,15 @@ class Compiler {
 		var prefix = pack == '' ? '' : pack + '.';
 		for( cp in classPaths ) {
 			var path = pack == '' ? cp : cp + "/" + pack.split(".").join("/");
-			if( !neko.FileSystem.exists(path) || !neko.FileSystem.isDirectory(path) )
+			if( !sys.FileSystem.exists(path) || !sys.FileSystem.isDirectory(path) )
 				continue;
-			for( file in neko.FileSystem.readDirectory(path) ) {
+			for( file in sys.FileSystem.readDirectory(path) ) {
 				if( StringTools.endsWith(file, ".hx") ) {
 					var cl = prefix + file.substr(0, file.length - 3);
 					if( skip(cl) )
 						continue;
 					Context.getModule(cl);
-				} else if( rec && neko.FileSystem.isDirectory(path + "/" + file) && !skip(prefix + file) )
+				} else if( rec && sys.FileSystem.isDirectory(path + "/" + file) && !skip(prefix + file) )
 					include(prefix + file, true, ignore, classPaths);
 			}
 		}
@@ -218,9 +218,9 @@ class Compiler {
 		{
 			for ( p in Context.getClassPath() ) {
 				var p = p + path.split(".").join("/");
-				if (neko.FileSystem.exists(p) && neko.FileSystem.isDirectory(p))
+				if (sys.FileSystem.exists(p) && sys.FileSystem.isDirectory(p))
 				{
-					for( file in neko.FileSystem.readDirectory(p) ) {
+					for( file in sys.FileSystem.readDirectory(p) ) {
 						if( StringTools.endsWith(file, ".hx") ) {
 							var module = path + "." + file.substr(0, file.length - 3);
 							var types = Context.getModule(module);
@@ -234,7 +234,7 @@ class Compiler {
 										//
 								}
 							}
-						} else if( rec && neko.FileSystem.isDirectory(p + "/" + file) )
+						} else if( rec && sys.FileSystem.isDirectory(p + "/" + file) )
 							keep(path + "." + file, true);
 					}
 				} else {

+ 17 - 30
std/neko/FileSystem.hx → std/neko/_std/sys/FileSystem.hx

@@ -22,35 +22,22 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package neko;
+package sys;
 
-typedef FileStat = {
-	var gid : Int;
-	var uid : Int;
-	var atime : Date;
-	var mtime : Date;
-	var ctime : Date;
-	var dev : Int;
-	var ino : Int;
-	var nlink : Int;
-	var rdev : Int;
-	var size : Int;
-	var mode : Int;
-}
-
-enum FileKind {
+private enum FileKind {
 	kdir;
 	kfile;
 	kother( k : String );
 }
 
+@:core_api
 class FileSystem {
 
 	public static function exists( path : String ) : Bool {
 		return sys_exists(untyped path.__s);
 	}
 
-	public static function rename( path : String, newpath : String ) {
+	public static function rename( path : String, newpath : String ) : Void {
 		untyped sys_rename(path.__s,newpath.__s);
 	}
 
@@ -66,7 +53,7 @@ class FileSystem {
 		return new String(file_full_path(untyped relpath.__s));
 	}
 
-	public static function kind( path : String ) : FileKind {
+	static function kind( path : String ) : FileKind {
 		var k = new String(sys_file_type(untyped path.__s));
 		return switch(k) {
 		case "file": kfile;
@@ -79,15 +66,15 @@ class FileSystem {
 		return kind(path) == kdir;
 	}
 
-	public static function createDirectory( path : String ) {
+	public static function createDirectory( path : String ) : Void {
 		sys_create_dir( untyped path.__s, 493 );
 	}
 
-	public static function deleteFile( path : String ) {
+	public static function deleteFile( path : String ) : Void {
 		file_delete(untyped path.__s);
 	}
 
-	public static function deleteDirectory( path : String ) {
+	public static function deleteDirectory( path : String ) : Void {
 		sys_remove_dir(untyped path.__s);
 	}
 
@@ -101,14 +88,14 @@ class FileSystem {
 		return a;
 	}
 
-	private static var sys_exists = Lib.load("std","sys_exists",1);
-	private static var file_delete = Lib.load("std","file_delete",1);
-	private static var sys_rename = Lib.load("std","sys_rename",2);
-	private static var sys_stat = Lib.load("std","sys_stat",1);
-	private static var sys_file_type = Lib.load("std","sys_file_type",1);
-	private static var sys_create_dir = Lib.load("std","sys_create_dir",2);
-	private static var sys_remove_dir = Lib.load("std","sys_remove_dir",1);
-	private static var sys_read_dir = Lib.load("std","sys_read_dir",1);
-	private static var file_full_path = Lib.load("std","file_full_path",1);
+	private static var sys_exists = neko.Lib.load("std","sys_exists",1);
+	private static var file_delete = neko.Lib.load("std","file_delete",1);
+	private static var sys_rename = neko.Lib.load("std","sys_rename",2);
+	private static var sys_stat = neko.Lib.load("std","sys_stat",1);
+	private static var sys_file_type = neko.Lib.load("std","sys_file_type",1);
+	private static var sys_create_dir = neko.Lib.load("std","sys_create_dir",2);
+	private static var sys_remove_dir = neko.Lib.load("std","sys_remove_dir",1);
+	private static var sys_read_dir = neko.Lib.load("std","sys_read_dir",1);
+	private static var file_full_path = neko.Lib.load("std","file_full_path",1);
 
 }

+ 2 - 2
std/neko/net/ProxyDetect.hx

@@ -61,7 +61,7 @@ class ProxyDetect {
 	}
 
 	static function detectFF( basedir : String ) {
-		var files = try neko.FileSystem.readDirectory(basedir) catch( e : Dynamic ) return null;
+		var files = try sys.FileSystem.readDirectory(basedir) catch( e : Dynamic ) return null;
 		var profile = null;
 		for( f in files )
 			if( f.substr(-8) == ".default" ) {
@@ -98,7 +98,7 @@ class ProxyDetect {
 		}
 		// it's possible that if registry access was disabled the proxy file is not created
 		var content = try sys.io.File.getContent(temp) catch( e : Dynamic ) return null;
-		neko.FileSystem.deleteFile(temp);
+		sys.FileSystem.deleteFile(temp);
 		// turn 16-bit string into 8-bit one
 		var b = new StringBuf();
 		var p = 0;

+ 1 - 1
std/php/_std/haxe/Resource.hx

@@ -40,7 +40,7 @@ class Resource {
 	}
 
 	public static function listNames() : Array<String> {
-		var a = php.FileSystem.readDirectory(getDir());
+		var a = sys.FileSystem.readDirectory(getDir());
 		if(a[0] == '.') a.shift();
 		if(a[0] == '..') a.shift();
 		return a;

+ 8 - 21
std/php/FileSystem.hx → std/php/_std/sys/FileSystem.hx

@@ -22,35 +22,22 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package php;
+package sys;
 
-typedef FileStat = {
-	var gid : Int;
-	var uid : Int;
-	var atime : Date;
-	var mtime : Date;
-	var ctime : Date;
-	var dev : Int;
-	var ino : Int;
-	var nlink : Int;
-	var rdev : Int;
-	var size : Int;
-	var mode : Int;
-}
-
-enum FileKind {
+private enum FileKind {
 	kdir;
 	kfile;
 	kother( k : String );
 }
 
+@:core_api
 class FileSystem {
 
 	public static inline function exists( path : String ) : Bool {
 		return untyped __call__("file_exists", path);
 	}
 
-	public static inline function rename( path : String, newpath : String ) {
+	public static inline function rename( path : String, newpath : String ) : Void {
 		untyped __call__("rename", path, newpath);
 	}
 
@@ -81,7 +68,7 @@ class FileSystem {
 			return p;
 	}
 
-	public static function kind( path : String ) : FileKind {
+	static function kind( path : String ) : FileKind {
 		var k = untyped __call__("filetype", path);
 		switch(k) {
 			case "file": return kfile;
@@ -94,15 +81,15 @@ class FileSystem {
 		return untyped __call__("is_dir", path);
 	}
 
-	public static inline function createDirectory( path : String ) {
+	public static inline function createDirectory( path : String ) : Void {
 		untyped __call__("@mkdir", path, 493); // php default is 0777, neko is 0755
 	}
 
-	public static inline function deleteFile( path : String ) {
+	public static inline function deleteFile( path : String ) : Void {
 		untyped __call__("@unlink", path);
 	}
 
-	public static inline function deleteDirectory( path : String ) {
+	public static inline function deleteDirectory( path : String ) : Void {
 		untyped __call__("@rmdir", path);
 	}
 

+ 48 - 0
std/sys/FileStat.hx

@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2005-2012, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package sys;
+
+/**
+	File informations, as given by [sys.FileSystem.stat]
+**/
+typedef FileStat = {
+	/** the user group id for the file **/
+	var gid : Int;
+	/** the user id for the file **/
+	var uid : Int;
+	/** the last access time for the file (when enabled by the file system) **/
+	var atime : Date;
+	/** the last modification time for the file **/
+	var mtime : Date;
+	/** the creation time for the file **/
+	var ctime : Date;
+	/** the size of the file **/
+	var size : Int;
+	var dev : Int;
+	var ino : Int;
+	var nlink : Int;
+	var rdev : Int;
+	var mode : Int;
+}

+ 76 - 0
std/sys/FileSystem.hx

@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package sys;
+
+/**
+	This class allows you to get informations about the files and directories.
+**/
+extern class FileSystem {
+
+	/**
+		Tells if the given file or directory exists.
+	**/
+	static function exists( path : String ) : Bool;
+
+	/**
+		Rename the corresponding file or directory, allow to move it accross directories as well.
+	**/
+	static function rename( path : String, newpath : String ) : Void;
+
+	/**
+		Returns informations for the given file/directory.
+	**/
+	static function stat( path : String ) : FileStat;
+
+	/**
+		Returns the full path for the given path which is relative to the current working directory.
+	**/
+	static function fullPath( relpath : String ) : String;
+
+	/**
+		Tells if the given path is a directory. Throw an exception if it does not exists or is not accesible.
+	**/
+	static function isDirectory( path : String ) : Bool;
+
+	/**
+		Create the given directory. Not recursive : the parent directory must exists.
+	**/
+	static function createDirectory( path : String ) : Void;
+
+	/**
+		Delete a given file.
+	**/
+	static function deleteFile( path : String ) : Void;
+	/**
+		Delete a given directory.
+	**/
+	static function deleteDirectory( path : String ) : Void;
+
+	/**
+		Read all the files/directories stored into the given directory.
+	**/
+	static function readDirectory( path : String ) : Array<String>;
+
+}