From cc3a12eb37c1c87d13c9a1da3e377c8108560b15 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Thu, 30 Sep 2021 15:42:00 -0700 Subject: [PATCH 1/2] Avoid infinite recursion on dev machines when pipeline root is pointed at the reference study directory from the module's source tree --- ehr/src/org/labkey/ehr/EHRServiceImpl.java | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ehr/src/org/labkey/ehr/EHRServiceImpl.java b/ehr/src/org/labkey/ehr/EHRServiceImpl.java index e5016892e..d11144112 100644 --- a/ehr/src/org/labkey/ehr/EHRServiceImpl.java +++ b/ehr/src/org/labkey/ehr/EHRServiceImpl.java @@ -58,6 +58,7 @@ import org.labkey.api.query.FieldKey; import org.labkey.api.query.QueryService; import org.labkey.api.query.UserSchema; +import org.labkey.api.resource.FileResource; import org.labkey.api.resource.Resource; import org.labkey.api.security.SecurableResource; import org.labkey.api.security.SecurityPolicy; @@ -866,16 +867,29 @@ public void importStudyDefinition(Container container, User user, Module m, Path Resource root = m.getModuleResource(sourceStudyDirPath); PipeRoot pipeRoot = PipelineService.get().findPipelineRoot(container); java.nio.file.Path pipeRootPath = pipeRoot.getRootNioPath(); - java.nio.file.Path studyPath = pipeRootPath.resolve("upgradeStudyImport"); - if (Files.exists(studyPath)) + + java.nio.file.Path studyXmlPath; + + if (root instanceof FileResource && ((FileResource)root).getFile().equals(pipeRootPath.toFile())) + { + // The pipeline root is already pointed at the study definition's folder, like it might be on a dev machine. + // No need to copy, especially since copying can cause infinite recursion when the paths are nested + studyXmlPath = pipeRootPath.resolve("study.xml"); + } + else { - FileUtil.deleteDir(studyPath); + java.nio.file.Path studyPath = pipeRootPath.resolve("moduleStudyImport"); + studyXmlPath = studyPath.resolve("study.xml"); + if (Files.exists(studyPath)) + { + FileUtil.deleteDir(studyPath); + } + copyResourceToPath(root, studyPath); } - copyResourceToPath(root, studyPath); - java.nio.file.Path studyXmlPath = studyPath.resolve("study.xml"); + if (!Files.exists(studyXmlPath)) { - throw new FileNotFoundException("Couldn't find an extracted " + studyPath); + throw new FileNotFoundException("Couldn't find an extracted " + studyXmlPath); } ImportOptions options = new ImportOptions(container.getId(), user.getUserId()); options.setSkipQueryValidation(true); From c908ddf1347f65589dbffe3f997bc702edf547e6 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Thu, 30 Sep 2021 15:49:21 -0700 Subject: [PATCH 2/2] DirectoryResource instead of FileResource --- ehr/src/org/labkey/ehr/EHRServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ehr/src/org/labkey/ehr/EHRServiceImpl.java b/ehr/src/org/labkey/ehr/EHRServiceImpl.java index d11144112..4b1fe9142 100644 --- a/ehr/src/org/labkey/ehr/EHRServiceImpl.java +++ b/ehr/src/org/labkey/ehr/EHRServiceImpl.java @@ -58,6 +58,7 @@ import org.labkey.api.query.FieldKey; import org.labkey.api.query.QueryService; import org.labkey.api.query.UserSchema; +import org.labkey.api.resource.DirectoryResource; import org.labkey.api.resource.FileResource; import org.labkey.api.resource.Resource; import org.labkey.api.security.SecurableResource; @@ -870,7 +871,7 @@ public void importStudyDefinition(Container container, User user, Module m, Path java.nio.file.Path studyXmlPath; - if (root instanceof FileResource && ((FileResource)root).getFile().equals(pipeRootPath.toFile())) + if (root instanceof DirectoryResource && ((DirectoryResource)root).getDir().equals(pipeRootPath.toFile())) { // The pipeline root is already pointed at the study definition's folder, like it might be on a dev machine. // No need to copy, especially since copying can cause infinite recursion when the paths are nested