Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the existence check of a task directory #24

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/main/java/saps/common/core/storage/swift/SwiftAPIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class SwiftAPIClient {

private static final Logger LOGGER = Logger.getLogger(SwiftAPIClient.class);
private static final String CONTAINER_URL_PATTERN = "%s/%s?path=%s";
private static final String TASK_URL_PATTERN = "%s/%s?path=%s/%s";

private final String swiftUrl;

Expand Down Expand Up @@ -168,18 +169,20 @@ public List<String> listFiles(String containerName, String dirPath) throws IOExc
}

public boolean existsTask(String containerName, String basePath, String taskId)
throws IOException {
List<String> files = this.listFiles(containerName, basePath);
for (String filePath : files) {
try {
if (Paths.get(filePath).getFileName().toString().equals(taskId)) {
return true;
}
} catch (NullPointerException np) {
LOGGER.error("Error while checking if task exists", np);
return false;
}
}
return false;
throws IOException {
String url = String.format(TASK_URL_PATTERN, swiftUrl, containerName, basePath, taskId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need the listFiles implementation? could we removed it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still used in other methods.

HttpClient client = HttpClients.createDefault();
HttpGet httpget = new HttpGet(url);
httpget.addHeader("X-Auth-Token", token.getAccessId());
HttpResponse response = client.execute(httpget);

if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return true;
}
else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
return false;
} else {
throw new IOException("Error while checking if task exists: " + response.getStatusLine().getStatusCode());
}
}
}