Commits

Tim Olsen committed b838122

Bug Fix: When XNAT attempts to move files which are located outside of the session directory, it fails miserably. For now, it should halt and throw an error.

  • Participants
  • Parent commits bf4a67b

Comments (0)

Files changed (2)

plugin-resources/webapp/xnat/java/org/nrg/xdat/om/base/BaseXnatExperimentdata.java

     		if(newLabel==null)newLabel = this.getLabel();
     		if(newLabel==null)newLabel = this.getId();
     		
-    		File newSessionDir = new File(new File(newProject.getRootArchivePath(),newProject.getCurrentArc()),newLabel);
+    		final File newSessionDir = new File(new File(newProject.getRootArchivePath(),newProject.getCurrentArc()),newLabel);
     		
     		String current_label=this.getLabel();
     		if(current_label==null)current_label=this.getId();
         				existingSessionDir=uri.substring(0,lastIndex);
         			}else{
         				//outside session_dir
-        				newSessionDir = new File(newSessionDir,"RESOURCES");
-        				newSessionDir = new File(newSessionDir,"RESOURCES/"+abstRes.getXnatAbstractresourceId());
-        				int lastSlash=uri.lastIndexOf("/");
-        				if(uri.lastIndexOf("\\")>lastSlash){
-        					lastSlash=uri.lastIndexOf("\\");
-        				}
-        				existingSessionDir=uri.substring(0,lastSlash);
+//        				newSessionDir = new File(newSessionDir,"RESOURCES");
+//        				newSessionDir = new File(newSessionDir,"RESOURCES/"+abstRes.getXnatAbstractresourceId());
+//        				int lastSlash=uri.lastIndexOf("/");
+//        				if(uri.lastIndexOf("\\")>lastSlash){
+//        					lastSlash=uri.lastIndexOf("\\");
+//        				}
+//        				existingSessionDir=uri.substring(0,lastSlash);
+        				//don't attempt to move sessions which are outside of the Session Directory.
+        				throw new Exception("Non-standard file location for file(s):" + uri);
         			}
         			abstRes.moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
     			}else{
 		
 		if(newLabel==null)return;
 		
-		File newSessionDir = new File(new File(proj.getRootArchivePath(),proj.getCurrentArc()),newLabel);
+		final File newSessionDir = new File(new File(proj.getRootArchivePath(),proj.getCurrentArc()),newLabel);
 		
 		String current_label=this.getLabel();
 		if(current_label==null)current_label=this.getId();
     				existingSessionDir=uri.substring(0,lastIndex);
     			}else{
     				//outside session_dir
-    				newSessionDir = new File(newSessionDir,"RESOURCES");
-    				newSessionDir = new File(newSessionDir,"RESOURCES/"+abstRes.getXnatAbstractresourceId());
-    				int lastSlash=uri.lastIndexOf("/");
-    				if(uri.lastIndexOf("\\")>lastSlash){
-    					lastSlash=uri.lastIndexOf("\\");
-    				}
-    				existingSessionDir=uri.substring(0,lastSlash);
+//    				newSessionDir = new File(newSessionDir,"RESOURCES");
+//    				newSessionDir = new File(newSessionDir,"RESOURCES/"+abstRes.getXnatAbstractresourceId());
+//    				int lastSlash=uri.lastIndexOf("/");
+//    				if(uri.lastIndexOf("\\")>lastSlash){
+//    					lastSlash=uri.lastIndexOf("\\");
+//    				}
+//    				existingSessionDir=uri.substring(0,lastSlash);
+    				//don't attempt to move sessions which are outside of the Session Directory.
+    				throw new Exception("Non-standard file location for file(s):" + uri);
     			}
     			abstRes.moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
 			}else{

plugin-resources/webapp/xnat/java/org/nrg/xdat/om/base/BaseXnatImagesessiondata.java

     		if(newLabel==null)newLabel = this.getLabel();
     		if(newLabel==null)newLabel = this.getId();
     		
-    		File newSessionDir = new File(new File(newProject.getRootArchivePath(),newProject.getCurrentArc()),newLabel);
+    		final File newSessionDir = new File(new File(newProject.getRootArchivePath(),newProject.getCurrentArc()),newLabel);
     		
     		String current_label=this.getLabel();
     		if(current_label==null)current_label=this.getId();
             				existingSessionDir=uri.substring(0,lastIndex);
             			}else{
             				//outside session_dir
-            				newSessionDir = new File(new File(newSessionDir,"SCANS"),scan.getId());
-            				int lastSlash=uri.lastIndexOf("/");
-            				if(uri.lastIndexOf("\\")>lastSlash){
-            					lastSlash=uri.lastIndexOf("\\");
-            				}
-            				existingSessionDir=uri.substring(0,lastSlash);
+//            				newSessionDir = new File(new File(newSessionDir,"SCANS"),scan.getId());
+//            				int lastSlash=uri.lastIndexOf("/");
+//            				if(uri.lastIndexOf("\\")>lastSlash){
+//            					lastSlash=uri.lastIndexOf("\\");
+//            				}
+//            				existingSessionDir=uri.substring(0,lastSlash);
+            				//don't attempt to move sessions which are outside of the Session Directory.
+            				throw new Exception("Non-standard file location for file(s):" + uri);
             			}
             			abstRes.moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
         			}else{
             				existingSessionDir=uri.substring(0,lastIndex);
             			}else{
             				//outside session_dir
-            				newSessionDir = new File(new File(newSessionDir,"PROCESSED"),recon.getId());
-            				int lastSlash=uri.lastIndexOf("/");
-            				if(uri.lastIndexOf("\\")>lastSlash){
-            					lastSlash=uri.lastIndexOf("\\");
-            				}
-            				existingSessionDir=uri.substring(0,lastSlash);
+//            				newSessionDir = new File(new File(newSessionDir,"PROCESSED"),recon.getId());
+//            				int lastSlash=uri.lastIndexOf("/");
+//            				if(uri.lastIndexOf("\\")>lastSlash){
+//            					lastSlash=uri.lastIndexOf("\\");
+//            				}
+//            				existingSessionDir=uri.substring(0,lastSlash);
+            				//don't attempt to move sessions which are outside of the Session Directory.
+            				throw new Exception("Non-standard file location for file(s):" + uri);
             			}
             			abstRes.moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
         			}else{
             				existingSessionDir=uri.substring(0,lastIndex);
             			}else{
             				//outside session_dir
-            				newSessionDir = new File(new File(newSessionDir,"ASSESSORS"),assessor.getId());
-            				int lastSlash=uri.lastIndexOf("/");
-            				if(uri.lastIndexOf("\\")>lastSlash){
-            					lastSlash=uri.lastIndexOf("\\");
-            				}
-            				existingSessionDir=uri.substring(0,lastSlash);
+//            				newSessionDir = new File(new File(newSessionDir,"ASSESSORS"),assessor.getId());
+//            				int lastSlash=uri.lastIndexOf("/");
+//            				if(uri.lastIndexOf("\\")>lastSlash){
+//            					lastSlash=uri.lastIndexOf("\\");
+//            				}
+//            				existingSessionDir=uri.substring(0,lastSlash);
+            				//don't attempt to move sessions which are outside of the Session Directory.
+            				throw new Exception("Non-standard file location for file(s):" + uri);
             			}
             			abstRes.moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
         			}else{
     		
     		if(newLabel==null)return;
     		
-    		File newSessionDir = new File(new File(proj.getRootArchivePath(),proj.getCurrentArc()),newLabel);
+    		final File newSessionDir = new File(new File(proj.getRootArchivePath(),proj.getCurrentArc()),newLabel);
     		
     		String current_label=this.getLabel();
     		if(current_label==null)current_label=this.getId();
             					lastIndex+=1+this.getId().length();
             				}
         				}
+        				
         				String existingSessionDir=null;
         				if(lastIndex>-1){
             				//in session_dir
             				existingSessionDir=uri.substring(0,lastIndex);
             			}else{
             				//outside session_dir
-            				newSessionDir = new File(new File(newSessionDir,"SCANS"),scan.getId());
-            				int lastSlash=uri.lastIndexOf("/");
-            				if(uri.lastIndexOf("\\")>lastSlash){
-            					lastSlash=uri.lastIndexOf("\\");
-            				}
-            				existingSessionDir=uri.substring(0,lastSlash);
+//            				newSessionDir = new File(new File(newSessionDir,"SCANS"),scan.getId());
+//            				int lastSlash=uri.lastIndexOf("/");
+//            				if(uri.lastIndexOf("\\")>lastSlash){
+//            					lastSlash=uri.lastIndexOf("\\");
+//            				}
+//            				existingSessionDir=uri.substring(0,lastSlash);
+            				//don't attempt to move sessions which are outside of the Session Directory.
+            				throw new Exception("Non-standard file location for file(s):" + uri);
             			}
             			abstRes.moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
         			}else{
             				existingSessionDir=uri.substring(0,lastIndex);
             			}else{
             				//outside session_dir
-            				newSessionDir = new File(new File(newSessionDir,"PROCESSED"),recon.getId());
-            				int lastSlash=uri.lastIndexOf("/");
-            				if(uri.lastIndexOf("\\")>lastSlash){
-            					lastSlash=uri.lastIndexOf("\\");
-            				}
-            				existingSessionDir=uri.substring(0,lastSlash);
+//            				newSessionDir = new File(new File(newSessionDir,"PROCESSED"),recon.getId());
+//            				int lastSlash=uri.lastIndexOf("/");
+//            				if(uri.lastIndexOf("\\")>lastSlash){
+//            					lastSlash=uri.lastIndexOf("\\");
+//            				}
+//            				existingSessionDir=uri.substring(0,lastSlash);
+            				//don't attempt to move sessions which are outside of the Session Directory.
+            				throw new Exception("Non-standard file location for file(s):" + uri);
             			}
             			abstRes.moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
         			}else{
             				existingSessionDir=uri.substring(0,lastIndex);
             			}else{
             				//outside session_dir
-            				newSessionDir = new File(new File(newSessionDir,"ASSESSORS"),assessor.getId());
-            				int lastSlash=uri.lastIndexOf("/");
-            				if(uri.lastIndexOf("\\")>lastSlash){
-            					lastSlash=uri.lastIndexOf("\\");
-            				}
-            				existingSessionDir=uri.substring(0,lastSlash);
+//            				newSessionDir = new File(new File(newSessionDir,"ASSESSORS"),assessor.getId());
+//            				int lastSlash=uri.lastIndexOf("/");
+//            				if(uri.lastIndexOf("\\")>lastSlash){
+//            					lastSlash=uri.lastIndexOf("\\");
+//            				}
+//            				existingSessionDir=uri.substring(0,lastSlash);
+            				//don't attempt to move sessions which are outside of the Session Directory.
+            				throw new Exception("Non-standard file location for file(s):" + uri);
             			}
             			abstRes.moveTo(newSessionDir,existingSessionDir,existingRootPath,user);
         			}else{