Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 10, 2025

This PR separates the monolithic Node class into specialized FileNode and DirNode classes that inherit from a common abstract Node base class, improving code organization and type safety.

Changes Made

  • Abstract Node base class: Contains common functionality like timestamps, permissions, mode, uid/gid, symlink support, and permission checks
  • FileNode class: Extends Node with file-specific operations (getString(), setString(), getBuffer(), setBuffer(), write(), read(), truncate(), and the buf property)
  • DirNode class: Extends Node for directories (no buffer operations needed)
  • Smart node creation: Updated Superblock.createNode() to instantiate the appropriate node type based on file mode (S_IFDIRDirNode, otherwise → FileNode)
  • Updated exports: Added FileNode and DirNode to module exports alongside the base Node class

Benefits

  • Better separation of concerns: File-specific operations are now isolated to FileNode
  • Type safety: Abstract base class prevents direct instantiation of the generic Node class
  • Backward compatibility: All existing APIs continue to work exactly as before
  • Memory efficiency: Directory nodes no longer carry unnecessary buffer-related properties

Testing

  • All existing tests pass without modification (except updating the node-specific test to use FileNode)
  • Manual verification confirms both node types work correctly with their respective operations
  • Build and linter checks pass successfully

The implementation maintains full backward compatibility while providing a cleaner, more maintainable codebase structure.

Fixes #1181.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Separate Node class for files and directories feat: separate Node class into FileNode and DirNode classes Sep 10, 2025
@Copilot Copilot AI requested a review from streamich September 10, 2025 13:56
Copilot finished work on behalf of streamich September 10, 2025 13:56
@streamich streamich marked this pull request as ready for review September 10, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate Node class for files and directories
2 participants