Skip to content

[minor] Place functions into anonymous namespace #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 47 additions & 45 deletions extension/httpfs/httpfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,53 @@

namespace duckdb {

namespace {
void TimestampToTimeT(timestamp_t timestamp, time_t &result) {
auto components = Timestamp::GetComponents(timestamp);
struct tm tm {};
tm.tm_year = components.year - 1900;
tm.tm_mon = components.month - 1;
tm.tm_mday = components.day;
tm.tm_hour = components.hour;
tm.tm_min = components.minute;
tm.tm_sec = components.second;
tm.tm_isdst = 0;
result = mktime(&tm);
}

optional_idx TryParseContentRange(const HTTPHeaders &headers) {
if (!headers.HasHeader("Content-Range")) {
return optional_idx();
}
string content_range = headers.GetHeaderValue("Content-Range");
auto range_find = content_range.find("/");
if (range_find == std::string::npos || content_range.size() < range_find + 1) {
return optional_idx();
}
string range_length = content_range.substr(range_find + 1);
if (range_length == "*") {
return optional_idx();
}
try {
return std::stoull(range_length);
} catch (...) {
return optional_idx();
}
}

optional_idx TryParseContentLength(const HTTPHeaders &headers) {
if (!headers.HasHeader("Content-Length")) {
return optional_idx();
}
string content_length = headers.GetHeaderValue("Content-Length");
try {
return std::stoull(content_length);
} catch (...) {
return optional_idx();
}
}
} // namespace

shared_ptr<HTTPUtil> HTTPFSUtil::GetHTTPUtil(optional_ptr<FileOpener> opener) {
if (opener) {
return opener->GetHTTPUtil();
Expand Down Expand Up @@ -259,19 +306,6 @@ unique_ptr<HTTPResponse> HTTPFileSystem::GetRangeRequest(FileHandle &handle, str
return response;
}

void TimestampToTimeT(timestamp_t timestamp, time_t &result) {
auto components = Timestamp::GetComponents(timestamp);
struct tm tm {};
tm.tm_year = components.year - 1900;
tm.tm_mon = components.month - 1;
tm.tm_mday = components.day;
tm.tm_hour = components.hour;
tm.tm_min = components.minute;
tm.tm_sec = components.second;
tm.tm_isdst = 0;
result = mktime(&tm);
}

HTTPFileHandle::HTTPFileHandle(FileSystem &fs, const OpenFileInfo &file, FileOpenFlags flags,
unique_ptr<HTTPParams> params_p)
: FileHandle(fs, file.path, flags), params(std::move(params_p)), http_params(params->Cast<HTTPFSParams>()),
Expand Down Expand Up @@ -562,38 +596,6 @@ bool HTTPFileSystem::TryParseLastModifiedTime(const string &timestamp, time_t &r
return true;
}

optional_idx TryParseContentRange(const HTTPHeaders &headers) {
if (!headers.HasHeader("Content-Range")) {
return optional_idx();
}
string content_range = headers.GetHeaderValue("Content-Range");
auto range_find = content_range.find("/");
if (range_find == std::string::npos || content_range.size() < range_find + 1) {
return optional_idx();
}
string range_length = content_range.substr(range_find + 1);
if (range_length == "*") {
return optional_idx();
}
try {
return std::stoull(range_length);
} catch (...) {
return optional_idx();
}
}

optional_idx TryParseContentLength(const HTTPHeaders &headers) {
if (!headers.HasHeader("Content-Length")) {
return optional_idx();
}
string content_length = headers.GetHeaderValue("Content-Length");
try {
return std::stoull(content_length);
} catch (...) {
return optional_idx();
}
}

void HTTPFileHandle::LoadFileInfo() {
if (initialized || force_full_download) {
// already initialized or we specifically do not want to perform a head request and just run a direct download
Expand Down
Loading