yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::cli::agent::tools::FileSystemToolBase Class Reference

Base class for filesystem operations. More...

#include <filesystem_tool.h>

Inherits yaze::cli::resources::CommandHandler.

Inherited by yaze::cli::agent::tools::FileSystemExistsTool, yaze::cli::agent::tools::FileSystemInfoTool, yaze::cli::agent::tools::FileSystemListTool, and yaze::cli::agent::tools::FileSystemReadTool.

Collaboration diagram for yaze::cli::agent::tools::FileSystemToolBase:

Protected Member Functions

absl::StatusOr< std::filesystem::path > ValidatePath (const std::string &path_str) const
 Validate and normalize a path for safe access.
 
std::filesystem::path GetProjectRoot () const
 Get the project root directory.
 
bool IsPathInProject (const std::filesystem::path &path) const
 Check if a path is within the project directory.
 
std::string FormatFileSize (uintmax_t size_bytes) const
 Format file size for human-readable output.
 
std::string FormatTimestamp (const std::filesystem::file_time_type &time) const
 Format timestamp for readable output.
 
- Protected Member Functions inherited from yaze::cli::resources::CommandHandler
virtual absl::Status ValidateArgs (const ArgumentParser &parser)=0
 Validate command arguments.
 
virtual absl::Status Execute (Rom *rom, const ArgumentParser &parser, OutputFormatter &formatter)=0
 Execute the command business logic.
 
virtual std::string GetDefaultFormat () const
 Get the default output format ("json" or "text")
 
virtual std::string GetOutputTitle () const
 Get the output title for formatting.
 

Additional Inherited Members

- Public Member Functions inherited from yaze::cli::resources::CommandHandler
virtual ~CommandHandler ()=default
 
absl::Status Run (const std::vector< std::string > &args, Rom *rom_context, std::string *captured_output=nullptr)
 Execute the command.
 
virtual std::string GetName () const =0
 Get the command name.
 
virtual Descriptor Describe () const
 Provide metadata for TUI/help summaries.
 
virtual std::string GetUsage () const =0
 Get the command usage string.
 
virtual bool RequiresRom () const
 Check if the command requires a loaded ROM.
 
virtual bool RequiresLabels () const
 Check if the command requires ROM labels.
 
virtual void SetProjectContext (project::YazeProject *project)
 Set the YazeProject context. Default implementation does nothing, override if tool needs project info.
 
virtual void SetAsarWrapper (core::AsarWrapper *asar_wrapper)
 Set the AsarWrapper context. Default implementation does nothing, override if tool needs Asar access.
 
virtual void SetRomContext (Rom *rom)
 Set the ROM context for tools that need ROM access. Default implementation stores the ROM pointer for subclass use.
 
- Protected Attributes inherited from yaze::cli::resources::CommandHandler
Romrom_ = nullptr
 
project::YazeProjectproject_ = nullptr
 
core::AsarWrapperasar_wrapper_ = nullptr
 

Detailed Description

Base class for filesystem operations.

Provides common functionality for filesystem tools including:

  • Path validation and sanitization
  • Project directory restriction
  • Security checks (path traversal protection)

Definition at line 24 of file filesystem_tool.h.

Member Function Documentation

◆ ValidatePath()

absl::StatusOr< fs::path > yaze::cli::agent::tools::FileSystemToolBase::ValidatePath ( const std::string & path_str) const
protected

Validate and normalize a path for safe access.

Ensures the path:

  • Is within the project directory
  • Does not contain path traversal attempts (..)
  • Is normalized to an absolute path

Definition at line 23 of file filesystem_tool.cc.

References GetProjectRoot(), and IsPathInProject().

Referenced by yaze::cli::agent::tools::FileSystemListTool::Execute(), yaze::cli::agent::tools::FileSystemReadTool::Execute(), yaze::cli::agent::tools::FileSystemExistsTool::Execute(), and yaze::cli::agent::tools::FileSystemInfoTool::Execute().

Here is the call graph for this function:

◆ GetProjectRoot()

fs::path yaze::cli::agent::tools::FileSystemToolBase::GetProjectRoot ( ) const
protected

Get the project root directory.

Returns the root directory of the yaze project. Defaults to current working directory if not explicitly set.

Definition at line 71 of file filesystem_tool.cc.

Referenced by IsPathInProject(), and ValidatePath().

◆ IsPathInProject()

bool yaze::cli::agent::tools::FileSystemToolBase::IsPathInProject ( const std::filesystem::path & path) const
protected

Check if a path is within the project directory.

Definition at line 98 of file filesystem_tool.cc.

References GetProjectRoot().

Referenced by ValidatePath().

Here is the call graph for this function:

◆ FormatFileSize()

std::string yaze::cli::agent::tools::FileSystemToolBase::FormatFileSize ( uintmax_t size_bytes) const
protected

◆ FormatTimestamp()

std::string yaze::cli::agent::tools::FileSystemToolBase::FormatTimestamp ( const std::filesystem::file_time_type & time) const
protected

Format timestamp for readable output.

Definition at line 127 of file filesystem_tool.cc.

Referenced by yaze::cli::agent::tools::FileSystemInfoTool::Execute().


The documentation for this class was generated from the following files: