or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

File Link Manager

Build a simple utility that creates and manages symbolic links in a filesystem for organizing related files.

Background

Your task is to implement a file link manager that helps organize files by creating symbolic links. The manager should be able to create links to files, verify link creation, and handle various edge cases.

Requirements

Implement a FileLinkManager class with the following functionality:

Link Creation

The manager should create symbolic links from a source path to a target path. When creating a link:

  • The link should point to the target file or directory
  • If a link already exists at the same path, throw an error
  • Return true when the link is successfully created

Link Verification

The manager should verify that a symbolic link exists and points to the expected target:

  • Check if a path is a symbolic link
  • Read and return the target path that a symbolic link points to
  • Return null if the path is not a symbolic link

Error Handling

The manager should handle error conditions appropriately:

  • Throw an error when attempting to create a link at a path that already exists
  • Throw an error when attempting to read a non-existent link
  • Provide meaningful error messages

Test Cases

Your implementation should pass the following test cases:

  • Creates a symbolic link pointing to a file @test
  • Throws an error when creating a link at an existing path @test
  • Verifies a symbolic link and returns its target path @test
  • Returns null when checking a regular file (not a symlink) @test

Implementation

@generates

API

/**
 * Manages symbolic links in a filesystem
 */
class FileLinkManager {
  /**
   * Creates a new FileLinkManager
   * @param {Object} fs - Filesystem module to use for operations
   */
  constructor(fs);

  /**
   * Creates a symbolic link from linkPath to targetPath
   * @param {string} targetPath - The path the symbolic link should point to
   * @param {string} linkPath - The path where the symbolic link should be created
   * @returns {boolean} - Returns true if link was created successfully
   * @throws {Error} - Throws if link already exists or operation fails
   */
  createLink(targetPath, linkPath);

  /**
   * Verifies if a path is a symbolic link and returns its target
   * @param {string} linkPath - The path to check
   * @returns {string|null} - Returns the target path if it's a symlink, null otherwise
   */
  verifyLink(linkPath);
}

module.exports = { FileLinkManager };

Dependencies { .dependencies }

metro-memory-fs { .dependency }

Provides an in-memory filesystem implementation for testing.

@satisfied-by