r125 - in trunk/src/main: java/org/nuiton/scmwebeditor java/org/nuiton/scmwebeditor/actions resources
Author: kcardineaud Date: 2011-06-17 17:24:35 +0200 (Fri, 17 Jun 2011) New Revision: 125 Url: http://nuiton.org/repositories/revision/scmwebeditor/125 Log: Add a method in AbstractScmWebEditor to delete the temporary directory Modified: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java trunk/src/main/resources/struts.xml Modified: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-17 14:43:57 UTC (rev 124) +++ trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-17 15:24:35 UTC (rev 125) @@ -25,6 +25,8 @@ package org.nuiton.scmwebeditor; import info.monitorenter.cpdetector.io.*; + +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -77,6 +79,7 @@ protected static final String ATTRIBUTE_INVALIDATE_MAX_TIME = "InvalidateMaxTime"; protected static final String ATTRIBUTE_LOGIN = "Login"; protected static final String ATTRIBUTE_IS_LOGIN = "IsLogin"; + protected static final String ATTRIBUTE_BAD_LOGIN = "badLogin"; protected static final String ATTRIBUTE_PROJECT_URL = "Project_url"; protected static final String ATTRIBUTE_SCM_EDITOR_URI = "scmEditorUri"; protected static final String ATTRIBUTE_PREVIEW_SERVLET_URL = "previewServletUrl"; @@ -173,6 +176,17 @@ } } } + + public void delTempDirectory(SvnSession svnSess) { + try { + FileUtils.deleteDirectory(svnSess.getCheckoutdir()); + } catch (IOException e) { + if(log.isErrorEnabled()) { + log.error("Can't delete temp directory"); + } + } + } + protected SvnSession getSvnSession(HttpSession httpSession) { SvnSession svnSess = (SvnSession) httpSession.getAttribute(ATTRIBUTE_SVN_SESSION); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-17 14:43:57 UTC (rev 124) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-17 15:24:35 UTC (rev 125) @@ -116,7 +116,6 @@ svnSess.setLogin(null); svnSess.setPassword(null); // if authentication failed edition page is reload form user's relogin - log.debug("AUTH REDIRECT"+getRedirectUrl(svnSess)); request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat()); request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(newText)); request.setAttribute(ATTRIBUTE_INVALIDATE_MAX_TIME, (httpSession.getMaxInactiveInterval() / 60)); @@ -127,28 +126,22 @@ request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI()); request.setAttribute(ATTRIBUTE_PREVIEW_SERVLET_URL, request.getContextPath() + "/previewservlet"); - request.setAttribute("badLogin", true); + request.setAttribute(ATTRIBUTE_BAD_LOGIN, true); return "authError"; } catch (SVNException e) { if(log.isErrorEnabled()) { log.error("SVN FAIL",e); } + //Suppression du repertoire temporaire + delTempDirectory(svnSess); request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess)); - return "ko"; + return "erreur"; } } if (svnSess.getCheckoutdir() != null) { - if(log.isDebugEnabled()) { - log.debug("Delete tempdir"); - } - try { - FileUtils.deleteDirectory(svnSess.getCheckoutdir()); - } catch (IOException e) { - if(log.isErrorEnabled()) { - log.error("Can't delete the temp dir",e); - } - } + //Suppression du repertoire temporaire + delTempDirectory(svnSess); } //if commit success user is redirect on the project page request.setAttribute(ATTRIBUTE_REDIRECTION_URL, svnSess.getProjectUrl()); @@ -156,6 +149,8 @@ if(log.isDebugEnabled()) { log.debug("End of commit"); } + //Suppression du repertoire temporaire + delTempDirectory(svnSess); return "success"; } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 14:43:57 UTC (rev 124) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 15:24:35 UTC (rev 125) @@ -142,25 +142,13 @@ log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); } //Suppression du repertoire temporaire - try { - svnSess.cleanCheckoutDir(); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can't delete temp directory",e); - } - } + delTempDirectory(svnSess); //redirect to a login page return "login"; } catch (SVNException e) { //Suppression du repertoire temporaire - try { - svnSess.cleanCheckoutDir(); - } catch (IOException ee) { - if(log.isErrorEnabled()) { - log.error("Can't delete temp directory"); - } - } + delTempDirectory(svnSess); return "erreurPath"; } @@ -187,13 +175,7 @@ /* fichier non trouve, on redirige vers BadFileRedirect.jsp * après avoir supprimé le repertoire temporaire */ - try { - FileUtils.deleteDirectory(svnSess.getCheckoutdir()); - } catch (IOException e) { - if(log.isErrorEnabled()) { - log.error("Can't delete temp directory"); - } - } + delTempDirectory(svnSess); request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl()); return "erreurPath"; } catch (IOException e) { @@ -213,5 +195,6 @@ } + } Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-06-17 14:43:57 UTC (rev 124) +++ trunk/src/main/resources/struts.xml 2011-06-17 15:24:35 UTC (rev 125) @@ -14,7 +14,7 @@ <action name="commit" class="org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction" method="execute"> <result name="success" >/Redirect.jsp</result> <result name="authError" >/ModificationViewer.jsp</result> - <result name="ko">/BadFileRedirect.jsp</result> + <result name="erreur">/BadFileRedirect.jsp</result> </action> </package> </struts> \ No newline at end of file
participants (1)
-
kcardineaud@users.nuiton.org