fix broken memory when assigning fd.path variable
This commit is contained in:
@@ -27,7 +27,7 @@ public:
|
|||||||
try {
|
try {
|
||||||
// Always convert to absolute path
|
// Always convert to absolute path
|
||||||
fs::path new_root = fs::absolute(fs::weakly_canonical(_root));
|
fs::path new_root = fs::absolute(fs::weakly_canonical(_root));
|
||||||
fd.path = new_root.string().c_str();
|
fd.path = strdup(new_root.c_str());
|
||||||
|
|
||||||
// Create directory if it doesn't exist
|
// Create directory if it doesn't exist
|
||||||
if (!fs::exists(new_root)) {
|
if (!fs::exists(new_root)) {
|
||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
try {
|
try {
|
||||||
// Always convert to absolute path
|
// Always convert to absolute path
|
||||||
fs::path new_cwd = fs::weakly_canonical(_cwd);
|
fs::path new_cwd = fs::weakly_canonical(_cwd);
|
||||||
fd.path = new_cwd.string().c_str();
|
fd.path = strdup(new_cwd.c_str());
|
||||||
|
|
||||||
// Create directory if it doesn't exist
|
// Create directory if it doesn't exist
|
||||||
if (!fs::exists(root / new_cwd)) {
|
if (!fs::exists(root / new_cwd)) {
|
||||||
@@ -131,7 +131,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dir.empty() || dir == ".") {
|
if (dir.empty() || dir == ".") {
|
||||||
fd.path = requested_path.c_str();
|
fd.path = strdup(requested_path.c_str());
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ public:
|
|||||||
|
|
||||||
// Update current working directory relative to root
|
// Update current working directory relative to root
|
||||||
cwd = "/" + rel_path.string();
|
cwd = "/" + rel_path.string();
|
||||||
fd.path = requested_path.string().c_str();
|
fd.path = strdup(requested_path.c_str());
|
||||||
|
|
||||||
} catch (const fs::filesystem_error& ex) {
|
} catch (const fs::filesystem_error& ex) {
|
||||||
logger->print(LOGLEVEL_ERROR, "Path fallback: %s", ex.what());
|
logger->print(LOGLEVEL_ERROR, "Path fallback: %s", ex.what());
|
||||||
@@ -173,7 +173,7 @@ public:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd.path = resolved.string().c_str();
|
fd.path = strdup(resolved.c_str());
|
||||||
|
|
||||||
if (fs::exists(resolved)) {
|
if (fs::exists(resolved)) {
|
||||||
fd.error = file_error{FilerStatusCodes::FileExists, "Directory Already Exists"};
|
fd.error = file_error{FilerStatusCodes::FileExists, "Directory Already Exists"};
|
||||||
@@ -196,7 +196,7 @@ public:
|
|||||||
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = resolved.string().c_str();
|
fd.path = strdup(resolved.c_str());
|
||||||
|
|
||||||
if (!fs::exists(resolved)) {
|
if (!fs::exists(resolved)) {
|
||||||
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};
|
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};
|
||||||
@@ -229,7 +229,7 @@ public:
|
|||||||
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = resolved.c_str();
|
fd.path = strdup(resolved.c_str());
|
||||||
|
|
||||||
std::error_code err;
|
std::error_code err;
|
||||||
if (!fs::remove(resolved, err)) {
|
if (!fs::remove(resolved, err)) {
|
||||||
@@ -259,7 +259,7 @@ public:
|
|||||||
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = resolved.string().c_str();
|
fd.path = strdup(resolved.c_str());
|
||||||
|
|
||||||
if (!fs::exists(resolved)) {
|
if (!fs::exists(resolved)) {
|
||||||
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};
|
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};
|
||||||
@@ -296,7 +296,7 @@ public:
|
|||||||
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = resolved.string().c_str();
|
fd.path = strdup(resolved.c_str());
|
||||||
|
|
||||||
std::ios_base::openmode omode = std::ios::out|std::ios::binary;
|
std::ios_base::openmode omode = std::ios::out|std::ios::binary;
|
||||||
if (append) omode |= std::ios::app;
|
if (append) omode |= std::ios::app;
|
||||||
@@ -338,8 +338,8 @@ public:
|
|||||||
|
|
||||||
// Perform the rename operation
|
// Perform the rename operation
|
||||||
std::filesystem::rename(src_path, dst_path);
|
std::filesystem::rename(src_path, dst_path);
|
||||||
|
fd.path = strdup(dst_path.c_str());
|
||||||
fd.error = {0, "OK"};
|
fd.error = {0, "OK"};
|
||||||
|
|
||||||
} catch (const std::filesystem::filesystem_error& e) {
|
} catch (const std::filesystem::filesystem_error& e) {
|
||||||
fd.error = {FilerStatusCodes::AccessDenied, e.what()};
|
fd.error = {FilerStatusCodes::AccessDenied, e.what()};
|
||||||
}
|
}
|
||||||
@@ -355,7 +355,7 @@ public:
|
|||||||
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = resolved.string().c_str();
|
fd.path = strdup(resolved.c_str());
|
||||||
|
|
||||||
if (!fs::exists(resolved)) {
|
if (!fs::exists(resolved)) {
|
||||||
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};
|
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};
|
||||||
|
|||||||
Reference in New Issue
Block a user