aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform')
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Environment.cpp23
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/FileSystem.cpp292
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/OSVersionInfo.cpp59
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Security.cpp26
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Time.cpp31
5 files changed, 431 insertions, 0 deletions
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Environment.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Environment.cpp
new file mode 100644
index 0000000000..ee627340bb
--- /dev/null
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Environment.cpp
@@ -0,0 +1,23 @@
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+
+#include <aws/core/platform/Environment.h>
+
+//#include <aws/core/utils/memory/stl/AWSStringStream.h>
+//#include <sys/utsname.h>
+
+namespace Aws
+{
+namespace Environment
+{
+
+Aws::String GetEnv(const char* variableName)
+{
+ auto variableValue = std::getenv(variableName);
+ return Aws::String( variableValue ? variableValue : "" );
+}
+
+} // namespace Environment
+} // namespace Aws
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/FileSystem.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/FileSystem.cpp
new file mode 100644
index 0000000000..c1ad818911
--- /dev/null
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/FileSystem.cpp
@@ -0,0 +1,292 @@
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+#include <aws/core/platform/FileSystem.h>
+
+#include <aws/core/platform/Environment.h>
+#include <aws/core/platform/Platform.h>
+#include <aws/core/utils/DateTime.h>
+#include <aws/core/utils/logging/LogMacros.h>
+#include <aws/core/utils/StringUtils.h>
+#include <aws/core/utils/UUID.h>
+
+#include <unistd.h>
+#include <pwd.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+#include <climits>
+
+#include <cassert>
+#ifdef __APPLE__
+#include <mach-o/dyld.h>
+#endif
+namespace Aws
+{
+namespace FileSystem
+{
+
+static const char* FILE_SYSTEM_UTILS_LOG_TAG = "FileSystemUtils";
+
+ class PosixDirectory : public Directory
+ {
+ public:
+ PosixDirectory(const Aws::String& path, const Aws::String& relativePath) : Directory(path, relativePath), m_dir(nullptr)
+ {
+ m_dir = opendir(m_directoryEntry.path.c_str());
+ AWS_LOGSTREAM_TRACE(FILE_SYSTEM_UTILS_LOG_TAG, "Entering directory " << m_directoryEntry.path);
+
+ if(m_dir)
+ {
+ AWS_LOGSTREAM_TRACE(FILE_SYSTEM_UTILS_LOG_TAG, "Successfully opened directory " << m_directoryEntry.path);
+ m_directoryEntry.fileType = FileType::Directory;
+ }
+ else
+ {
+ AWS_LOGSTREAM_ERROR(FILE_SYSTEM_UTILS_LOG_TAG, "Could not load directory " << m_directoryEntry.path << " with error code " << errno);
+ }
+ }
+
+ ~PosixDirectory()
+ {
+ if (m_dir)
+ {
+ closedir(m_dir);
+ }
+ }
+
+ operator bool() const override { return m_directoryEntry.operator bool() && m_dir != nullptr; }
+
+ DirectoryEntry Next() override
+ {
+ assert(m_dir);
+ DirectoryEntry entry;
+
+ dirent* dirEntry;
+ bool invalidEntry(true);
+
+ while(invalidEntry)
+ {
+ if ((dirEntry = readdir(m_dir)))
+ {
+ Aws::String entryName = dirEntry->d_name;
+ if(entryName != ".." && entryName != ".")
+ {
+ entry = ParseFileInfo(dirEntry, true);
+ invalidEntry = false;
+ }
+ else
+ {
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "skipping . or ..");
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ return entry;
+ }
+
+ private:
+ DirectoryEntry ParseFileInfo(dirent* dirEnt, bool computePath)
+ {
+ DirectoryEntry entry;
+
+ if(computePath)
+ {
+ Aws::StringStream ss;
+ ss << m_directoryEntry.path << PATH_DELIM << dirEnt->d_name;
+ entry.path = ss.str();
+
+ ss.str("");
+ if(m_directoryEntry.relativePath.empty())
+ {
+ ss << dirEnt->d_name;
+ }
+ else
+ {
+ ss << m_directoryEntry.relativePath << PATH_DELIM << dirEnt->d_name;
+ }
+ entry.relativePath = ss.str();
+ }
+ else
+ {
+ entry.path = m_directoryEntry.path;
+ entry.relativePath = m_directoryEntry.relativePath;
+ }
+
+ AWS_LOGSTREAM_TRACE(FILE_SYSTEM_UTILS_LOG_TAG, "Calling stat on path " << entry.path);
+
+ struct stat dirInfo;
+ if(!lstat(entry.path.c_str(), &dirInfo))
+ {
+ if(S_ISDIR(dirInfo.st_mode))
+ {
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "type directory detected");
+ entry.fileType = FileType::Directory;
+ }
+ else if(S_ISLNK(dirInfo.st_mode))
+ {
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "type symlink detected");
+ entry.fileType = FileType::Symlink;
+ }
+ else if(S_ISREG(dirInfo.st_mode))
+ {
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "type file detected");
+ entry.fileType = FileType::File;
+ }
+
+ entry.fileSize = static_cast<int64_t>(dirInfo.st_size);
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "file size detected as " << entry.fileSize);
+ }
+ else
+ {
+ AWS_LOGSTREAM_ERROR(FILE_SYSTEM_UTILS_LOG_TAG, "Failed to stat file path " << entry.path << " with error code " << errno);
+ }
+
+ return entry;
+ }
+
+ DIR* m_dir;
+ };
+
+Aws::String GetHomeDirectory()
+{
+ static const char* HOME_DIR_ENV_VAR = "HOME";
+
+ AWS_LOGSTREAM_TRACE(FILE_SYSTEM_UTILS_LOG_TAG, "Checking " << HOME_DIR_ENV_VAR << " for the home directory.");
+
+ Aws::String homeDir = Aws::Environment::GetEnv(HOME_DIR_ENV_VAR);
+
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Environment value for variable " << HOME_DIR_ENV_VAR << " is " << homeDir);
+
+ if(homeDir.empty())
+ {
+ AWS_LOGSTREAM_WARN(FILE_SYSTEM_UTILS_LOG_TAG, "Home dir not stored in environment, trying to fetch manually from the OS.");
+
+ passwd pw;
+ passwd *p_pw = nullptr;
+ char pw_buffer[4096];
+ getpwuid_r(getuid(), &pw, pw_buffer, sizeof(pw_buffer), &p_pw);
+ if(p_pw && p_pw->pw_dir)
+ {
+ homeDir = p_pw->pw_dir;
+ }
+
+ AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Pulled " << homeDir << " as home directory from the OS.");
+ }
+
+ Aws::String retVal = homeDir.size() > 0 ? Aws::Utils::StringUtils::Trim(homeDir.c_str()) : "";
+ if(!retVal.empty())
+ {
+ if(retVal.at(retVal.length() - 1) != PATH_DELIM)
+ {
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Home directory is missing the final " << PATH_DELIM << " appending one to normalize");
+ retVal += PATH_DELIM;
+ }
+ }
+
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Final Home Directory is " << retVal);
+
+ return retVal;
+}
+
+bool CreateDirectoryIfNotExists(const char* path, bool createParentDirs)
+{
+ Aws::String directoryName = path;
+ AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Creating directory " << directoryName);
+
+ for (size_t i = (createParentDirs ? 0 : directoryName.size() - 1); i < directoryName.size(); i++)
+ {
+ // Create the parent directory if we find a delimiter and the delimiter is not the first char, or if this is the target directory.
+ if (i != 0 && (directoryName[i] == FileSystem::PATH_DELIM || i == directoryName.size() - 1))
+ {
+ if (directoryName[i] == FileSystem::PATH_DELIM)
+ {
+ directoryName[i] = '\0';
+ }
+ int errorCode = mkdir(directoryName.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
+ if (errorCode != 0 && errno != EEXIST)
+ {
+ AWS_LOGSTREAM_ERROR(FILE_SYSTEM_UTILS_LOG_TAG, "Creation of directory " << directoryName.c_str() << " returned code: " << errno);
+ return false;
+ }
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Creation of directory " << directoryName.c_str() << " returned code: " << errno);
+ directoryName[i] = FileSystem::PATH_DELIM;
+ }
+ }
+ return true;
+}
+
+bool RemoveFileIfExists(const char* path)
+{
+ AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Deleting file: " << path);
+
+ int errorCode = unlink(path);
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Deletion of file: " << path << " Returned error code: " << errno);
+ return errorCode == 0 || errno == ENOENT;
+}
+
+bool RemoveDirectoryIfExists(const char* path)
+{
+ AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Deleting directory: " << path);
+ int errorCode = rmdir(path);
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Deletion of directory: " << path << " Returned error code: " << errno);
+ return errorCode == 0 || errno == ENOTDIR || errno == ENOENT;
+}
+
+bool RelocateFileOrDirectory(const char* from, const char* to)
+{
+ AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Moving file at " << from << " to " << to);
+
+ int errorCode = std::rename(from, to);
+
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "The moving operation of file at " << from << " to " << to << " Returned error code of " << errno);
+ return errorCode == 0;
+}
+
+Aws::String CreateTempFilePath()
+{
+ Aws::StringStream ss;
+ auto dt = Aws::Utils::DateTime::Now();
+
+ ss << dt.ToGmtString("%Y%m%dT%H%M%S") << dt.Millis() << Aws::String(Aws::Utils::UUID::RandomUUID());
+ Aws::String tempFile(ss.str());
+
+ AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "CreateTempFilePath generated: " << tempFile);
+
+ return tempFile;
+}
+
+Aws::String GetExecutableDirectory()
+{
+ char dest[PATH_MAX];
+ memset(dest, 0, PATH_MAX);
+#ifdef __APPLE__
+ uint32_t destSize = PATH_MAX;
+ if (_NSGetExecutablePath(dest, &destSize) == 0)
+#else
+ size_t destSize = PATH_MAX;
+ if (readlink("/proc/self/exe", dest, destSize))
+#endif
+ {
+ Aws::String executablePath(dest);
+ auto lastSlash = executablePath.find_last_of('/');
+ if(lastSlash != std::string::npos)
+ {
+ return executablePath.substr(0, lastSlash);
+ }
+ }
+ return "./";
+}
+
+Aws::UniquePtr<Directory> OpenDirectory(const Aws::String& path, const Aws::String& relativePath)
+{
+ return Aws::MakeUnique<PosixDirectory>(FILE_SYSTEM_UTILS_LOG_TAG, path, relativePath);
+}
+
+} // namespace FileSystem
+} // namespace Aws
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/OSVersionInfo.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/OSVersionInfo.cpp
new file mode 100644
index 0000000000..040173a2e5
--- /dev/null
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/OSVersionInfo.cpp
@@ -0,0 +1,59 @@
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+
+#include <aws/core/platform/OSVersionInfo.h>
+#include <aws/core/utils/memory/stl/AWSStringStream.h>
+#include <aws/core/utils/StringUtils.h>
+#include <sys/utsname.h>
+
+namespace Aws
+{
+namespace OSVersionInfo
+{
+
+Aws::String GetSysCommandOutput(const char* command)
+{
+ Aws::String outputStr;
+ FILE* outputStream;
+ const int maxBufferSize = 256;
+ char outputBuffer[maxBufferSize];
+
+ outputStream = popen(command, "r");
+
+ if (outputStream)
+ {
+ while (!feof(outputStream))
+ {
+ if (fgets(outputBuffer, maxBufferSize, outputStream) != nullptr)
+ {
+ outputStr.append(outputBuffer);
+ }
+ }
+
+ pclose(outputStream);
+
+ return Aws::Utils::StringUtils::Trim(outputStr.c_str());
+ }
+
+ return {};
+}
+
+
+Aws::String ComputeOSVersionString()
+{
+ utsname name;
+ int32_t success = uname(&name);
+ if(success >= 0)
+ {
+ Aws::StringStream ss;
+ ss << name.sysname << "/" << name.release << " " << name.machine;
+ return ss.str();
+ }
+
+ return "non-windows/unknown";
+}
+
+} // namespace OSVersionInfo
+} // namespace Aws
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Security.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Security.cpp
new file mode 100644
index 0000000000..286de1a948
--- /dev/null
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Security.cpp
@@ -0,0 +1,26 @@
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+
+#include <aws/core/platform/Security.h>
+
+#include <string.h>
+
+namespace Aws
+{
+namespace Security
+{
+
+void SecureMemClear(unsigned char *data, size_t length)
+{
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
+ memset_s(data, length, 0, length);
+#else
+ memset(data, 0, length);
+ asm volatile("" : "+m" (data));
+#endif
+}
+
+} // namespace Security
+} // namespace Aws
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Time.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Time.cpp
new file mode 100644
index 0000000000..7a0d3d1c0a
--- /dev/null
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/platform/linux-shared/Time.cpp
@@ -0,0 +1,31 @@
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+
+#include <aws/core/platform/Time.h>
+
+#include <time.h>
+
+namespace Aws
+{
+namespace Time
+{
+
+time_t TimeGM(struct tm* const t)
+{
+ return timegm(t);
+}
+
+void LocalTime(tm* t, std::time_t time)
+{
+ localtime_r(&time, t);
+}
+
+void GMTime(tm* t, std::time_t time)
+{
+ gmtime_r(&time, t);
+}
+
+} // namespace Time
+} // namespace Aws