From e074b294911e39877ee9a480e44979f16b9a4882 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Fri, 21 Feb 2003 09:42:36 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274160 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/optional/net/FTP.java | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java index 9564e868c..ad1d73413 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java @@ -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 @@ public class FTP */ 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 @@ public class FTP 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()))) { - handleMkDirFailure(ftp); + 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 @@ public class FTP // 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);