summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Samuels <richard.l.samuels@gmail.com>2021-08-04 16:27:21 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-17 14:56:54 +0000
commit4c04e869d3d164f2133aa4ecb62e4480a0c670bf (patch)
treece09bb74d4d797d9d73b3b986968a6fa58392ddc
parent044cd0058a294d9dadedb15fcabce25e3c2c43a0 (diff)
downloadmongo-4c04e869d3d164f2133aa4ecb62e4480a0c670bf.tar.gz
SERVER-59236 add shell function to recursively copy a directory
(cherry picked from commit 4cdb2c6340c7c13be51ba12e0f3d5437e27c9bf0)
-rw-r--r--src/mongo/shell/shell_utils_extended.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/shell/shell_utils_extended.cpp b/src/mongo/shell/shell_utils_extended.cpp
index 796ca0e529a..550125c33ac 100644
--- a/src/mongo/shell/shell_utils_extended.cpp
+++ b/src/mongo/shell/shell_utils_extended.cpp
@@ -295,6 +295,22 @@ BSONObj mkdir(const BSONObj& args, void* data) {
return wrapper.obj();
}
+/**
+ * @param args - [ source, destination ]
+ * copies directory 'source' to 'destination'. Errors if the 'destination' file already exists.
+ */
+BSONObj copyDir(const BSONObj& args, void* data) {
+ uassert(8423308, "copyDir takes 2 arguments", args.nFields() == 2);
+
+ BSONObjIterator it(args);
+ const std::string source = it.next().str();
+ const std::string destination = it.next().str();
+
+ boost::filesystem::copy(source, destination, boost::filesystem::copy_options::recursive);
+
+ return undefinedReturn;
+}
+
BSONObj removeFile(const BSONObj& args, void* data) {
BSONElement e = singleArg(args);
bool found = false;
@@ -528,6 +544,7 @@ void installShellUtilsExtended(Scope& scope) {
scope.injectNative("hostname", hostname);
scope.injectNative("md5sumFile", md5sumFile);
scope.injectNative("mkdir", mkdir);
+ scope.injectNative("copyDir", copyDir);
scope.injectNative("passwordPrompt", passwordPrompt);
scope.injectNative("umask", changeUmask);
scope.injectNative("getFileMode", getFileMode);