// <script type ="text/Javascript">
-GLib = imports.gi.GLib;
-Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+
+//const String = imports.String.String;
+const console = imports.console.console;
-String = imports.String.String;
/**
* @namespace File
*
SEPARATOR : '/',
- // fixme - this needs a bitter location..
+ // fixme - this needs a bitter location..
// they where in a string class before, but overriding String methods is not a good normally a good idea..
-
rtrim : function (s,toTrim) {
if (s.substr(s.length - toTrim.length) == toTrim) {
return s.slice(0, s.length - toTrim.length);
return s;
},
+
trim : function (s,toTrim) {
var out = this.ltrim(s,toTrim);
out = this.rtrim(out,toTrim);
}
return out;
},
+
read : function (path) {
var out = {};
- GLib.file_get_contents(path, out, null, null);
- return out['value'];
+ if (typeof(Seed) == 'undefined') {
+ var ret;
+ var err;
+ [ret, out, err] = GLib.file_get_contents(path, out, null, null);
+ return out;
+ } else {
+ GLib.file_get_contents(path, out, null);
+ return out['value'];
+ }
},
isFile : function (path) {
return GLib.file_test(path, GLib.FileTest.IS_REGULAR);
},
+
exists : function (path) {
return GLib.file_test(path, GLib.FileTest.EXISTS);
},
+
isDirectory : function (path) {
return GLib.file_test(path, GLib.FileTest.IS_DIR);
},
list : function (path) {
var listing = [];
- var f = Gio.file_new_for_path(String(path));
+ //var f = Gio.file_new_for_path(String(path));
+ var f = Gio.file_new_for_path(path);
var file_enum = f.enumerate_children(Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, Gio.FileQueryInfoFlags.NONE, null);
var next_file = null;
},
mtime : function (path) {
- var f = Gio.file_new_for_path(String(path));
+ //var f = Gio.file_new_for_path(String(path));
+ var f = Gio.file_new_for_path(path);
var mtime = new GLib.TimeVal();
var info = f.query_info(Gio.FILE_ATTRIBUTE_TIME_MODIFIED, Gio.FileQueryInfoFlags.NONE, null);
},
canonical : function (path) {
- var f = Gio.file_new_for_path(String(path));
+ //var f = Gio.file_new_for_path(String(path));
+ var f = Gio.file_new_for_path(path);
var can = f.resolve_relative_path('');
return can.get_path();
},
*
*/
write : function (path, string) {
- var f = Gio.file_new_for_path(String(path));
+ //var f = Gio.file_new_for_path(String(path));
+ var f = Gio.file_new_for_path(path);
var data_out = new Gio.DataOutputStream({base_stream:f.replace(null, false, Gio.FileCreateFlags.NONE, null)});
data_out.put_string(string, null);
data_out.close(null);
},
+
/**
* append
* @arg path {String} File to write to
*
*/
append : function (path, string) {
- var f = Gio.file_new_for_path(String(path));
+ //var f = Gio.file_new_for_path(String(path));
+ var f = Gio.file_new_for_path(path);
var data_out = new Gio.DataOutputStream({
base_stream:f.append_to(Gio.FileCreateFlags.NONE, null)
});
data_out.put_string(string, null);
data_out.close(null);
},
+
/**
* remove
* Delete a file.
*/
remove : function (path)
{
- var f = Gio.file_new_for_path(String(path));
+ //var f = Gio.file_new_for_path(String(path));
+ var f = Gio.file_new_for_path(path);
return f['delete']();
},
+
/**
* silentRecursiveCopy
* copy files recursively from fromDir, silently ignore them if they already exist in toDir
*
*/
silentRecursiveCopy : function (fromDir, toDir, opts) {
-
+
var filesToCopy = File.recursiveListing(fromDir);
var srcPath, destPath, src, dest;
if (typeof(opts) =='undefined') {
opts = Gio.FileCopyFlags.NONE;
}
-
+
for (var index in filesToCopy) {
- srcPath = File.join(String(fromDir), filesToCopy[index]);
- destPath = File.join(String(toDir), filesToCopy[index]);
+ //srcPath = File.join(String(fromDir), filesToCopy[index]);
+ //destPath = File.join(String(toDir), filesToCopy[index]);
+ srcPath = File.join(fromDir, filesToCopy[index]);
+ destPath = File.join(toDir, filesToCopy[index]);
if (File.isDirectory(srcPath) && !File.isDirectory(destPath)) {
File.mkdir(destPath);
continue;
}
+
// source is not file..?!?!?
if (!File.isFile(srcPath)) {
continue;
}
+
if (File.isFile(destPath) && opts == Gio.FileCopyFlags.NONE) {
// do not overwrite.. - if file exists and we are not flaged to overwrite.
continue;
}
-
+
File.copyFile(srcPath, destPath, opts);
-
}
},
-
+
/**
* mkdir
* make a directory..
* @arg {String} dstPath directory to make
*/
mkdir : function (destPath) {
- var dest = Gio.file_new_for_path(String(destPath));
-
+ //var dest = Gio.file_new_for_path(String(destPath));
+ var dest = Gio.file_new_for_path(destPath);
+
return dest.make_directory(null, null);
},
+
/**
* copyFile
* @arg {String} src source path
opts = Gio.FileCopyFlags.NONE;
}
var dest = Gio.file_new_for_path(String(destPath));
- var src = Gio.file_new_for_path(String(srcPath));
+ //var dest = Gio.file_new_for_path(destPath);
+ var src = Gio.file_new_for_path(String(srcPath));
+ //var src = Gio.file_new_for_path(srcPath);
// a bit of a hack for the fact that Gio.File.copy arguments
// can be nulled, but not according to the GIR file
- return src.copy(dest, opts);
+ //return src.copy(dest, opts);
+ if (typeof(Seed) != 'undefined')
+ return src.copy(dest, opts, null);
+ else
+ return src.copy(dest, opts, null, null);
+
},
recursiveListing : function (dir) {