Skip to content

Commit

Permalink
Merge pull request #58 from rw2/trailing-slash
Browse files Browse the repository at this point in the history
Trailing slash
  • Loading branch information
jhiemstrawisc authored Dec 2, 2024
2 parents 51e3c1a + b6e1ecb commit fe48042
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/S3Commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,10 @@ bool AmazonS3Head::SendRequest() {
// ---------------------------------------------------------------------------

bool AmazonS3List::SendRequest(const std::string &continuationToken) {
query_parameters["list-type"] = "2"; // Version 2 of the object-listing API
query_parameters["list-type"] = "2"; // Version 2 of the object-listing
query_parameters["delimiter"] = "/";
query_parameters["prefix"] = urlquote(object);
query_parameters["encoding-type"] = "url";
if (!continuationToken.empty()) {
query_parameters["continuation-token"] = urlquote(continuationToken);
}
Expand All @@ -564,6 +565,7 @@ bool AmazonS3List::SendRequest(const std::string &continuationToken) {

// Operation is on the bucket itself; alter the URL to remove the object
hostUrl = getProtocol() + "://" + host + bucketPath;
canonicalURI = bucketPath;

return SendS3Request("");
}
Expand Down
6 changes: 5 additions & 1 deletion src/S3Directory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ int S3Directory::Opendir(const char *path, XrdOucEnv &env) {
return -EBADF;
}
Reset();
std::string realPath = path;
if (realPath.back() != '/') {
realPath = realPath + "/";
}

std::string exposedPath, object;
int rv = m_fs.parsePath(path, exposedPath, object);
int rv = m_fs.parsePath(realPath.c_str(), exposedPath, object);
if (rv != 0) {
return rv;
}
Expand Down
12 changes: 9 additions & 3 deletions src/S3FileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <XrdSec/XrdSecEntity.hh>
#include <XrdVersion.hh>

#include <algorithm>
#include <filesystem>
#include <memory>
#include <sstream>
Expand Down Expand Up @@ -202,9 +203,14 @@ XrdOssDF *S3FileSystem::newFile(const char *user) {
int S3FileSystem::Stat(const char *path, struct stat *buff, int opts,
XrdOucEnv *env) {
m_log.Log(XrdHTTPServer::Debug, "Stat", "Stat'ing path", path);
std::string localPath = path;

if (std::count(localPath.begin(), localPath.end(), '/') == 1) {
localPath = localPath + "/";
}

std::string exposedPath, object;
auto rv = parsePath(path, exposedPath, object);
auto rv = parsePath(localPath.c_str(), exposedPath, object);
if (rv != 0) {
return rv;
}
Expand All @@ -226,7 +232,7 @@ int S3FileSystem::Stat(const char *path, struct stat *buff, int opts,
if (httpCode == 0) {
if (m_log.getMsgMask() & XrdHTTPServer::Info) {
std::stringstream ss;
ss << "Failed to stat path " << path
ss << "Failed to stat path " << localPath
<< "; error: " << listCommand.getErrorMessage()
<< " (code=" << listCommand.getErrorCode() << ")";
m_log.Log(XrdHTTPServer::Info, "Stat", ss.str().c_str());
Expand All @@ -235,7 +241,7 @@ int S3FileSystem::Stat(const char *path, struct stat *buff, int opts,
} else {
if (m_log.getMsgMask() & XrdHTTPServer::Info) {
std::stringstream ss;
ss << "Failed to stat path " << path << "; response code "
ss << "Failed to stat path " << localPath << "; response code "
<< httpCode;
m_log.Log(XrdHTTPServer::Info, "Stat", ss.str().c_str());
}
Expand Down
3 changes: 2 additions & 1 deletion test/s3_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ TEST(TestS3URLGeneration, Test1) {
TestAmazonRequest pathReq{serviceUrl, "akf", "skf", b, o, "path", 4};
std::string generatedHostUrl = pathReq.getHostUrl();
ASSERT_EQ(generatedHostUrl,
"https://s3-service.com:443/test-bucket/test-object");
"https://s3-service.com:443/test-bucket/test-object")
<< "generatedURL: " << generatedHostUrl;

// Test virtual-style URL generation
TestAmazonRequest virtReq{serviceUrl, "akf", "skf", b, o, "virtual", 4};
Expand Down

0 comments on commit fe48042

Please sign in to comment.