Author: kcardineaud Date: 2011-07-28 17:01:30 +0200 (Thu, 28 Jul 2011) New Revision: 192 Url: http://nuiton.org/repositories/revision/scmwebeditor/192 Log: Change the way to create the temp directory Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-07-28 13:55:23 UTC (rev 191) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-07-28 15:01:30 UTC (rev 192) @@ -186,22 +186,22 @@ } - public void checkout(SvnSession svnSess) throws SVNException { + public void checkout(SvnSession svnSess, File checkoutdir) throws SVNException { SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); if (log.isDebugEnabled()) { log.debug("Do Checkout of " + svnSess.getRemoteUrl()); } - upclient.doCheckout(svnSess.getRemoteUrl(), svnSess.getCheckoutdir(), + upclient.doCheckout(svnSess.getRemoteUrl(), checkoutdir, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); } - public void delTempDirectory(SvnSession svnSess) { + public void delTempDirectory(File checkoutdir) { try { - FileUtils.deleteDirectory(svnSess.getCheckoutdir()); + FileUtils.deleteDirectory(checkoutdir); } catch (IOException e) { if(log.isErrorEnabled()) { log.error("Can't delete temp directory"); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-07-28 13:55:23 UTC (rev 191) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-07-28 15:01:30 UTC (rev 192) @@ -15,6 +15,7 @@ import org.nuiton.jrst.JRST; import org.nuiton.scmwebeditor.ScmWebEditorBaseAction; import org.nuiton.scmwebeditor.SvnSession; +import org.nuiton.util.FileUtil; import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; @@ -111,6 +112,7 @@ protected boolean testRstParsing(String newText) { try { + JRST.generate(JRST.TYPE_HTML, newText); if(log.isDebugEnabled()) { log.debug("RST generate success"); } @@ -145,8 +147,9 @@ svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : username, svnSess.getPassword() != null && !svnSess.getPassword().equalsIgnoreCase("") ? svnSess.getPassword() : pw); + File checkoutdir = null; try { - svnSess.createCheckoutdir(); + checkoutdir = FileUtil.createTempDirectory("scm_", ""); } catch (IOException e1) { if(log.isErrorEnabled()) { log.error("Can't create checkoutDir",e1); @@ -157,7 +160,7 @@ // Avant le commit, il faut checkout le repertoire try { - checkout(svnSess); + checkout(svnSess, checkoutdir); } catch (SVNAuthenticationException authexep) { request.setAttribute(PARAMETER_ADDRESS, address); @@ -166,18 +169,18 @@ log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); } //On supprime le repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutdir); //redirect to a login page return Action.LOGIN; } catch (SVNException e) { //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutdir); return "errorPath"; } - File checkOutFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); + File checkOutFile = new File(checkoutdir, svnSess.getFileName()); lastText=newText; @@ -204,7 +207,7 @@ /* fichier non trouve, on redirige vers BadFileRedirect.jsp * après avoir supprimé le repertoire temporaire */ - delTempDirectory(svnSess); + delTempDirectory(checkoutdir); request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl()); return "error"; } catch (IOException e) { @@ -216,7 +219,7 @@ /* * Commit process */ - File pathToFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); + File pathToFile = new File(checkoutdir, svnSess.getFileName()); SVNCommitClient commitClient = new SVNCommitClient(svnSess.getManager(), svnSess.getSvnOption()); try { @@ -261,22 +264,22 @@ request.setAttribute(ATTRIBUTE_BAD_LOGIN, true); //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutdir); return Action.LOGIN; } catch (SVNException e) { if(log.isErrorEnabled()) { log.error("SVN FAIL",e); } //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutdir); request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess)); return "error"; } - if (svnSess.getCheckoutdir() != null) { + if (checkoutdir != null) { //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutdir); } //if commit success user is redirect on the project page request.setAttribute(ATTRIBUTE_REDIRECTION_URL, svnSess.getProjectUrl()); @@ -285,7 +288,7 @@ log.debug("End of commit"); } //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutdir); if(log.isInfoEnabled()) { log.info(username + " with IP "+request.getRemoteAddr()+" commit the file "+address+" with message : "+commitMessage); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-07-28 13:55:23 UTC (rev 191) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-07-28 15:01:30 UTC (rev 192) @@ -13,6 +13,7 @@ import org.apache.struts2.interceptor.ServletRequestAware; import org.nuiton.scmwebeditor.ScmWebEditorBaseAction; import org.nuiton.scmwebeditor.SvnSession; +import org.nuiton.util.FileUtil; import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; @@ -114,7 +115,9 @@ */ SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); + File checkoutDir = null; try { + checkoutDir = FileUtil.createTempDirectory("scm_", ""); svnSess.createCheckoutdir(); } catch (IOException e1) { if(log.isErrorEnabled()) { @@ -129,7 +132,7 @@ if (log.isDebugEnabled()) { log.debug("Do Checkout of " + svnSess.getRemoteUrl()); } - upclient.doCheckout(svnSess.getRemoteUrl(), svnSess.getCheckoutdir(), + upclient.doCheckout(svnSess.getRemoteUrl(), checkoutDir, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false); } catch (SVNAuthenticationException authexep) { @@ -138,20 +141,20 @@ log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); } //On supprime le repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutDir); //redirect to a login page error=true; return "error"; } catch (SVNException e) { //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutDir); error=true; return "error"; } - File checkoutDir = svnSess.getCheckoutdir(); + //On test si le chemin commence par un / si non, on l'ajoute @@ -207,7 +210,7 @@ } error=true; //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutDir); return Action.ERROR; } @@ -229,7 +232,7 @@ } badLogin=true; //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutDir); return Action.LOGIN; } catch (SVNException e) { @@ -238,13 +241,13 @@ } error=true; //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutDir); return ERROR; } //Suppression du repertoire temporaire - delTempDirectory(svnSess); + delTempDirectory(checkoutDir); if(log.isDebugEnabled()) { log.debug("File upload successful");