From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 07/11] libfile: Add copy_recursive
Date: Thu, 6 Nov 2014 13:59:34 +0100 [thread overview]
Message-ID: <1415278778-20826-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1415278778-20826-1-git-send-email-s.hauer@pengutronix.de>
To recursively copy a directory tree.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/libfile.h | 2 ++
lib/libfile.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/include/libfile.h b/include/libfile.h
index 6c48ce0..d5b914a 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -15,6 +15,8 @@ int write_file(const char *filename, void *buf, size_t size);
int copy_file(const char *src, const char *dst, int verbose);
+int copy_recursive(const char *src, const char *dst);
+
int compare_file(const char *f1, const char *f2);
#endif /* __LIBFILE_H */
diff --git a/lib/libfile.c b/lib/libfile.c
index 7ed4b93..8acff04 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -332,6 +332,46 @@ out:
}
EXPORT_SYMBOL(copy_file);
+int copy_recursive(const char *src, const char *dst)
+{
+ struct stat s;
+ DIR *dir;
+ struct dirent *d;
+ int ret;
+
+ ret = stat(src, &s);
+ if (ret)
+ return ret;
+
+ if (!S_ISDIR(s.st_mode))
+ return copy_file(src, dst, 0);
+
+ ret = make_directory(dst);
+ if (ret)
+ return ret;
+
+ dir = opendir(src);
+ if (!dir)
+ return -EIO;
+
+ while ((d = readdir(dir))) {
+ char *from, *to;
+ if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+ continue;
+
+ from = asprintf("%s/%s", src, d->d_name);
+ to = asprintf("%s/%s", dst, d->d_name);
+ ret = copy_recursive(from, to);
+ if (ret)
+ break;
+ free(from);
+ free(to);
+ }
+ closedir(dir);
+
+ return ret;
+}
+
/**
* compare_file - Compare two files
* @f1: The first file
--
2.1.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-11-06 13:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-06 12:59 non volatile variables and incremental envrironment Sascha Hauer
2014-11-06 12:59 ` [PATCH 01/11] environment: drop unnecessary casts Sascha Hauer
2014-11-06 12:59 ` [PATCH 02/11] environment: remove unused variable Sascha Hauer
2014-11-06 12:59 ` [PATCH 03/11] environment: refactor saveenv Sascha Hauer
2014-11-06 12:59 ` [PATCH 04/11] environment: Only save changes to the defaultenv Sascha Hauer
2014-11-06 12:59 ` [PATCH 05/11] magicvar: Add support for dynamically added magicvars Sascha Hauer
2014-11-06 12:59 ` [PATCH 06/11] Add support for non volatile variables Sascha Hauer
2014-11-06 12:59 ` Sascha Hauer [this message]
2014-11-06 12:59 ` [PATCH 08/11] cp: Add recursive copy Sascha Hauer
2014-11-06 12:59 ` [PATCH 09/11] Add defaultenv command Sascha Hauer
2014-11-06 12:59 ` [PATCH 10/11] globalvar: Add support for printing all global variables Sascha Hauer
2014-11-06 12:59 ` [PATCH 11/11] defaultenv-2: Make use of nonvolatile variables Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415278778-20826-8-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox