Skip to content

Commit

Permalink
Copy wrapper inputs to factory scratch directory (#2110)
Browse files Browse the repository at this point in the history
* Adds first pass at copying wrapper inputs to factory scratch dir

* Adds file and directory copying of wrapper inputs

* Fixes uninitialized variable

* Adds copy_direntry to header
Removes redundant file copy code

* Removes commented code
  • Loading branch information
nkremerh authored and dthain committed Aug 8, 2019
1 parent b697941 commit 6940cb0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions batch_job/src/work_queue_factory.c
Expand Up @@ -9,6 +9,7 @@ See the file COPYING for details.
#include "batch_job.h"
#include "hash_table.h"
#include "copy_stream.h"
#include "copy_tree.h"
#include "debug.h"
#include "domain_name_cache.h"
#include "envtools.h"
Expand Down Expand Up @@ -1080,6 +1081,7 @@ int main(int argc, char *argv[])
char *mesos_path = NULL;
char *mesos_preload = NULL;
char *k8s_image = NULL;
struct jx *wrapper_inputs = jx_array(NULL);

//Environment variable handling
char *ev = NULL;
Expand Down Expand Up @@ -1195,6 +1197,8 @@ int main(int argc, char *argv[])
} else {
wrapper_input = string_format("%s,%s",wrapper_input,optarg);
}
struct jx *file = jx_string(optarg);
jx_array_append(wrapper_inputs, file);
break;
case LONG_OPT_WORKER_BINARY:
worker_command = strdup(optarg);
Expand Down Expand Up @@ -1331,6 +1335,18 @@ int main(int argc, char *argv[])
return 1;
}

if(wrapper_input) {
struct jx *item;
for(void *i = NULL; (item = jx_iterate_array(wrapper_inputs, &i));) {
const char *value = item->u.string_value;
const char *file_at_scratch_dir = string_format("%s/%s", scratch_dir, path_basename(value));
int result = copy_direntry(value, file_at_scratch_dir);
if(result < 0) {
debug(D_NOTICE, "Cannot copy wrapper input file %s to factory scratch directory", value);
}
}
}

char* cmd;
if(worker_command != NULL){
cmd = string_format("cp '%s' '%s'",worker_command,scratch_dir);
Expand Down
9 changes: 9 additions & 0 deletions dttools/src/copy_tree.h
Expand Up @@ -23,6 +23,15 @@ int copy_dir(const char *source, const char *target);
*/
int copy_symlink(const char *source, const char *target);

/* copy_direntry copies the source dir or file into target. Like 'cp -r source target'.
* @param source: the source directory/file, which must be an existing directory/file.
* @param target: the target directory/file
* @return zero on success, non-zero on failure.
* If target does not exist, create the dir target and copy all the entries under the source dir into the target dir;
* If target exists, create a sub-dir basename(source) under target, and copy all the entries under the source dir into target/basename(source).
*/
int copy_direntry(const char *source, const char *target);

/* Only copy regular files, directories, and symlinks. */
typedef enum {
FILE_TYPE_REG,
Expand Down

0 comments on commit 6940cb0

Please sign in to comment.