diff --git a/src/filer.h b/src/filer.h index 54d0e54..97f1379 100644 --- a/src/filer.h +++ b/src/filer.h @@ -16,6 +16,7 @@ struct file_data { } std::shared_ptr stream = nullptr; const char* path = nullptr; + const char* relpath = nullptr; char* bin = nullptr; size_t size = 0; file_error error = {}; diff --git a/src/plugins/filer_local/filer_local.cpp b/src/plugins/filer_local/filer_local.cpp index 0716430..4f69913 100644 --- a/src/plugins/filer_local/filer_local.cpp +++ b/src/plugins/filer_local/filer_local.cpp @@ -56,6 +56,7 @@ public: // Always convert to absolute path fs::path new_cwd = fs::weakly_canonical(_cwd); fd.path = strdup(new_cwd.c_str()); + fd.relpath = strdup(fs::relative(new_cwd, root).c_str()); // Create directory if it doesn't exist if (!fs::exists(root / new_cwd)) { @@ -132,6 +133,7 @@ public: if (dir.empty() || dir == ".") { fd.path = strdup(requested_path.c_str()); + fd.relpath = strdup(fs::relative(requested_path, root).c_str()); return fd; } @@ -156,6 +158,7 @@ public: // Update current working directory relative to root cwd = "/" + rel_path.string(); fd.path = strdup(requested_path.c_str()); + fd.relpath = strdup(fs::relative(requested_path, root).c_str()); } catch (const fs::filesystem_error& ex) { logger->print(LOGLEVEL_ERROR, "Path fallback: %s", ex.what()); @@ -174,6 +177,7 @@ public: } fd.path = strdup(resolved.c_str()); + fd.relpath = strdup(fs::relative(resolved, root).c_str()); if (fs::exists(resolved)) { fd.error = file_error{FilerStatusCodes::FileExists, "Directory Already Exists"}; @@ -197,6 +201,7 @@ public: return fd; } fd.path = strdup(resolved.c_str()); + fd.relpath = strdup(fs::relative(resolved, root).c_str()); if (!fs::exists(resolved)) { fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"}; @@ -230,6 +235,7 @@ public: return fd; } fd.path = strdup(resolved.c_str()); + fd.relpath = strdup(fs::relative(resolved, root).c_str()); std::error_code err; if (!fs::remove(resolved, err)) { @@ -260,6 +266,7 @@ public: return fd; } fd.path = strdup(resolved.c_str()); + fd.relpath = strdup(fs::relative(resolved, root).c_str()); if (!fs::exists(resolved)) { fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"}; @@ -297,6 +304,7 @@ public: return fd; } 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; if (append) omode |= std::ios::app; @@ -339,6 +347,7 @@ public: // Perform the rename operation std::filesystem::rename(src_path, dst_path); fd.path = strdup(dst_path.c_str()); + fd.relpath = strdup(fs::relative(dst_path, root).c_str()); fd.error = {0, "OK"}; } catch (const std::filesystem::filesystem_error& e) { fd.error = {FilerStatusCodes::AccessDenied, e.what()}; @@ -356,6 +365,7 @@ public: return fd; } fd.path = strdup(resolved.c_str()); + fd.relpath = strdup(fs::relative(resolved, root).c_str()); if (!fs::exists(resolved)) { fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};