conor 2003/02/21 01:42:37
Modified: src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java Log: Change the way FTP tries to create parent directories. It now does this by attempting to change to the dir first and if that fails, then trying to make the dir. This means that file upload should not require non-critical errors to be ignored. PR: 9586 Revision Changes Path 1.32 +36 -8 ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java Index: FTP.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -w -u -r1.31 -r1.32 --- FTP.java 10 Feb 2003 14:14:18 -0000 1.31 +++ FTP.java 21 Feb 2003 09:42:36 -0000 1.32 @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -641,6 +641,9 @@ */ protected void createParents(FTPClient ftp, String filename) throws IOException, BuildException { + + String cwd = ftp.printWorkingDirectory(); + Vector parents = new Vector(); File dir = new File(filename); String dirname; @@ -650,16 +653,43 @@ parents.addElement(dir); } - for (int i = parents.size() - 1; i >= 0; i--) { + // find first non cached dir + int i = parents.size() - 1; + while (i >= 0) { dir = (File) parents.elementAt(i); if (!dirCache.contains(dir)) { - log("creating remote directory " + resolveFile(dir.getPath()), - Project.MSG_VERBOSE); - if(!ftp.makeDirectory(resolveFile(dir.getPath()))) { + break; + } + i--; + } + + if (i >= 0) { + String parent = dir.getParent(); + if (parent != null) { + if (!ftp.changeWorkingDirectory(parent)) { + throw new BuildException("could not change to " + + "directory: " + ftp.getReplyString()); + } + } + + while (i >= 0) { + dir = (File) parents.elementAt(i--); + // check if dir exists by trying to change into it. + if (!ftp.changeWorkingDirectory(dir.getName())) { + // could not change to it - try to create it + log("creating remote directory " + + resolveFile(dir.getPath()), Project.MSG_VERBOSE); + if(!ftp.makeDirectory(dir.getName())) { handleMkDirFailure(ftp); } + if (!ftp.changeWorkingDirectory(dir.getName())) { + throw new BuildException("could not change to " + + "directory: " + ftp.getReplyString()); + } + } dirCache.addElement(dir); } + ftp.changeWorkingDirectory(cwd); } } @@ -1049,9 +1079,7 @@ // directory is the directory to create. if (action == MK_DIR) { - makeRemoteDir(ftp, remotedir); - } else { if (remotedir != null) { log("changing the remote directory", Project.MSG_VERBOSE);