or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

File System Node Inspector

Build a utility that inspects and analyzes the internal structure of a memory-based filesystem. Your implementation should be able to traverse the filesystem and collect information about different types of nodes (directories, files, and symbolic links), including their properties and relationships.

Requirements

Your solution should:

  1. Identify Node Types: Distinguish between directories, files, and symbolic links
  2. Traverse the Structure: Recursively walk through the filesystem starting from a given path
  3. Collect Statistics: Generate a summary report containing:
    • Total count of each node type (directories, files, symbolic links)
    • A list of all symbolic links with their target paths
    • A list of all files with their sizes in bytes

Implementation Details

Create a module inspector.js that exports a function analyzeFilesystem(fs, rootPath):

  • Input:
    • fs: An instance of the memory filesystem
    • rootPath: The starting path to analyze (e.g., '/')
  • Output: An object with the structure:
    {
      totalDirectories: <number>,
      totalFiles: <number>,
      totalSymlinks: <number>,
      symlinks: [{ path: <string>, target: <string> }, ...],
      files: [{ path: <string>, size: <number> }, ...]
    }

Test Cases { .test }

Create a test file inspector.test.js with the following test cases:

Test 1: Basic filesystem structure @test

// Setup: Create a simple filesystem with one directory, one file, and one symlink
// /testdir/
// /testdir/file.txt (content: "hello world")
// /link -> /testdir/file.txt

// Expected output:
{
  totalDirectories: 2,  // root + testdir
  totalFiles: 1,
  totalSymlinks: 1,
  symlinks: [{ path: '/link', target: '/testdir/file.txt' }],
  files: [{ path: '/testdir/file.txt', size: 11 }]
}

Test 2: Nested directories @test

// Setup: Create nested directory structure
// /a/
// /a/b/
// /a/b/c/
// /a/b/c/data.txt (content: "test")

// Expected output:
{
  totalDirectories: 4,  // root + a + b + c
  totalFiles: 1,
  totalSymlinks: 0,
  symlinks: [],
  files: [{ path: '/a/b/c/data.txt', size: 4 }]
}

Test 3: Multiple files and symlinks @test

// Setup: Mixed filesystem structure
// /docs/
// /docs/readme.md (content: "documentation")
// /docs/guide.md (content: "instructions")
// /config.json (content: "{}")
// /readme -> /docs/readme.md

// Expected output:
{
  totalDirectories: 2,  // root + docs
  totalFiles: 3,
  totalSymlinks: 1,
  symlinks: [{ path: '/readme', target: '/docs/readme.md' }],
  files: [
    { path: '/docs/readme.md', size: 13 },
    { path: '/docs/guide.md', size: 12 },
    { path: '/config.json', size: 2 }
  ]
}

Dependencies { .dependencies }

metro-memory-fs { .dependency }

Provides an in-memory filesystem implementation for testing purposes.