[ease] [general] Added recursive_copy to utilities.
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease] [general] Added recursive_copy to utilities.
- Date: Sat, 24 Jul 2010 00:36:37 +0000 (UTC)
commit 853bce59d3a941b0056181342ee59a501601d958
Author: Nate Stedman <natesm gmail com>
Date: Fri Jul 23 20:35:12 2010 -0400
[general] Added recursive_copy to utilities.
recursive_copy replaces all calls of
Posix.system("cp ...
It uses the new recursive_directory function
in utilities, as all recursive directory actions
should going forward.
src/ease-slide-set.vala | 15 ---------------
src/ease-theme.vala | 9 +++++----
src/ease-utilities.vala | 31 +++++++++++++++++++++++++++++--
3 files changed, 34 insertions(+), 21 deletions(-)
---
diff --git a/src/ease-slide-set.vala b/src/ease-slide-set.vala
index df2aa5a..833ff29 100644
--- a/src/ease-slide-set.vala
+++ b/src/ease-slide-set.vala
@@ -99,21 +99,6 @@ public abstract class Ease.SlideSet : Object
}
/**
- * Copies all files under Media/ to a new directory.
- *
- * @param target The path to copy media files to.
- */
- public void copy_media(string target) throws GLib.Error
- {
- var origin_path = Path.build_filename(path, MEDIA_PATH);
-
- var target_path = Path.build_filename(target, MEDIA_PATH);
-
- // TODO: non-system implementation of recursive copy
- Posix.system("cp -r %s %s".printf(origin_path, target_path));
- }
-
- /**
* Copies a media file to the temporary directory.
*
* Returns the path to the new file, as it should be stored in the
diff --git a/src/ease-theme.vala b/src/ease-theme.vala
index c4dda8e..5c40a2f 100644
--- a/src/ease-theme.vala
+++ b/src/ease-theme.vala
@@ -221,10 +221,10 @@ public class Ease.Theme : GLib.Object
*
* @param copy_to The path to copy the Theme to.
*/
- public Theme copy_to_path(string copy_to)
+ public Theme copy_to_path(string copy_to) throws Error
{
// copy data files
- Posix.system("cp -r %s %s".printf(path, copy_to));
+ recursive_copy(path, copy_to);
// create a copy of this theme and change its path
var theme = new Theme.copy(this);
@@ -289,10 +289,11 @@ public class Ease.Theme : GLib.Object
{
var origin_path = Path.build_filename(path, MEDIA_PATH);
+ if (!File.new_for_path(origin_path).query_exists(null)) return;
+
var target_path = Path.build_filename(target, MEDIA_PATH);
- // TODO: non-system implementation of recursive copy
- Posix.system("cp -r %s %s".printf(origin_path, target_path));
+ recursive_copy(origin_path, target_path);
}
/**
diff --git a/src/ease-utilities.vala b/src/ease-utilities.vala
index a7954db..18995f0 100644
--- a/src/ease-utilities.vala
+++ b/src/ease-utilities.vala
@@ -189,14 +189,15 @@ namespace Ease
}
}
- public delegate void RecursiveDirAction(string path, string full_path);
+ public delegate void RecursiveDirAction(string path, string full_path)
+ throws GLib.Error;
/**
* Recursively removes a directory.
*
* @param path The directory to be recursively deleted.
*/
- public static void recursive_delete(string path) throws GLib.Error
+ public void recursive_delete(string path) throws GLib.Error
{
var dir = GLib.Dir.open(path, 0);
@@ -216,6 +217,32 @@ namespace Ease
DirUtils.remove(path);
}
+
+ /**
+ * Recursive copies a directory.
+ *
+ * @param from_dir The directory to copy from.
+ * @param to_dir The directory to copy to.
+ */
+ public void recursive_copy(string from_dir, string to_dir) throws GLib.Error
+ {
+ var top = File.new_for_path(to_dir);
+ if (!top.query_exists(null))
+ {
+ top.make_directory_with_parents(null);
+ }
+
+ recursive_directory(from_dir,
+ (path, full_path) => {
+ var dir = File.new_for_path(Path.build_filename(to_dir, path));
+ if (!dir.query_exists(null)) dir.make_directory(null);
+ },
+ (path, full_path) => {
+ var from = File.new_for_path(full_path);
+ var to = File.new_for_path(Path.build_filename(to_dir, path));
+ from.copy(to, FileCopyFlags.OVERWRITE, null, null);
+ });
+ }
public double dmax(double a, double b)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]