XRootD
XrdClS3::Filesystem Class Referencefinal

#include <XrdClS3Filesystem.hh>

+ Inheritance diagram for XrdClS3::Filesystem:
+ Collaboration diagram for XrdClS3::Filesystem:

Public Member Functions

 Filesystem (const std::string &, XrdCl::Log *log)
 
virtual ~Filesystem () noexcept
 
virtual XrdCl::XRootDStatus DirList (const std::string &path, XrdCl::DirListFlags::Flags flags, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual bool GetProperty (const std::string &name, std::string &value) const override
 
virtual XrdCl::XRootDStatus Locate (const std::string &path, XrdCl::OpenFlags::Flags flags, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual XrdCl::XRootDStatus MkDir (const std::string &path, XrdCl::MkDirFlags::Flags flags, XrdCl::Access::Mode mode, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual XrdCl::XRootDStatus Query (XrdCl::QueryCode::Code queryCode, const XrdCl::Buffer &arg, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual XrdCl::XRootDStatus Rm (const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual XrdCl::XRootDStatus RmDir (const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
 
virtual bool SetProperty (const std::string &name, const std::string &value) override
 
virtual XrdCl::XRootDStatus Stat (const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override
 
- Public Member Functions inherited from XrdCl::FileSystemPlugIn
virtual ~FileSystemPlugIn ()
 Destructor. More...
 
virtual XRootDStatus ChMod (const std::string &path, Access::Mode mode, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus DeepLocate (const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus DelXAttr (const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus GetXAttr (const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus ListXAttr (const std::string &path, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Mv (const std::string &source, const std::string &dest, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Ping (ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Prepare (const std::vector< std::string > &fileList, PrepareFlags::Flags flags, uint8_t priority, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Protocol (ResponseHandler *handler, time_t timeout=0)
 
virtual XRootDStatus SendInfo (const std::string &info, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus SetXAttr (const std::string &path, const std::vector< xattr_t > &attrs, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus StatVFS (const std::string &path, ResponseHandler *handler, time_t timeout)
 
virtual XRootDStatus Truncate (const std::string &path, uint64_t size, ResponseHandler *handler, time_t timeout)
 

Detailed Description

Definition at line 41 of file XrdClS3Filesystem.hh.

Constructor & Destructor Documentation

◆ Filesystem()

Filesystem::Filesystem ( const std::string &  url,
XrdCl::Log log 
)

Definition at line 455 of file XrdClS3Filesystem.cc.

455  :
456  m_logger(log),
457  m_url(url)
458 {
459  m_url.SetPath("");
461  m_url.SetParams(map);
462 
463  m_logger->Debug(kLogXrdClS3, "S3 filesystem constructed with URL: %s.",
464  m_url.GetURL().c_str());
465 }
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
void SetParams(const std::string &params)
Set params.
Definition: XrdClURL.cc:402
std::string GetURL() const
Get the URL.
Definition: XrdClURL.hh:86
void SetPath(const std::string &path)
Set the path.
Definition: XrdClURL.hh:225
const uint64_t kLogXrdClS3

References XrdCl::Log::Debug(), XrdCl::URL::GetURL(), XrdClS3::kLogXrdClS3, XrdCl::URL::SetParams(), and XrdCl::URL::SetPath().

+ Here is the call graph for this function:

◆ ~Filesystem()

Filesystem::~Filesystem ( )
virtualnoexcept

Definition at line 467 of file XrdClS3Filesystem.cc.

467 {}

Member Function Documentation

◆ DirList()

XrdCl::XRootDStatus Filesystem::DirList ( const std::string &  path,
XrdCl::DirListFlags::Flags  flags,
XrdCl::ResponseHandler handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::DirlList

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 470 of file XrdClS3Filesystem.cc.

474 {
475  std::string https_url, err_msg;
476  const auto s3_url = JoinUrl(m_url.GetURL(), path);
477  std::string obj;
478  if (!Factory::GenerateHttpUrl(s3_url, https_url, &obj, err_msg)) {
480  }
481  obj = obj.substr(0, obj.find('?'));
482  auto query_loc = https_url.find('?');
483  https_url += (query_loc == std::string::npos) ? "?" : "&";
484  https_url += "list-type=2&delimiter=/&encoding-type=url";
485  https_url += "&prefix=" + urlquote(obj) + "/";
486 
487  auto expiry = time(NULL) + timeout;
488 
489  return DownloadUrl(
490  https_url,
491  &m_header_callout,
492  new DirListResponseHandler(
493  false, https_url, &m_header_callout, handler, expiry, *m_logger
494  ),
495  timeout
496  );
497 }
static bool GenerateHttpUrl(const std::string &s3_url, std::string &https_url, std::string *obj_result, std::string &err_msg)
XrdCl::XRootDStatus DownloadUrl(const std::string &url, XrdClHttp::HeaderCallout *header_callout, XrdCl::ResponseHandler *handler, time_t timeout)
const uint16_t errInvalidAddr
Definition: XrdClStatus.hh:71
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32

References XrdClS3::DownloadUrl(), XrdCl::errInvalidAddr, XrdClS3::Factory::GenerateHttpUrl(), XrdCl::URL::GetURL(), and XrdCl::stError.

+ Here is the call graph for this function:

◆ GetProperty()

bool Filesystem::GetProperty ( const std::string &  name,
std::string &  value 
) const
overridevirtual
See also
XrdCl::FileSystem::GetProperty

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 540 of file XrdClS3Filesystem.cc.

542 {
543  std::unique_lock lock(m_properties_mutex);
544  const auto p = m_properties.find(name);
545  if (p == std::end(m_properties)) {
546  return false;
547  }
548 
549  value = p->second;
550  return true;
551 }

◆ Locate()

XrdCl::XRootDStatus Filesystem::Locate ( const std::string &  path,
XrdCl::OpenFlags::Flags  flags,
XrdCl::ResponseHandler handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Locate

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 554 of file XrdClS3Filesystem.cc.

558 {
559  auto cleaned_path = Factory::CleanObjectName(path);
560  auto [st, fs] = GetFSHandle(cleaned_path);
561  if (!st.IsOK()) {
562  return st;
563  }
564  return fs->Locate(cleaned_path, flags, handler, timeout);
565 }
static std::string CleanObjectName(const std::string &object)

References XrdClS3::Factory::CleanObjectName().

+ Here is the call graph for this function:

◆ MkDir()

XrdCl::XRootDStatus Filesystem::MkDir ( const std::string &  path,
XrdCl::MkDirFlags::Flags  flags,
XrdCl::Access::Mode  mode,
XrdCl::ResponseHandler handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::MkDir

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 568 of file XrdClS3Filesystem.cc.

573 {
574  auto sentinel = Factory::GetMkdirSentinel();
575  if (sentinel.empty()) {
576  if (handler) handler->HandleResponse(new XrdCl::XRootDStatus{}, nullptr);
577  return {};
578  }
579  auto loc = input_path.find('?');
580  auto path = input_path.substr(0, loc);
581  if (!path.empty() && path[path.size() - 1] != '/') path += "/";
582  path += sentinel;
583  if (loc != std::string::npos) {
584  path += input_path.substr(loc);
585  }
586 
587  // Try creating a zero-sized sentinel.
588  std::string https_url, err_msg;
589  const auto s3_url = JoinUrl(m_url.GetURL(), path);
590  if (!Factory::GenerateHttpUrl(s3_url, https_url, nullptr, err_msg)) {
592  }
593 
594  XrdCl::File *http_file(new XrdCl::File(https_url));
595 
596  auto callout_loc = reinterpret_cast<long long>(&m_header_callout);
597  size_t buf_size = 16;
598  char callout_buf[buf_size];
599  std::to_chars_result result = std::to_chars(callout_buf, callout_buf + buf_size - 1, callout_loc, 16);
600  if (result.ec == std::errc{}) {
601  std::string callout_str(callout_buf, result.ptr - callout_buf);
602  http_file->SetProperty("XrdClHttpHeaderCallout", callout_str);
603  }
604 
605  MkdirHandler *mkdirHandler = new MkdirHandler(http_file, handler, timeout);
606 
607  return http_file->Open(https_url, XrdCl::OpenFlags::Write, XrdCl::Access::None, mkdirHandler, timeout);
608 }
static const std::string & GetMkdirSentinel()
A file.
Definition: XrdClFile.hh:52
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
@ Write
Open only for writing.

References XrdCl::errInvalidAddr, XrdClS3::Factory::GenerateHttpUrl(), XrdClS3::Factory::GetMkdirSentinel(), XrdCl::URL::GetURL(), XrdCl::ResponseHandler::HandleResponse(), XrdCl::Access::None, XrdCl::File::Open(), XrdCl::File::SetProperty(), XrdCl::stError, and XrdCl::OpenFlags::Write.

+ Here is the call graph for this function:

◆ Query()

XrdCl::XRootDStatus Filesystem::Query ( XrdCl::QueryCode::Code  queryCode,
const XrdCl::Buffer arg,
XrdCl::ResponseHandler handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Query

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 611 of file XrdClS3Filesystem.cc.

615 {
616  if (queryCode != XrdCl::QueryCode::Checksum && queryCode != XrdCl::QueryCode::XAttr) {
618  }
619  auto cleaned_path = Factory::CleanObjectName(arg.ToString());
620  auto [st, fs] = GetFSHandle(cleaned_path);
621  if (!st.IsOK()) {
622  return st;
623  }
624  XrdCl::Buffer cleanedArg;
625  cleanedArg.FromString(cleaned_path);
626  return fs->Query(queryCode, cleanedArg, handler, timeout);
627 }
Binary blob representation.
Definition: XrdClBuffer.hh:34
void FromString(const std::string str)
Fill the buffer from a string.
Definition: XrdClBuffer.hh:205
std::string ToString() const
Convert the buffer to a string.
Definition: XrdClBuffer.hh:215
const uint16_t errNotImplemented
Operation is not implemented.
Definition: XrdClStatus.hh:64
@ XAttr
Query file extended attributes.
@ Checksum
Query file checksum.

References XrdCl::QueryCode::Checksum, XrdClS3::Factory::CleanObjectName(), XrdCl::errNotImplemented, XrdCl::Buffer::FromString(), XrdCl::stError, XrdCl::Buffer::ToString(), and XrdCl::QueryCode::XAttr.

+ Here is the call graph for this function:

◆ Rm()

XrdCl::XRootDStatus Filesystem::Rm ( const std::string &  path,
XrdCl::ResponseHandler handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Rm

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 631 of file XrdClS3Filesystem.cc.

634 {
635  auto cleaned_path = Factory::CleanObjectName(path);
636  auto [st, fs] = GetFSHandle(cleaned_path);
637  if (!st.IsOK()) {
638  return st;
639  }
640  return fs->Rm(cleaned_path, handler, timeout);
641 }

References XrdClS3::Factory::CleanObjectName().

Referenced by RmDir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RmDir()

XrdCl::XRootDStatus Filesystem::RmDir ( const std::string &  path,
XrdCl::ResponseHandler handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::RmDir

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 644 of file XrdClS3Filesystem.cc.

647 {
648  auto sentinel = Factory::GetMkdirSentinel();
649  if (sentinel.empty()) {
650  if (handler) handler->HandleResponse(new XrdCl::XRootDStatus{}, nullptr);
651  return {};
652  }
653  auto loc = input_path.find('?');
654  auto path = input_path.substr(0, loc);
655  if (!path.empty() && path[path.size() - 1] != '/') path += "/";
656  path += sentinel;
657  if (loc != std::string::npos) {
658  path += input_path.substr(loc);
659  }
660  return Rm(path, handler, timeout);
661 }
virtual XrdCl::XRootDStatus Rm(const std::string &path, XrdCl::ResponseHandler *handler, time_t timeout) override

References XrdClS3::Factory::GetMkdirSentinel(), XrdCl::ResponseHandler::HandleResponse(), and Rm().

+ Here is the call graph for this function:

◆ SetProperty()

bool Filesystem::SetProperty ( const std::string &  name,
const std::string &  value 
)
overridevirtual
See also
XrdCl::FileSystem::SetProperty

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 665 of file XrdClS3Filesystem.cc.

667 {
668  std::unique_lock lock(m_properties_mutex);
669  m_properties[name] = value;
670  return true;
671 }

◆ Stat()

XrdCl::XRootDStatus Filesystem::Stat ( const std::string &  path,
XrdCl::ResponseHandler handler,
time_t  timeout 
)
overridevirtual
See also
XrdCl::FileSystem::Stat

Reimplemented from XrdCl::FileSystemPlugIn.

Definition at line 674 of file XrdClS3Filesystem.cc.

677 {
678  auto cleaned_path = Factory::CleanObjectName(path);
679  auto [st, fs] = GetFSHandle(cleaned_path);
680  if (!st.IsOK()) {
681  return st;
682  }
683  return fs->Stat(cleaned_path, new StatHandler(cleaned_path, m_url.GetURL(), &m_header_callout, handler, timeout, *m_logger), timeout);
684 }

References XrdClS3::Factory::CleanObjectName(), and XrdCl::URL::GetURL().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: