add relpath variable to file_data
This commit is contained in:
@@ -16,6 +16,7 @@ struct file_data {
|
|||||||
}
|
}
|
||||||
std::shared_ptr<std::ifstream> stream = nullptr;
|
std::shared_ptr<std::ifstream> stream = nullptr;
|
||||||
const char* path = nullptr;
|
const char* path = nullptr;
|
||||||
|
const char* relpath = nullptr;
|
||||||
char* bin = nullptr;
|
char* bin = nullptr;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
file_error error = {};
|
file_error error = {};
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
// 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 = strdup(new_cwd.c_str());
|
fd.path = strdup(new_cwd.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(new_cwd, root).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)) {
|
||||||
@@ -132,6 +133,7 @@ public:
|
|||||||
|
|
||||||
if (dir.empty() || dir == ".") {
|
if (dir.empty() || dir == ".") {
|
||||||
fd.path = strdup(requested_path.c_str());
|
fd.path = strdup(requested_path.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(requested_path, root).c_str());
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,6 +158,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 = strdup(requested_path.c_str());
|
fd.path = strdup(requested_path.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(requested_path, root).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());
|
||||||
@@ -174,6 +177,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
fd.path = strdup(resolved.c_str());
|
fd.path = strdup(resolved.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(resolved, root).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"};
|
||||||
@@ -197,6 +201,7 @@ public:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = strdup(resolved.c_str());
|
fd.path = strdup(resolved.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(resolved, root).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"};
|
||||||
@@ -230,6 +235,7 @@ public:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = strdup(resolved.c_str());
|
fd.path = strdup(resolved.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(resolved, root).c_str());
|
||||||
|
|
||||||
std::error_code err;
|
std::error_code err;
|
||||||
if (!fs::remove(resolved, err)) {
|
if (!fs::remove(resolved, err)) {
|
||||||
@@ -260,6 +266,7 @@ public:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = strdup(resolved.c_str());
|
fd.path = strdup(resolved.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(resolved, root).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"};
|
||||||
@@ -297,6 +304,7 @@ public:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = strdup(resolved.c_str());
|
fd.path = strdup(resolved.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(resolved, root).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;
|
||||||
@@ -339,6 +347,7 @@ 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.path = strdup(dst_path.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(dst_path, root).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()};
|
||||||
@@ -356,6 +365,7 @@ public:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
fd.path = strdup(resolved.c_str());
|
fd.path = strdup(resolved.c_str());
|
||||||
|
fd.relpath = strdup(fs::relative(resolved, root).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