[valadoc] File Helper: Copy directories recursively
- From: Ben Iofel <beniofel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [valadoc] File Helper: Copy directories recursively
- Date: Wed, 30 Mar 2016 22:00:56 +0000 (UTC)
commit 17cc99671ca715ef8472d4b09b51b6b77b0f4118
Author: Ben Iofel <iofelben gmail com>
Date: Wed Mar 30 17:58:57 2016 -0400
File Helper: Copy directories recursively
src/libvaladoc/filehelper.vala | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/libvaladoc/filehelper.vala b/src/libvaladoc/filehelper.vala
index 7dcbec8..bc2369b 100644
--- a/src/libvaladoc/filehelper.vala
+++ b/src/libvaladoc/filehelper.vala
@@ -57,14 +57,20 @@ namespace Valadoc {
* @param dest the destination path
*/
public bool copy_directory (string src, string dest) {
- string _src = (src.has_suffix ( "/" ))? src : src + "/";
- string _dest = (dest.has_suffix ( "/" ))? dest : dest + "/";
-
try {
- GLib.Dir dir = GLib.Dir.open (_src);
- for (weak string name = dir.read_name (); name != null ; name = dir.read_name ()) {
- if (!copy_file (_src+name, _dest+name)) {
- return false;
+ GLib.Dir dir = GLib.Dir.open (src);
+ for (string? file = dir.read_name (); file != null; file = dir.read_name ()) {
+ string src_file_path = GLib.Path.build_filename (src, file);
+ string dest_file_path = GLib.Path.build_filename (dest, file);
+ if (GLib.FileUtils.test (src_file_path, GLib.FileTest.IS_DIR)) {
+ GLib.DirUtils.create (dest_file_path, 0755); // mkdir if necessary
+ if (!copy_directory (src_file_path, dest_file_path)) { // copy
directories recursively
+ return false;
+ }
+ } else {
+ if (!copy_file (src_file_path, dest_file_path)) {
+ return false;
+ }
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]