From f4f144cc399a5b816faf5eb60778f61eba28ad1f Mon Sep 17 00:00:00 2001 From: bernatx Date: Tue, 9 Nov 2021 09:59:54 +0100 Subject: [PATCH] Add folder with current CARLA version to cache --- LibCarla/source/carla/client/FIleTransfer.cpp | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/LibCarla/source/carla/client/FIleTransfer.cpp b/LibCarla/source/carla/client/FIleTransfer.cpp index bfbc68b8a..bcb0b8097 100644 --- a/LibCarla/source/carla/client/FIleTransfer.cpp +++ b/LibCarla/source/carla/client/FIleTransfer.cpp @@ -5,6 +5,7 @@ // For a copy, see . #include "FileTransfer.h" +#include "carla/Version.h" namespace carla { namespace client { @@ -33,11 +34,21 @@ namespace client { bool FileTransfer::FileExists(std::string file) { // Check if the file exists or not struct stat buffer; - return (stat((_filesBaseFolder + file).c_str(), &buffer) == 0); + std::string fullpath = _filesBaseFolder; + fullpath += "/"; + fullpath += ::carla::version(); + fullpath += "/"; + fullpath += file; + + return (stat(fullpath.c_str(), &buffer) == 0); } bool FileTransfer::WriteFile(std::string path, std::vector content) { - std::string writePath = _filesBaseFolder + path; + std::string writePath = _filesBaseFolder; + writePath += "/"; + writePath += ::carla::version(); + writePath += "/"; + writePath += path; // Validate and create the file path carla::FileSystem::ValidateFilePath(writePath); @@ -56,8 +67,13 @@ namespace client { } std::vector FileTransfer::ReadFile(std::string path) { + std::string fullpath = _filesBaseFolder; + fullpath += "/"; + fullpath += ::carla::version(); + fullpath += "/"; + fullpath += path; // Read the binary file from the base folder - std::ifstream file(_filesBaseFolder + path, std::ios::binary); + std::ifstream file(fullpath, std::ios::binary); std::vector content(std::istreambuf_iterator(file), {}); return content; }