diff --git a/golem/task/localcomputer.py b/golem/task/localcomputer.py index c1be5ec678..b9312bd98f 100644 --- a/golem/task/localcomputer.py +++ b/golem/task/localcomputer.py @@ -133,11 +133,27 @@ def onerror(func, target_path, exc_info): shutil.rmtree(self.test_task_res_path, onerror=onerror) if resources: - if len(resources) == 1: - path = os.path.dirname(resources[0]) + if len(resources) == 1 and os.path.isdir(resources[0]): + shutil.copytree(resources[0], self.test_task_res_path) else: - path = common_dir(resources) - shutil.copytree(path, self.test_task_res_path) + # no trailing separator + if len(resources) == 1: + base_dir = os.path.dirname(resources[0]) + else: + base_dir = common_dir(resources) + + base_dir = os.path.normpath(base_dir) + + for resource in filter(None, resources): + norm_path = os.path.normpath(resource) + + sub_path = norm_path.replace(base_dir + os.path.sep, '', 1) + sub_dir = os.path.dirname(sub_path) + dst_dir = os.path.join(self.test_task_res_path, sub_dir) + os.makedirs(dst_dir, exist_ok=True) + + name = os.path.basename(resource) + shutil.copy2(resource, os.path.join(dst_dir, name)) for res in self.additional_resources: if not os.path.exists(self.test_task_res_path): diff --git a/tests/golem/task/test_localcomputer.py b/tests/golem/task/test_localcomputer.py index f651f7d928..38ddf3a621 100644 --- a/tests/golem/task/test_localcomputer.py +++ b/tests/golem/task/test_localcomputer.py @@ -102,6 +102,9 @@ def reset_permissions(_path): resources = [os.path.join(resource_dir, 'file')] Path(existing_file).touch() + for resource in resources: + Path(resource).touch() + remove_permissions(existing_file) lc._prepare_resources(resources)