Skip to content

Commit 39b533b

Browse files
authored
Merge pull request OSGeo#12802 from rouault/s3_listdir_path_specific_option
/vsis3/: retrieve path specific options in ReadDir()
2 parents c085222 + 4bd8d57 commit 39b533b

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

autotest/gcore/vsis3.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,9 +1244,16 @@ def method(request):
12441244
</Contents>
12451245
</ListBucketResult>
12461246
""",
1247+
expected_headers={"foo": "bar"},
1248+
)
1249+
gdal.SetPathSpecificOption(
1250+
"/vsis3/s3_fake_bucket2/a_dir",
1251+
"GDAL_HTTP_HEADERS",
1252+
"foo:bar",
12471253
)
12481254
with webserver.install_http_handler(handler):
12491255
dir_contents = gdal.ReadDir("/vsis3/s3_fake_bucket2/a_dir")
1256+
gdal.ClearPathSpecificOptions()
12501257
assert dir_contents == ["test.txt"]
12511258

12521259
# Test CPL_VSIL_CURL_IGNORE_GLACIER_STORAGE=NO

port/cpl_vsil_az.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ const char GDAL_MARKER_FOR_DIR[] = ".gdal_marker_for_dir";
6161

6262
struct VSIDIRAz : public VSIDIRS3Like
6363
{
64-
explicit VSIDIRAz(IVSIS3LikeFSHandler *poFSIn) : VSIDIRS3Like(poFSIn)
64+
VSIDIRAz(const std::string &osDirName, IVSIS3LikeFSHandler *poFSIn)
65+
: VSIDIRS3Like(osDirName, poFSIn)
6566
{
6667
}
6768

@@ -2479,7 +2480,7 @@ VSIDIR *VSIAzureFSHandler::OpenDir(const char *pszPath, int nRecurseDepth,
24792480
return nullptr;
24802481
}
24812482

2482-
VSIDIRAz *dir = new VSIDIRAz(this);
2483+
VSIDIRAz *dir = new VSIDIRAz(pszPath, this);
24832484
dir->nRecurseDepth = nRecurseDepth;
24842485
dir->poHandleHelper = std::move(poHandleHelper);
24852486
dir->osBucket = std::move(osBucket);

port/cpl_vsil_curl_class.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,8 @@ struct VSIDIRWithMissingDirSynthesis : public VSIDIR
10261026

10271027
struct VSIDIRS3Like : public VSIDIRWithMissingDirSynthesis
10281028
{
1029+
const std::string m_osDirName;
1030+
10291031
int nRecurseDepth = 0;
10301032

10311033
std::string osNextMarker{};
@@ -1045,12 +1047,14 @@ struct VSIDIRS3Like : public VSIDIRWithMissingDirSynthesis
10451047
std::unique_ptr<VSIDIR, decltype(&VSICloseDir)> m_subdir{nullptr,
10461048
VSICloseDir};
10471049

1048-
explicit VSIDIRS3Like(IVSIS3LikeFSHandler *poFSIn)
1049-
: poFS(poFSIn), poS3FS(poFSIn)
1050+
VSIDIRS3Like(const std::string &osDirName, IVSIS3LikeFSHandler *poFSIn)
1051+
: m_osDirName(osDirName), poFS(poFSIn), poS3FS(poFSIn)
10501052
{
10511053
}
10521054

1053-
explicit VSIDIRS3Like(VSICurlFilesystemHandlerBase *poFSIn) : poFS(poFSIn)
1055+
VSIDIRS3Like(const std::string &osDirName,
1056+
VSICurlFilesystemHandlerBase *poFSIn)
1057+
: m_osDirName(osDirName), poFS(poFSIn)
10541058
{
10551059
}
10561060

port/cpl_vsil_s3.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ struct VSIDIRS3 : public VSIDIRS3Like
7373
bool m_bDirectoryBucketListingDone = false;
7474
bool m_bListBucket = false;
7575

76-
explicit VSIDIRS3(IVSIS3LikeFSHandler *poFSIn) : VSIDIRS3Like(poFSIn)
76+
VSIDIRS3(const std::string &osDirName, IVSIS3LikeFSHandler *poFSIn)
77+
: VSIDIRS3Like(osDirName, poFSIn)
7778
{
7879
}
7980

80-
explicit VSIDIRS3(VSICurlFilesystemHandlerBase *poFSIn)
81-
: VSIDIRS3Like(poFSIn)
81+
VSIDIRS3(const std::string &osDirName, VSICurlFilesystemHandlerBase *poFSIn)
82+
: VSIDIRS3Like(osDirName, poFSIn)
8283
{
8384
}
8485

@@ -515,6 +516,9 @@ bool VSIDIRS3::IssueListDir()
515516
l_poHandlerHelper = poTmpHandleHelper.get();
516517
}
517518

519+
const CPLStringList aosHTTPOptions(
520+
CPLHTTPGetOptionsFromEnv(m_osDirName.c_str()));
521+
518522
while (true)
519523
{
520524
l_poHandlerHelper->ResetQueryParameters();
@@ -541,8 +545,9 @@ bool VSIDIRS3::IssueListDir()
541545
m_osFilterPrefix);
542546
}
543547

544-
struct curl_slist *headers = VSICurlSetOptions(
545-
hCurlHandle, l_poHandlerHelper->GetURL().c_str(), nullptr);
548+
struct curl_slist *headers =
549+
VSICurlSetOptions(hCurlHandle, poHandleHelper->GetURL().c_str(),
550+
aosHTTPOptions.List());
546551

547552
headers = l_poHandlerHelper->GetCurlHeaders("GET", headers);
548553
// Disable automatic redirection
@@ -703,7 +708,7 @@ bool VSICurlFilesystemHandlerBase::AnalyseS3FileList(
703708
int nMaxFiles, const std::set<std::string> &oSetIgnoredStorageClasses,
704709
bool &bIsTruncated)
705710
{
706-
VSIDIRS3 oDir(this);
711+
VSIDIRS3 oDir(std::string(), this);
707712
oDir.nMaxFiles = nMaxFiles;
708713
bool ret = oDir.AnalyseS3FileList(osBaseURL, pszXML,
709714
oSetIgnoredStorageClasses, bIsTruncated);
@@ -3403,7 +3408,7 @@ VSIDIR *IVSIS3LikeFSHandler::OpenDir(const char *pszPath, int nRecurseDepth,
34033408
return nullptr;
34043409
}
34053410

3406-
VSIDIRS3 *dir = new VSIDIRS3(this);
3411+
VSIDIRS3 *dir = new VSIDIRS3(pszPath, this);
34073412
dir->nRecurseDepth = nRecurseDepth;
34083413
dir->poHandleHelper = std::move(poS3HandleHelper);
34093414
dir->osBucket = std::move(osBucket);

0 commit comments

Comments
 (0)