Author: kcardineaud Date: 2011-06-29 16:07:46 +0200 (Wed, 29 Jun 2011) New Revision: 140 Url: http://nuiton.org/repositories/revision/scmwebeditor/140 Log: Upload files can now be place at a specific directory in the svn (but only children directory for the moment) Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-06-28 15:36:36 UTC (rev 139) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-06-29 14:07:46 UTC (rev 140) @@ -78,6 +78,7 @@ public String execute() { + if(log.isInfoEnabled()) { log.info("PictureName : "+uploadFileName); @@ -110,7 +111,7 @@ log.debug("Do Checkout of " + svnSess.getRemoteUrl()); } upclient.doCheckout(svnSess.getRemoteUrl(), svnSess.getCheckoutdir(), - SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false); } catch (SVNAuthenticationException authexep) { // if svn authentication failed user is redirected on login page @@ -131,16 +132,24 @@ File checkoutDir = svnSess.getCheckoutdir(); + + + //On test si le chemin commence par un / si non, on l'ajoute + if(!svnPath.startsWith("/")) { + svnPath="/"+svnPath; + } + //On test si le chemin se termine par un / si non, on l'ajoute + if(!svnPath.endsWith("/")) { + svnPath+=("/"); + } + //Copy file in checkourdir - - String checkoutPath = checkoutDir.getAbsolutePath(); - File file = new File(checkoutPath,uploadFileName); + File file = new File(checkoutPath+svnPath,uploadFileName); - try { FileUtils.copyFile(upload, file); } catch (IOException e) { @@ -151,39 +160,70 @@ //Commit process - - + SVNClientManager manager = svnSess.getManager(); + + + try { + + if(log.isDebugEnabled()) { + log.debug("leSvnPath : "+checkoutPath+svnPath+uploadFileName); + } + + //On ajoute le repertoire + manager.getWCClient().doAdd( file , false , false , false , SVNDepth.EMPTY, false, true ); + if(log.isDebugEnabled()) { + log.debug("Add success !"); + } + //On ajoute l'image aux fichiers versionnés + + } + catch (SVNException e) { + log.error("Erreur SVN Add",e); + request.setAttribute("error", true); + //Suppression du repertoire temporaire + delTempDirectory(svnSess); + return Action.ERROR; + } + + - File[] tabFile = new File[1]; - tabFile[0] = file; - + File[] checkoutDirTab = new File[1]; + checkoutDirTab[0] = checkoutDir; + try { - //On ajoute l'image aux fichiers versionnés - manager.getWCClient().doAdd( file , false , false , false , SVNDepth.FILES, false, false ); - //On commit la modification - manager.getCommitClient().doCommit(tabFile, false, "From scmwebeditor -- add the file : "+uploadFileName, null, null, false, true, SVNDepth.FILES); + manager.getCommitClient().doCommit(checkoutDirTab, false, "From scmwebeditor -- add the file : "+uploadFileName, null, null, false, true, SVNDepth.INFINITY); + + if(log.isDebugEnabled()) { + log.debug("Commit success !"); + } + } 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); + log.error("Erreur SVN commit",e); request.setAttribute("error", true); //Suppression du repertoire temporaire delTempDirectory(svnSess); return Action.ERROR; } + //Suppression du repertoire temporaire delTempDirectory(svnSess); return Action.SUCCESS; + + } + + @Override public void setServletRequest(HttpServletRequest request) { this.request=request;