Skip to content

Commit

Permalink
Added code to "open" so that a 404 could be returned if the file didn…
Browse files Browse the repository at this point in the history
…'t exist.
  • Loading branch information
rw2 committed Apr 18, 2024
1 parent 4fc2839 commit 6e7066e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/S3File.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ int S3File::Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env) {
std::string configured_s3_secret_key =
m_oss->getS3SecretKeyFile(exposedPath);
std::string configured_s3_bucket_name = m_oss->getS3BucketName(exposedPath);
std::string configured_s3_url_style = m_oss->getS3URLStyle();

// We used to query S3 here to see if the object existed, but of course
// if you're creating a file on upload, you don't care.
Expand All @@ -114,18 +115,22 @@ int S3File::Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env) {
this->s3_service_url = configured_s3_service_url;
this->s3_access_key = configured_s3_access_key;
this->s3_secret_key = configured_s3_secret_key;
std::string configured_s3_url_style = m_oss->getS3URLStyle();
this->s3_url_style = configured_s3_url_style;

// We used to query S3 here to see if the object existed, but of course
// if you're creating a file on upload, you don't care.
//This flag is not set when it's going to be a read operation
//so we check if the file exists in order to be able to return a 404
if (!Oflag) {
AmazonS3Download download(this->s3_service_url, this->s3_access_key,
this->s3_secret_key, this->s3_bucket_name,
this->s3_object_name, this->s3_url_style, m_log);

this->s3_object_name = object;
this->s3_bucket_name = configured_s3_bucket_name;
this->s3_service_url = configured_s3_service_url;
this->s3_access_key = configured_s3_access_key;
this->s3_secret_key = configured_s3_secret_key;
this->s3_url_style = configured_s3_url_style;
return 0;
if (!download.SendRequest(0, 10)) {
return -ENOENT;
}

}

return 0;
}

ssize_t S3File::Read(void *buffer, off_t offset, size_t size) {
Expand Down
2 changes: 2 additions & 0 deletions src/S3File.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <memory>

#include <fcntl.h>

int parse_path(const S3FileSystem &fs, const char *path,
std::string &exposedPath, std::string &object);

Expand Down

0 comments on commit 6e7066e

Please sign in to comment.