Skip to content

Fix: Create test_images directory if it doesn't exist#87

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-30828954-610e-4815-bf44-003d6dd67220
Draft

Fix: Create test_images directory if it doesn't exist#87
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-30828954-610e-4815-bf44-003d6dd67220

Conversation

Copy link
Copy Markdown

Copilot AI commented Sep 26, 2025

Fixes an issue where the convert() function would fail when trying to save PNG files to the test_images directory in fresh git clones or installations where this directory doesn't exist.

Problem

The convert() function in crates/crust-core/src/convert.rs generates PNG filenames using paths like ./test_images/{timestamp}.png via the unique_timestamp() function. However, the function attempts to save files to this directory without ensuring it exists first, causing the save operation to fail with a directory not found error in fresh installations.

Solution

Added automatic directory creation before attempting to save PNG files:

// Ensure the test_images directory exists
if let Err(e) = fs::create_dir_all("./test_images") {
    error!("Failed to create test_images directory: {}", e);
    std::process::exit(1);
}

The fix uses fs::create_dir_all() which:

  • Creates the directory if it doesn't exist
  • Succeeds silently if the directory already exists (idempotent)
  • Creates parent directories if needed
  • Maintains consistent error handling with the existing code pattern

Changes

  • Added use std::fs; import
  • Added directory creation logic before the PNG save operation
  • Maintains existing error handling patterns using tracing::error and std::process::exit(1)

This ensures users can successfully run the conversion process immediately after cloning the repository without manual directory creation.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/doubleailes/ogawa-rs/commits/HEAD
    • Triggering command: /home/REDACTED/.rustup/toolchains/1.89.0-x86_64-REDACTED-linux-gnu/bin/cargo check (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Create test_images folder if it does not exist</issue_title>
<issue_description>The folder test_images used in the convert process to png maybe not exist in a fresh git clone or install.

It can be great if can be create in case in does not exist already</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #86

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: doubleailes <23233470+doubleailes@users.noreply.github.com>
Copilot AI changed the title [WIP] Create test_images folder if it does not exist Fix: Create test_images directory if it doesn't exist Sep 26, 2025
Copilot AI requested a review from doubleailes September 26, 2025 08:38
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.

Create test_images folder if it does not exist

2 participants