Author: kcardineaud Date: 2011-06-24 16:18:08 +0200 (Fri, 24 Jun 2011) New Revision: 137 Url: http://nuiton.org/repositories/revision/scmwebeditor/137 Log: The upload file function checkout the repository in a temp directory before commit Modified: 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/actions/ScmWebEditorCommitAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-24 13:43:55 UTC (rev 136) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-24 14:18:08 UTC (rev 137) @@ -171,9 +171,9 @@ } catch (IOException e) { log.error("Can't find the checkout file",e); } - + /* * Commit process */ Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-06-24 13:43:55 UTC (rev 136) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-06-24 14:18:08 UTC (rev 137) @@ -1,6 +1,7 @@ package org.nuiton.scmwebeditor.actions; import java.io.File; + import java.io.IOException; import javax.servlet.http.HttpServletRequest; @@ -16,6 +17,8 @@ import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.wc.SVNClientManager; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.SVNUpdateClient; import com.opensymphony.xwork2.Action; @@ -87,7 +90,52 @@ HttpSession httpSession = request.getSession(true); SvnSession svnSess = getSvnSession(httpSession); + + + +// Resetting authentification information and manager + svnSess.updateAuthentication( + svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : username, + svnSess.getPassword() != null && !svnSess.getPassword().equalsIgnoreCase("") ? svnSess.getPassword() : pw); + + + /* + * Checkout process + */ + SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); + + + try { + if (log.isDebugEnabled()) { + log.debug("Do Checkout of " + svnSess.getRemoteUrl()); + } + upclient.doCheckout(svnSess.getRemoteUrl(), svnSess.getCheckoutdir(), + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + } catch (SVNAuthenticationException authexep) { + + // if svn authentication failed user is redirected on login page + if(log.isDebugEnabled()) { + log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); + } + //On supprime le repertoire temporaire + delTempDirectory(svnSess); + //redirect to a login page + return "error"; + + } catch (SVNException e) { + //Suppression du repertoire temporaire + delTempDirectory(svnSess); + return "error"; + } + + File checkoutDir = svnSess.getCheckoutdir(); + + + + //Copy file in checkourdir + + String checkoutPath = checkoutDir.getAbsolutePath(); File file = new File(checkoutPath,uploadFileName); @@ -98,15 +146,13 @@ } catch (IOException e) { log.error("Can't copy the file to the checkout directory",e); } - -// Resetting authentification information and manager - svnSess.updateAuthentication( - svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : username, - svnSess.getPassword() != null && !svnSess.getPassword().equalsIgnoreCase("") ? svnSess.getPassword() : pw); + + //Commit process + SVNClientManager manager = svnSess.getManager(); File[] tabFile = new File[1]; @@ -120,15 +166,20 @@ } catch (SVNAuthenticationException authexep) { log.error("authentification fail"); request.setAttribute(ATTRIBUTE_BAD_LOGIN, true); + //Suppression du repertoire temporaire + delTempDirectory(svnSess); return Action.LOGIN; } catch (SVNException e) { log.error("Erreur SVN",e); request.setAttribute("error", true); + //Suppression du repertoire temporaire + delTempDirectory(svnSess); return Action.ERROR; } - + //Suppression du repertoire temporaire + delTempDirectory(svnSess); return Action.SUCCESS; }