mirror of
				https://github.com/gitbucket/gitbucket.git
				synced 2025-10-30 18:15:59 +01:00 
			
		
		
		
	(refs #476)Change Jetty temp directory to GITBUCKET_HOME/tmp
This commit is contained in:
		| @@ -2,6 +2,7 @@ import org.eclipse.jetty.server.Server; | ||||
| import org.eclipse.jetty.server.nio.SelectChannelConnector; | ||||
| import org.eclipse.jetty.webapp.WebAppContext; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.net.URL; | ||||
| import java.security.ProtectionDomain; | ||||
|  | ||||
| @@ -41,6 +42,14 @@ public class JettyLauncher { | ||||
|         server.addConnector(connector); | ||||
|  | ||||
|         WebAppContext context = new WebAppContext(); | ||||
|  | ||||
|         File tmpDir = new File(getGitBucketHome(), "tmp"); | ||||
|         if(tmpDir.exists()){ | ||||
|             deleteDirectory(tmpDir); | ||||
|         } | ||||
|         tmpDir.mkdirs(); | ||||
|         context.setTempDirectory(tmpDir); | ||||
|  | ||||
|         ProtectionDomain domain = JettyLauncher.class.getProtectionDomain(); | ||||
|         URL location = domain.getCodeSource().getLocation(); | ||||
|  | ||||
| @@ -56,4 +65,27 @@ public class JettyLauncher { | ||||
|         server.start(); | ||||
|         server.join(); | ||||
|     } | ||||
|  | ||||
|     private static File getGitBucketHome(){ | ||||
|         String home = System.getProperty("gitbucket.home"); | ||||
|         if(home != null && home.length() > 0){ | ||||
|             return new File(home); | ||||
|         } | ||||
|         home = System.getenv("GITBUCKET_HOME"); | ||||
|         if(home != null && home.length() > 0){ | ||||
|             return new File(home); | ||||
|         } | ||||
|         return new File(System.getProperty("user.home"), ".gitbucket"); | ||||
|     } | ||||
|  | ||||
|     private static void deleteDirectory(File dir){ | ||||
|         for(File file: dir.listFiles()){ | ||||
|             if(file.isFile()){ | ||||
|                 file.delete(); | ||||
|             } else if(file.isDirectory()){ | ||||
|                 deleteDirectory(file); | ||||
|             } | ||||
|         } | ||||
|         dir.delete(); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user