Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Gouache committed Sep 20, 2024
1 parent e6be430 commit 5cb469d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 102 deletions.
52 changes: 0 additions & 52 deletions src/drivertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ int (*ptr_driver_copyToLocal)(const char *sourcefilename,
const char *destfilename);
int (*ptr_driver_copyFromLocal)(const char *sourcefilename,
const char *destfilename);
void *(*ptr_test_getClient)();
bool (*ptr_test_compareFiles)(const char* local_file_path, const char* s3_uri);

/* functions prototype */
Expand Down Expand Up @@ -163,8 +162,6 @@ int main(int argc, char *argv[]) {
get_shared_library_function(library_handle, "driver_copyToLocal", 0);
*(void **)(&ptr_driver_copyFromLocal) =
get_shared_library_function(library_handle, "driver_copyFromLocal", 0);
*(void **)(&ptr_test_getClient) =
get_shared_library_function(library_handle, "test_getClient", 1);
*(void **)(&ptr_test_compareFiles) =
get_shared_library_function(library_handle, "test_compareFiles", 1);
}
Expand Down Expand Up @@ -546,52 +543,3 @@ void compareFiles(std::string local_file_path, std::string s3_uri) {
global_error = 1;
}
}

#if 0
void compareFiles(std::string local_file_path, std::string s3_uri) {
// Lire le fichier local
std::ifstream local_file(local_file_path, std::ios::binary);
if (!local_file) {
std::cerr << "Failure reading local file" << std::endl;
global_error = 1;
}
std::string local_content((std::istreambuf_iterator<char>(local_file)),
std::istreambuf_iterator<char>());

// Créer un client S3
Aws::S3::S3Client* s3_client = (Aws::S3::S3Client*)ptr_test_getClient();

// Télécharger l'objet S3
char const *prefix = "s3://";
const size_t prefix_size{std::strlen(prefix)};
const size_t pos = s3_uri.find('/', prefix_size);
std::string bucket_name = s3_uri.substr(prefix_size, pos - prefix_size);
std::string object_name = s3_uri.substr(pos + 1);

// Télécharger l'objet S3
Aws::S3::Model::GetObjectRequest object_request;
object_request.SetBucket(bucket_name.c_str());
object_request.SetKey(object_name.c_str());
auto get_object_outcome = s3_client->GetObject(object_request);
if (!get_object_outcome.IsSuccess()) {
std::cerr << "Failure retrieving object from S3" << std::endl;
global_error = 1;
return;
}

std::cerr << "Read OK, compare data" << std::endl;

// Lire le contenu de l'objet S3
std::stringstream s3_content;
s3_content << get_object_outcome.GetResult().GetBody().rdbuf();

std::cerr << "Result downloaded" << std::endl;

// Comparer les contenus
if (local_content != s3_content.str()) {
std::cerr << "Files are different" << std::endl;
global_error = 1;
}
return;
}
#endif
14 changes: 2 additions & 12 deletions src/s3plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ void* test_getActiveWriterHandles()
return &active_writer_handles;
}

void* test_getClient()
{
return client.get();
}

#define KH_S3_NOT_CONNECTED(err_val) \
if (kFalse == bIsConnected) \
{ \
Expand Down Expand Up @@ -1591,7 +1586,7 @@ long long int driver_fwrite(const void* ptr, size_t size, size_t count, void* st
return to_write;
}

int driver_fflush(void* stream)
int driver_fflush(void*)
{
KH_S3_NOT_CONNECTED(kBadSize);

Expand Down Expand Up @@ -1685,7 +1680,6 @@ int driver_copyToLocal(const char* sSourceFilePathName, const char* sDestFilePat
auto read_and_write = [](const Reader& from, size_t part, std::ofstream& to_file) -> bool
{
// file metadata
const Aws::String& file_name = from.filenames_[part];
const long long header_size = from.common_header_length_;

// limit download to a few MBs at a time.
Expand Down Expand Up @@ -1805,10 +1799,6 @@ bool test_compareFiles(const char* local_file_path_str, const char* s3_uri_str)
std::string local_content((std::istreambuf_iterator<char>(local_file)),
std::istreambuf_iterator<char>());

// Créer un client S3
Aws::S3::S3Client *s3_client =
reinterpret_cast<Aws::S3::S3Client *>(test_getClient());

// Télécharger l'objet S3
char const *prefix = "s3://";
const size_t prefix_size{std::strlen(prefix)};
Expand All @@ -1820,7 +1810,7 @@ bool test_compareFiles(const char* local_file_path_str, const char* s3_uri_str)
Aws::S3::Model::GetObjectRequest object_request;
object_request.SetBucket(bucket_name.c_str());
object_request.SetKey(object_name.c_str());
auto get_object_outcome = s3_client->GetObject(object_request);
auto get_object_outcome = client->GetObject(object_request);
if (!get_object_outcome.IsSuccess()) {
std::cerr << "Failure retrieving object from S3" << std::endl;
return false;
Expand Down
2 changes: 0 additions & 2 deletions src/s3plugin_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ extern "C"

VISIBLE void* test_getActiveWriterHandles();

VISIBLE void* test_getClient();

VISIBLE bool test_compareFiles(const char* local_file_path, const char* s3_uri);

#ifdef __cplusplus
Expand Down
39 changes: 3 additions & 36 deletions test/drivertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,42 +450,9 @@ int compareSize(const char *file_name_output, long long int filesize) {
}

int compareFiles(std::string local_file_path, std::string s3_uri) {
// Lire le fichier local
std::ifstream local_file(local_file_path, std::ios::binary);
if (!local_file) {
std::cerr << "Failure reading local file" << std::endl;
if (!test_compareFiles(local_file_path.c_str(), s3_uri.c_str())) {
std::cerr << "Files are different" << std::endl;
return false;
}
std::string local_content((std::istreambuf_iterator<char>(local_file)),
std::istreambuf_iterator<char>());

// Créer un client S3
Aws::S3::S3Client *s3_client =
reinterpret_cast<Aws::S3::S3Client *>(test_getClient());

// Télécharger l'objet S3
char const *prefix = "s3://";
const size_t prefix_size{std::strlen(prefix)};
const size_t pos = s3_uri.find('/', prefix_size);
std::string bucket_name = s3_uri.substr(prefix_size, pos - prefix_size);
std::string object_name = s3_uri.substr(pos + 1);

// Télécharger l'objet S3
Aws::S3::Model::GetObjectRequest object_request;
object_request.SetBucket(bucket_name.c_str());
object_request.SetKey(object_name.c_str());
auto get_object_outcome = s3_client->GetObject(object_request);
if (!get_object_outcome.IsSuccess()) {
std::cerr << "Failure retrieving object from S3" << std::endl;
return false;
}

// Lire le contenu de l'objet S3
std::stringstream s3_content;
s3_content << get_object_outcome.GetResult().GetBody().rdbuf();

// Comparer les contenus
auto result = local_content == s3_content.str() ? kSuccess : kFailure;

return result;
return true;
}

0 comments on commit 5cb469d

Please sign in to comment.