Skip to content

Trailing slash #58

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

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
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
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
Loading