Browse Source

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
master
Conor MacNeill 22 years ago
parent
commit
e074b29491
1 changed files with 36 additions and 8 deletions
  1. +36
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java

+ 36
- 8
src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java View File

@@ -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);


Loading…
Cancel
Save