Revision 59664
Added by Alessia Bardi over 3 years ago
SftpIterator.java | ||
---|---|---|
110 | 110 |
|
111 | 111 |
private void listDirectoryRecursive(final String parentDir, final String currentDir) { |
112 | 112 |
String dirToList = parentDir; |
113 |
if (StringUtils.isNotBlank(currentDir)) {
|
|
114 |
dirToList += "/" + currentDir;
|
|
113 |
if (StringUtils.isNotBlank(currentDir)) {
|
|
114 |
dirToList += "/" + currentDir;
|
|
115 | 115 |
} |
116 |
log.debug("PARENT DIR: " + parentDir);
|
|
117 |
log.debug("DIR TO LIST: " + dirToList);
|
|
118 |
try {
|
|
116 |
log.debug("PARENT DIR: " + parentDir);
|
|
117 |
log.debug("DIR TO LIST: " + dirToList);
|
|
118 |
try {
|
|
119 | 119 |
Vector<ChannelSftp.LsEntry> ls = sftpChannel.ls(dirToList); |
120 | 120 |
for (ChannelSftp.LsEntry entry : ls) { |
121 | 121 |
String currentFileName = entry.getFilename(); |
... | ... | |
123 | 123 |
// skip parent directory and directory itself |
124 | 124 |
continue; |
125 | 125 |
} |
126 |
|
|
127 | 126 |
SftpATTRS attrs = entry.getAttrs(); |
128 | 127 |
if (attrs.isDir()) { |
129 | 128 |
if (isRecursive) { |
... | ... | |
133 | 132 |
// test the file for extensions compliance and, just in case, add it to the list. |
134 | 133 |
for (String ext : extensionsSet) { |
135 | 134 |
if (currentFileName.endsWith(ext)) { |
136 |
//test if the file has been changed after the last collection date: |
|
137 |
if (incremental) { |
|
138 |
int mTime = attrs.getMTime(); |
|
139 |
//int times are values reduced by the milliseconds, hence we multiply per 1000L |
|
140 |
DateTime dt = new DateTime(mTime * 1000L); |
|
141 |
if (dt.isAfter(fromDate)) { |
|
142 |
queue.add(currentFileName); |
|
143 |
log.debug(currentFileName + " has changed and must be re-collected"); |
|
144 |
} else { |
|
145 |
if (log.isDebugEnabled()) { |
|
146 |
log.debug(currentFileName + " has not changed since last collection"); |
|
147 |
} |
|
148 |
} |
|
149 |
} else { |
|
150 |
//if it is not incremental, just add it to the queue |
|
151 |
queue.add(currentFileName); |
|
152 |
} |
|
153 |
|
|
135 |
if(dirToList.length() > 2){ |
|
136 |
currentFileName = dirToList + "/" + currentFileName; |
|
137 |
} |
|
138 |
//test if the file has been changed after the last collection date: |
|
139 |
if (incremental) { |
|
140 |
int mTime = attrs.getMTime(); |
|
141 |
//int times are values reduced by the milliseconds, hence we multiply per 1000L |
|
142 |
DateTime dt = new DateTime(mTime * 1000L); |
|
143 |
if (dt.isAfter(fromDate)) { |
|
144 |
queue.add(currentFileName); |
|
145 |
log.debug(currentFileName + " has changed and must be re-collected"); |
|
146 |
} else { |
|
147 |
if (log.isDebugEnabled()) { |
|
148 |
log.debug(currentFileName + " has not changed since last collection"); |
|
149 |
} |
|
150 |
} |
|
151 |
} else { |
|
152 |
//if it is not incremental, just add it to the queue |
|
153 |
queue.add(currentFileName); |
|
154 |
} |
|
154 | 155 |
} |
155 | 156 |
} |
156 | 157 |
} |
157 | 158 |
} |
158 | 159 |
} catch (SftpException e) { |
159 | 160 |
throw new CollectorServiceRuntimeException("Cannot list the sftp remote directory", e); |
160 |
|
|
161 | 161 |
} |
162 | 162 |
} |
163 | 163 |
|
Also available in: Unified diff
fix issue in recursive impletation. Addition of path from home directory to file in nested folder - from Miriam