XRootD
Loading...
Searching...
No Matches
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.
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}
std::map< std::string, std::string > ParamsMap
Definition XrdClURL.hh:33
const uint64_t kLogXrdClS3

References XrdClS3::kLogXrdClS3.

◆ ~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)) {
479 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidAddr, 0, 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
const uint16_t stError
An error occurred that could potentially be retried.

References XrdClS3::DownloadUrl(), XrdCl::errInvalidAddr, XrdClS3::Factory::GenerateHttpUrl(), 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)) {
591 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errInvalidAddr, 0, err_msg);
592 }
593
594 XrdCl::File *http_file(new XrdCl::File());
595 auto status = http_file->Open(https_url, XrdCl::OpenFlags::Compress, XrdCl::Access::None, nullptr, time_t(0));
596 if (!status.IsOK()) {
597 delete http_file;
598 return status;
599 }
600
601 auto callout_loc = reinterpret_cast<long long>(&m_header_callout);
602 size_t buf_size = 16;
603 char callout_buf[buf_size];
604 std::to_chars_result result = std::to_chars(callout_buf, callout_buf + buf_size - 1, callout_loc, 16);
605 if (result.ec == std::errc{}) {
606 std::string callout_str(callout_buf, result.ptr - callout_buf);
607 http_file->SetProperty("XrdClHttpHeaderCallout", callout_str);
608 }
609
610 MkdirHandler *mkdirHandler = new MkdirHandler(http_file, handler, timeout);
611
612 return http_file->Open(https_url, XrdCl::OpenFlags::Write, XrdCl::Access::None, mkdirHandler, timeout);
613}
static const std::string & GetMkdirSentinel()
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
@ Write
Open only for writing.

References XrdCl::OpenFlags::Compress, XrdCl::errInvalidAddr, XrdClS3::Factory::GenerateHttpUrl(), XrdClS3::Factory::GetMkdirSentinel(), XrdCl::ResponseHandler::HandleResponse(), XrdCl::Status::IsOK(), 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 616 of file XrdClS3Filesystem.cc.

620{
621 if (queryCode != XrdCl::QueryCode::Checksum && queryCode != XrdCl::QueryCode::XAttr) {
622 return XrdCl::XRootDStatus(XrdCl::stError, XrdCl::errNotImplemented);
623 }
624 auto cleaned_path = Factory::CleanObjectName(arg.ToString());
625 auto [st, fs] = GetFSHandle(cleaned_path);
626 if (!st.IsOK()) {
627 return st;
628 }
629 XrdCl::Buffer cleanedArg;
630 cleanedArg.FromString(cleaned_path);
631 return fs->Query(queryCode, cleanedArg, handler, timeout);
632}
void FromString(const std::string str)
Fill the buffer from a string.
std::string ToString() const
Convert the buffer to a string.
const uint16_t errNotImplemented
Operation is not implemented.
@ 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 636 of file XrdClS3Filesystem.cc.

639{
640 auto cleaned_path = Factory::CleanObjectName(path);
641 auto [st, fs] = GetFSHandle(cleaned_path);
642 if (!st.IsOK()) {
643 return st;
644 }
645 return fs->Rm(cleaned_path, handler, timeout);
646}

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 649 of file XrdClS3Filesystem.cc.

652{
653 auto sentinel = Factory::GetMkdirSentinel();
654 if (sentinel.empty()) {
655 if (handler) handler->HandleResponse(new XrdCl::XRootDStatus{}, nullptr);
656 return {};
657 }
658 auto loc = input_path.find('?');
659 auto path = input_path.substr(0, loc);
660 if (!path.empty() && path[path.size() - 1] != '/') path += "/";
661 path += sentinel;
662 if (loc != std::string::npos) {
663 path += input_path.substr(loc);
664 }
665 return Rm(path, handler, timeout);
666}
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 670 of file XrdClS3Filesystem.cc.

672{
673 std::unique_lock lock(m_properties_mutex);
674 m_properties[name] = value;
675 return true;
676}

◆ 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 679 of file XrdClS3Filesystem.cc.

682{
683 auto cleaned_path = Factory::CleanObjectName(path);
684 auto [st, fs] = GetFSHandle(cleaned_path);
685 if (!st.IsOK()) {
686 return st;
687 }
688 return fs->Stat(cleaned_path, new StatHandler(cleaned_path, m_url.GetURL(), &m_header_callout, handler, timeout, *m_logger), timeout);
689}

References XrdClS3::Factory::CleanObjectName().

Here is the call graph for this function:

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