1 | DirectoryScanner ds;↵ | | 1 | DirectoryScanner ds;↵
|
2 | if (action == SEND_FILES) {↵ | | 2 | if (task.getAction() == FTPTask.SEND_FILES) {↵
|
3 | ds = fs.getDirectoryScanner(getProject());↵ | | 3 | ds = fs.getDirectoryScanner(task.getProject());↵
|
4 | } else {↵ | | 4 | } else {↵
|
5 | ds = new FTPDirectoryScanner(ftp);↵ | | 5 | ds = new FTPDirectoryScanner(ftp);↵
|
6 | fs.setupDirectoryScanner(ds, getProject());↵ | | 6 | fs.setupDirectoryScanner(ds, task.getProject());↵
|
7 | ds.setFollowSymlinks(fs.isFollowSymlinks());↵ | | 7 | ds.setFollowSymlinks(fs.isFollowSymlinks());↵
|
8 | ds.scan();↵ | | 8 | ds.scan();↵
|
9 | }↵ | | 9 | }↵
|
|
10 | String[] dsfiles = null;↵ | | 10 | String[] dsfiles = null;↵
|
11 | if (action == RM_DIR) {↵ | | 11 | if (task.getAction() == FTPTask.RM_DIR) {↵
|
12 | dsfiles = ds.getIncludedDirectories();↵ | | 12 | dsfiles = ds.getIncludedDirectories();↵
|
13 | } else {↵ | | 13 | } else {↵
|
14 | dsfiles = ds.getIncludedFiles();↵ | | 14 | dsfiles = ds.getIncludedFiles();↵
|
15 | }↵ | | 15 | }↵
|
16 | String dir = null;↵ | | 16 | String dir = null;↵
|
|
17 | if ((ds.getBasedir() == null)↵ | | 17 | if ((ds.getBasedir() == null)↵
|
18 | && ((action == SEND_FILES) || (action == GET_FILES))) {↵ | | 18 | && ((task.getAction() == FTPTask.SEND_FILES) || (task.getAction() == FTPTask.GET_FILES))) {↵
|
19 | throw new BuildException("the dir attribute must be set for send "↵ | | 19 | throw new BuildException("the dir attribute must be set for send "↵
|
20 | + "and get actions");↵ | | 20 | + "and get actions");↵
|
21 | } else {↵ | | 21 | } else {↵
|
22 | if ((action == SEND_FILES) || (action == GET_FILES)) {↵ | | 22 | if ((task.getAction() == FTPTask.SEND_FILES) || (task.getAction() == FTPTask.GET_FILES)) {↵
|
23 | dir = ds.getBasedir().getAbsolutePath();↵ | | 23 | dir = ds.getBasedir().getAbsolutePath();↵
|
24 | }↵ | | 24 | }↵
|
25 | }↵ | | 25 | }↵
|
|
26 | // If we are doing a listing, we need the output stream created now.↵ | | 26 | // If we are doing a listing, we need the output stream created now.↵
|
27 | BufferedWriter bw = null;↵ | | 27 | BufferedWriter bw = null;↵
|
|
28 | try {↵ | | 28 | try {↵
|
29 | if (action == LIST_FILES) {↵ | | 29 | if (task.getAction() == FTPTask.LIST_FILES) {↵
|
30 | File pd = listing.getParentFile();↵ | | 30 | File pd = task.getListing().getParentFile();↵
|
|
31 | if (!pd.exists()) {↵ | | 31 | if (!pd.exists()) {↵
|
32 | pd.mkdirs();↵ | | 32 | pd.mkdirs();↵
|
33 | }↵ | | 33 | }↵
|
34 | bw = new BufferedWriter(new FileWriter(listing));↵ | | 34 | bw = new BufferedWriter(new FileWriter(task.getListing()));↵
|
35 | }↵ | | 35 | }↵
|
36 | RetryHandler h = new RetryHandler(this.retriesAllowed, this);↵ | | 36 | RetryHandler h = new RetryHandler(task.getRetriesAllowed(), task);↵
|
37 | if (action == RM_DIR) {↵ | | 37 | if (task.getAction() == FTPTask.RM_DIR) {↵
|
38 | // to remove directories, start by the end of the list↵ | | 38 | // to remove directories, start by the end of the list↵
|
39 | // the trunk does not let itself be removed before the leaves↵ | | 39 | // the trunk does not let itself be removed before the leaves↵
|
40 | for (int i = dsfiles.length - 1; i >= 0; i--) {↵ | | 40 | for (int i = dsfiles.length - 1; i >= 0; i--) {↵
|
41 | final String dsfile = dsfiles[i];↵ | | 41 | final String dsfile = dsfiles[i];↵
|
42 | executeRetryable(h, new Retryable() {↵ | | 42 | executeRetryable(h, new Retryable() {↵
|
43 | public void execute() throws IOException {↵ | | 43 | public void execute() throws IOException {↵
|
44 | rmDir(ftp, dsfile);↵ | | 44 | rmDir(ftp, dsfile);↵
|
45 | }↵ | | 45 | }↵
|
46 | }, dsfile);↵ | | 46 | }, dsfile);↵
|
47 | }↵ | | 47 | }↵
|
48 | } else {↵ | | 48 | } else {↵
|
49 | final BufferedWriter fbw = bw;↵ | | 49 | final BufferedWriter fbw = bw;↵
|
50 | final String fdir = dir;↵ | | 50 | final String fdir = dir;↵
|
51 | if (this.newerOnly) {↵ | | 51 | if (task.isNewer()) {↵
|
52 | this.granularityMillis =↵ | | 52 | task.setGranularityMillis↵
|
53 | this.timestampGranularity↵ | | 53 | (task.getTimestampGranularity()↵
|
54 | .getMilliseconds(action);↵ | | 54 | .getMilliseconds(task.getAction()));↵
|
55 | }↵ | | 55 | }↵
|
56 | for (int i = 0; i < dsfiles.length; i++) {↵ | | 56 | for (int i = 0; i < dsfiles.length; i++) {↵
|
57 | final String dsfile = dsfiles[i];↵ | | 57 | final String dsfile = dsfiles[i];↵
|
58 | executeRetryable(h, new Retryable() {↵ | | 58 | executeRetryable(h, new Retryable() {↵
|
59 | public void execute() throws IOException {↵ | | 59 | public void execute() throws IOException {↵
|
60 | switch (action) {↵ | | 60 | switch (task.getAction()) {↵
|
61 | case SEND_FILES:↵ | | 61 | case FTPTask.SEND_FILES:↵
|
62 | sendFile(ftp, fdir, dsfile);↵ | | 62 | sendFile(ftp, fdir, dsfile);↵
|
63 | break;↵ | | 63 | break;↵
|
64 | case GET_FILES:↵ | | 64 | case FTPTask.GET_FILES:↵
|
65 | getFile(ftp, fdir, dsfile);↵ | | 65 | getFile(ftp, fdir, dsfile);↵
|
66 | break;↵ | | 66 | break;↵
|
67 | case DEL_FILES:↵ | | 67 | case FTPTask.DEL_FILES:↵
|
68 | delFile(ftp, dsfile);↵ | | 68 | delFile(ftp, dsfile);↵
|
69 | break;↵ | | 69 | break;↵
|
70 | case LIST_FILES:↵ | | 70 | case FTPTask.LIST_FILES:↵
|
71 | listFile(ftp, fbw, dsfile);↵ | | 71 | listFile(ftp, fbw, dsfile);↵
|
72 | break;↵ | | 72 | break;↵
|
73 | case CHMOD:↵ | | 73 | case FTPTask.CHMOD:↵
|
74 | doSiteCommand(ftp, "chmod " + chmod↵ | | 74 | doSiteCommand(ftp, "chmod " + task.getChmod() + " "↵
|
75 | + " " + resolveFile(dsfile));↵ | | 75 | + resolveFile(dsfile));↵
|
76 | transferred++;↵ | | 76 | transferred++;↵
|
77 | break;↵ | | 77 | break;↵
|
78 | default:↵ | | 78 | default:↵
|
79 | throw new BuildException("unknown ftp action " + a↵ | | 79 | throw new BuildException("unknown ftp action "↵
|
80 | ction);↵ | | 80 | + task.getAction());↵
|
81 | }↵ | | 81 | }↵
|
82 | }↵ | | 82 | }↵
|
83 | }, dsfile);↵ | | 83 | }, dsfile);↵
|
84 | }↵ | | 84 | }↵
|
85 | }↵ | | 85 | }↵
|
86 | } finally {↵ | | 86 | } finally {↵
|
87 | ↵ | | 87 | if (bw != null) {↵
|
| | | 88 | bw.close();↵
|
| | | 89 | }↵
|
88 | FileUtils.close(bw);↵ | | 90 | //FileUtils.close(bw);↵
|
89 | }↵ | | 91 | }↵
|
|
90 | return dsfiles.length; | | 92 | return dsfiles.length;
|