Skip to content

Commit

Permalink
VSICurlFilesystemHandlerBase: make GetURLFromFilename() const
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Sep 7, 2024
1 parent 664f825 commit 7a7cb80
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 62 deletions.
18 changes: 9 additions & 9 deletions port/cpl_vsil_adls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ class VSIADLSFSHandler final : public IVSIS3LikeFSHandlerWithMultipartUpload

protected:
VSICurlHandle *CreateFileHandle(const char *pszFilename) override;
std::string GetURLFromFilename(const std::string &osFilename) override;
std::string
GetURLFromFilename(const std::string &osFilename) const override;

char **GetFileList(const char *pszFilename, int nMaxFiles,
bool *pbGotFileList) override;
Expand Down Expand Up @@ -1268,18 +1269,17 @@ void VSIADLSFSHandler::ClearCache()
/* GetURLFromFilename() */
/************************************************************************/

std::string VSIADLSFSHandler::GetURLFromFilename(const std::string &osFilename)
std::string
VSIADLSFSHandler::GetURLFromFilename(const std::string &osFilename) const
{
std::string osFilenameWithoutPrefix =
const std::string osFilenameWithoutPrefix =
osFilename.substr(GetFSPrefix().size());
VSIAzureBlobHandleHelper *poHandleHelper =
auto poHandleHelper = std::unique_ptr<VSIAzureBlobHandleHelper>(
VSIAzureBlobHandleHelper::BuildFromURI(osFilenameWithoutPrefix.c_str(),
GetFSPrefix().c_str());
if (poHandleHelper == nullptr)
GetFSPrefix().c_str()));
if (!poHandleHelper)
return std::string();
std::string osURL(poHandleHelper->GetURLNoKVP());
delete poHandleHelper;
return osURL;
return poHandleHelper->GetURLNoKVP();
}

/************************************************************************/
Expand Down
16 changes: 8 additions & 8 deletions port/cpl_vsil_az.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ class VSIAzureFSHandler final : public IVSIS3LikeFSHandlerWithMultipartUpload

protected:
VSICurlHandle *CreateFileHandle(const char *pszFilename) override;
std::string GetURLFromFilename(const std::string &osFilename) override;
std::string
GetURLFromFilename(const std::string &osFilename) const override;

VSIAzureBlobHandleHelper *CreateAzHandleHelper(const char *pszURI,
bool bAllowNoObject);
Expand Down Expand Up @@ -1423,18 +1424,17 @@ void VSIAzureFSHandler::ClearCache()
/* GetURLFromFilename() */
/************************************************************************/

std::string VSIAzureFSHandler::GetURLFromFilename(const std::string &osFilename)
std::string
VSIAzureFSHandler::GetURLFromFilename(const std::string &osFilename) const
{
std::string osFilenameWithoutPrefix =
osFilename.substr(GetFSPrefix().size());
VSIAzureBlobHandleHelper *poHandleHelper =
auto poHandleHelper = std::unique_ptr<VSIAzureBlobHandleHelper>(
VSIAzureBlobHandleHelper::BuildFromURI(osFilenameWithoutPrefix.c_str(),
GetFSPrefix().c_str());
if (poHandleHelper == nullptr)
GetFSPrefix().c_str()));
if (!poHandleHelper)
return std::string();
std::string osURL(poHandleHelper->GetURLNoKVP());
delete poHandleHelper;
return osURL;
return poHandleHelper->GetURLNoKVP();
}

/************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions port/cpl_vsil_curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4771,8 +4771,8 @@ static bool VSICurlParseFullFTPLine(char *pszLine, char *&pszFilename,
/* GetURLFromFilename() */
/************************************************************************/

std::string
VSICurlFilesystemHandlerBase::GetURLFromFilename(const std::string &osFilename)
std::string VSICurlFilesystemHandlerBase::GetURLFromFilename(
const std::string &osFilename) const
{
return VSICurlGetURLFromFilename(osFilename.c_str(), nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
Expand Down
2 changes: 1 addition & 1 deletion port/cpl_vsil_curl_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class VSICurlFilesystemHandlerBase : public VSIFilesystemHandler
void SetCachedDirList(const char *pszURL, CachedDirList &oCachedDirList);
bool ExistsInCacheDirList(const std::string &osDirname, bool *pbIsDir);

virtual std::string GetURLFromFilename(const std::string &osFilename);
virtual std::string GetURLFromFilename(const std::string &osFilename) const;

std::string
GetStreamingFilename(const std::string &osFilename) const override = 0;
Expand Down
17 changes: 9 additions & 8 deletions port/cpl_vsil_gs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class VSIGSFSHandler final : public IVSIS3LikeFSHandlerWithMultipartUpload
return m_osPrefix;
}

std::string GetURLFromFilename(const std::string &osFilename) override;
std::string
GetURLFromFilename(const std::string &osFilename) const override;

IVSIS3LikeHandleHelper *CreateHandleHelper(const char *pszURI,
bool bAllowNoObject) override;
Expand Down Expand Up @@ -292,17 +293,17 @@ char *VSIGSFSHandler::GetSignedURL(const char *pszFilename,
/* GetURLFromFilename() */
/************************************************************************/

std::string VSIGSFSHandler::GetURLFromFilename(const std::string &osFilename)
std::string
VSIGSFSHandler::GetURLFromFilename(const std::string &osFilename) const
{
std::string osFilenameWithoutPrefix =
const std::string osFilenameWithoutPrefix =
osFilename.substr(GetFSPrefix().size());
VSIGSHandleHelper *poHandleHelper = VSIGSHandleHelper::BuildFromURI(
osFilenameWithoutPrefix.c_str(), GetFSPrefix().c_str());
auto poHandleHelper =
std::unique_ptr<VSIGSHandleHelper>(VSIGSHandleHelper::BuildFromURI(
osFilenameWithoutPrefix.c_str(), GetFSPrefix().c_str()));
if (poHandleHelper == nullptr)
return std::string();
std::string osURL(poHandleHelper->GetURL());
delete poHandleHelper;
return osURL;
return poHandleHelper->GetURL();
}

/************************************************************************/
Expand Down
23 changes: 12 additions & 11 deletions port/cpl_vsil_oss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class VSIOSSFSHandler final : public IVSIS3LikeFSHandlerWithMultipartUpload

protected:
VSICurlHandle *CreateFileHandle(const char *pszFilename) override;
std::string GetURLFromFilename(const std::string &osFilename) override;
std::string
GetURLFromFilename(const std::string &osFilename) const override;

const char *GetDebugKey() const override
{
Expand Down Expand Up @@ -235,26 +236,26 @@ VSICurlHandle *VSIOSSFSHandler::CreateFileHandle(const char *pszFilename)
}

/************************************************************************/
/* GetURLFromFilename() */
/* GetURLFromFilename() */
/************************************************************************/

std::string VSIOSSFSHandler::GetURLFromFilename(const std::string &osFilename)
std::string
VSIOSSFSHandler::GetURLFromFilename(const std::string &osFilename) const
{
std::string osFilenameWithoutPrefix =
const std::string osFilenameWithoutPrefix =
osFilename.substr(GetFSPrefix().size());

VSIOSSHandleHelper *poHandleHelper = VSIOSSHandleHelper::BuildFromURI(
osFilenameWithoutPrefix.c_str(), GetFSPrefix().c_str(), true);
if (poHandleHelper == nullptr)
auto poHandleHelper =
std::unique_ptr<VSIOSSHandleHelper>(VSIOSSHandleHelper::BuildFromURI(
osFilenameWithoutPrefix.c_str(), GetFSPrefix().c_str(), true));
if (!poHandleHelper)
{
return "";
return std::string();
}

std::string osBaseURL(poHandleHelper->GetURL());
if (!osBaseURL.empty() && osBaseURL.back() == '/')
osBaseURL.resize(osBaseURL.size() - 1);
delete poHandleHelper;

osBaseURL.pop_back();
return osBaseURL;
}

Expand Down
21 changes: 11 additions & 10 deletions port/cpl_vsil_s3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ class VSIS3FSHandler final : public IVSIS3LikeFSHandlerWithMultipartUpload

protected:
VSICurlHandle *CreateFileHandle(const char *pszFilename) override;
std::string GetURLFromFilename(const std::string &osFilename) override;
std::string
GetURLFromFilename(const std::string &osFilename) const override;

const char *GetDebugKey() const override
{
Expand Down Expand Up @@ -2825,22 +2826,22 @@ VSICurlHandle *VSIS3FSHandler::CreateFileHandle(const char *pszFilename)
/* GetURLFromFilename() */
/************************************************************************/

std::string VSIS3FSHandler::GetURLFromFilename(const std::string &osFilename)
std::string
VSIS3FSHandler::GetURLFromFilename(const std::string &osFilename) const
{
std::string osFilenameWithoutPrefix =
const std::string osFilenameWithoutPrefix =
osFilename.substr(GetFSPrefix().size());

VSIS3HandleHelper *poS3HandleHelper = VSIS3HandleHelper::BuildFromURI(
osFilenameWithoutPrefix.c_str(), GetFSPrefix().c_str(), true);
if (poS3HandleHelper == nullptr)
auto poS3HandleHelper =
std::unique_ptr<VSIS3HandleHelper>(VSIS3HandleHelper::BuildFromURI(
osFilenameWithoutPrefix.c_str(), GetFSPrefix().c_str(), true));
if (!poS3HandleHelper)
{
return "";
return std::string();
}
std::string osBaseURL(poS3HandleHelper->GetURL());
if (!osBaseURL.empty() && osBaseURL.back() == '/')
osBaseURL.resize(osBaseURL.size() - 1);
delete poS3HandleHelper;

osBaseURL.pop_back();
return osBaseURL;
}

Expand Down
21 changes: 11 additions & 10 deletions port/cpl_vsil_swift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ class VSISwiftFSHandler final : public IVSIS3LikeFSHandler

protected:
VSICurlHandle *CreateFileHandle(const char *pszFilename) override;
std::string GetURLFromFilename(const std::string &osFilename) override;
std::string
GetURLFromFilename(const std::string &osFilename) const override;

const char *GetDebugKey() const override
{
Expand Down Expand Up @@ -385,22 +386,22 @@ VSICurlHandle *VSISwiftFSHandler::CreateFileHandle(const char *pszFilename)
/* GetURLFromFilename() */
/************************************************************************/

std::string VSISwiftFSHandler::GetURLFromFilename(const std::string &osFilename)
std::string
VSISwiftFSHandler::GetURLFromFilename(const std::string &osFilename) const
{
std::string osFilenameWithoutPrefix =
const std::string osFilenameWithoutPrefix =
osFilename.substr(GetFSPrefix().size());

VSISwiftHandleHelper *poHandleHelper = VSISwiftHandleHelper::BuildFromURI(
osFilenameWithoutPrefix.c_str(), GetFSPrefix().c_str());
if (poHandleHelper == nullptr)
auto poHandleHelper = std::unique_ptr<VSISwiftHandleHelper>(
VSISwiftHandleHelper::BuildFromURI(osFilenameWithoutPrefix.c_str(),
GetFSPrefix().c_str()));
if (!poHandleHelper)
{
return "";
return std::string();
}
std::string osBaseURL(poHandleHelper->GetURL());
if (!osBaseURL.empty() && osBaseURL.back() == '/')
osBaseURL.resize(osBaseURL.size() - 1);
delete poHandleHelper;

osBaseURL.pop_back();
return osBaseURL;
}

Expand Down
7 changes: 4 additions & 3 deletions port/cpl_vsil_webhdfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class VSIWebHDFSFSHandler final : public VSICurlFilesystemHandlerBaseWritable
char **GetFileList(const char *pszFilename, int nMaxFiles,
bool *pbGotFileList) override;

std::string GetURLFromFilename(const std::string &osFilename) override;
std::string
GetURLFromFilename(const std::string &osFilename) const override;

VSIVirtualHandleUniquePtr
CreateWriteHandle(const char *pszFilename,
Expand Down Expand Up @@ -564,11 +565,11 @@ VSICurlHandle *VSIWebHDFSFSHandler::CreateFileHandle(const char *pszFilename)
}

/************************************************************************/
/* GetURLFromFilename() */
/* GetURLFromFilename() */
/************************************************************************/

std::string
VSIWebHDFSFSHandler::GetURLFromFilename(const std::string &osFilename)
VSIWebHDFSFSHandler::GetURLFromFilename(const std::string &osFilename) const
{
return osFilename.substr(GetFSPrefix().size());
}
Expand Down

0 comments on commit 7a7cb80

Please sign in to comment.