From 7feabb1807b80e23b3920eac5a384072f604d905 Mon Sep 17 00:00:00 2001
From: Nico <nigr21@inf.ufpr.br>
Date: Sat, 25 Feb 2023 11:10:04 -0300
Subject: [PATCH] ahh

---
 headers/client.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/headers/client.h b/headers/client.h
index bf547f4..e704893 100644
--- a/headers/client.h
+++ b/headers/client.h
@@ -211,9 +211,12 @@ int client::send_message(vector<char> data, int type) {
 string client::calc_file_size(string fileName)
 {
   struct stat buffer;
-  stat(fileName.c_str(), &buffer);
-  int fileSize = buffer.st_size;
+  if ( stat(fileName.c_str(), &buffer) == -1 ) {
+    cout << "Arquivo inexistente. Operacao abortada\n";
+    return {};
+  }
 
+  int fileSize = buffer.st_size;
   return to_string(fileSize);
 }
 
@@ -221,11 +224,6 @@ vector<char> client::read_file(string fileName)
 {
   fstream file;
   file.open(fileName, ios::in); 
-
-  if (!file) {
-    cout << "Arquivo inexistente. Operacao abortada\n";
-    return vector<char>();
-  }
   
   string teste;
   vector<char> fileData;
@@ -254,6 +252,8 @@ void client::send_file() {
 
   // Envia o primeiro frame com o tamanho do arquivo
   string fileSize = calc_file_size(fileName);
+  if ( fileSize.empty() ) { return; }
+
   cout << "Tamanho do arquivo: " << fileSize << "\n";
   cout << "Enviando tamanho do arquivo\n";
   if (!send_message(vector<char>(fileSize.begin(), fileSize.end()), MIDIA))
-- 
GitLab