Skip to content

Conversation

ildyria
Copy link
Member

@ildyria ildyria commented Aug 31, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Prevents false failure status after successful cleanup in background extraction tasks.
    • Improves reliability of directory deletion during maintenance and cleanup.
  • Refactor

    • Centralizes recursive directory removal via a shared helper for consistent behavior across the app.
  • Documentation

    • Updates facade documentation to expose the new directory removal method.

@ildyria ildyria requested a review from a team as a code owner August 31, 2025 09:44
Copy link

coderabbitai bot commented Aug 31, 2025

📝 Walkthrough

Walkthrough

Adds Helpers::remove_dir(string $dir) to App\Assets\Helpers, documents it on the Helpers facade, and replaces ad-hoc directory removals in a controller and a job to call the centralized helper; the job removes its internal remover and returns early on success.

Changes

Cohort / File(s) Change summary
Helper implementation
app/Assets/Helpers.php
Added public function remove_dir(string $dir): void that recursively deletes files and subdirectories using RecursiveDirectoryIterator (CHILD_FIRST) and calls Safe\unlink / Safe\rmdir; imports Safe\FilesystemException; documents possible exception.
Facade API annotation
app/Facades/Helpers.php
Added PHPDoc annotation @method static void remove_dir(string $dir): void to reflect the new helper method; no runtime code change.
Controller integration
app/Http/Controllers/Admin/Maintenance/Cleaning.php
Replaced direct rmdir(...) calls with Helpers::remove_dir(...); added use App\Facades\Helpers; and removed use function Safe\rmdir;; file deletion for non-directories remains via unlink(...).
Job refactor and flow tweak
app/Jobs/CleanUpExtraction.php
Removed the job's internal directory-removal implementation and Safe imports; now calls Helpers::remove_dir($this->folder_path) in handle() and returns early on successful removal to avoid overriding status; other control flow unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I nibble bytes and tidy every burrow,
A Helper hops and clears each folder narrow.
Facade gives a shout, the job skips back with glee,
Early return—now everything is free.
Carrots stored, the warren hums in harmony. 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-clean-up-action

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ildyria ildyria changed the title Fix cleanup action no working on directories Fix cleanup action not working on directories Aug 31, 2025
Copy link

codecov bot commented Aug 31, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.18%. Comparing base (701e36b) to head (44fde05).
⚠️ Report is 4 commits behind head on master.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ildyria
Copy link
Member Author

ildyria commented Aug 31, 2025

@CodeRabbit review

Copy link

coderabbitai bot commented Aug 31, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
app/Facades/Helpers.php (1)

31-31: Facade doc added — consider camelCase for consistency

Most methods on Helpers use camelCase. Consider renaming to removeDir for consistency across the codebase.

Apply across files:

- * @method static void    remove_dir(string $dir): void
+ * @method static void    removeDir(string $dir): void
app/Assets/Helpers.php (2)

279-282: Add minimal guardrails to avoid accidental top-level deletion

Cheap safety net; bail out early on invalid or dangerous inputs. Keeps Helper generic while avoiding obvious footguns.

 public function remove_dir(string $dir): void
 {
+    // Guardrails
+    if ($dir === '' || $dir === '/' || !is_dir($dir)) {
+        return;
+    }
     $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);

279-291: Optional: method naming consistency

If you adopt camelCase, update the method here as well.

- public function remove_dir(string $dir): void
+ public function removeDir(string $dir): void
app/Http/Controllers/Admin/Maintenance/Cleaning.php (1)

49-53: Prefer getPathname() and align with optional rename

getRealPath() can return false; getPathname() is safer with DirectoryIterator when you already control the base path. Also, if you switch to removeDir (camelCase), update here.

-Helpers::remove_dir($file_info->getRealPath());
+Helpers::remove_dir($file_info->getPathname());

If adopting camelCase rename:

-Helpers::remove_dir($file_info->getPathname());
+Helpers::removeDir($file_info->getPathname());

And for files:

-unlink($file_info->getRealPath());
+unlink($file_info->getPathname());
app/Jobs/CleanUpExtraction.php (1)

58-63: Happy path + early return — LGTM; consider optional catch for richer history

Current behavior will fail the job if deletion throws (which may be fine). If you prefer to record a FAILURE status with context instead of a failed job, catch FilesystemException, set status to FAILURE, and rethrow or return.

Example:

-Helpers::remove_dir($this->folder_path);
+try {
+    Helpers::remove_dir($this->folder_path);
+} catch (\Safe\Exceptions\FilesystemException $e) {
+    $this->history->status = JobStatus::FAILURE;
+    $this->history->save();
+    throw $e; // or return; depending on desired semantics
+}

If adopting camelCase:

-Helpers::remove_dir($this->folder_path);
+Helpers::removeDir($this->folder_path);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 701e36b and df16b89.

📒 Files selected for processing (4)
  • app/Assets/Helpers.php (2 hunks)
  • app/Facades/Helpers.php (1 hunks)
  • app/Http/Controllers/Admin/Maintenance/Cleaning.php (2 hunks)
  • app/Jobs/CleanUpExtraction.php (2 hunks)
🔇 Additional comments (3)
app/Assets/Helpers.php (1)

14-19: Safe filesystem imports — LGTM

Importing Safe exceptions and functions here is appropriate and keeps failure modes explicit.

app/Http/Controllers/Admin/Maintenance/Cleaning.php (1)

11-11: Centralizing deletion via Helpers facade — good move

Reduces duplication and keeps behavior consistent across call sites.

app/Jobs/CleanUpExtraction.php (1)

12-12: Facade import — LGTM

Keeps the job lean and delegates deletion specifics to the shared helper.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
app/Assets/Helpers.php (2)

294-295: Release iterators before removing the root directory (Windows handle contention)

On Windows, open directory handles held by iterators can prevent rmdir(). Free them explicitly before the final removal.

-    rmdir($dir);
+    // Ensure iterators release directory handles before final removal (notably on Windows)
+    unset($files, $it);
+    rmdir($dir);

277-278: Docblock: include all thrown exceptions

If you adopt the guards above, document the additional exception for callers.

-     * @throws FilesystemException
+     * @throws FilesystemException
+     * @throws \InvalidArgumentException if $dir is root-like or invalid
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between df16b89 and 44fde05.

📒 Files selected for processing (1)
  • app/Assets/Helpers.php (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.php: New PHP files must include the project license header and have a single blank line after the opening <?php tag
Use snake_case for PHP variable names
Apply PSR-4 coding standard to PHP code
Always call in_array with true as the third parameter for strict checking (in_array($needle, $haystack, true))
Only use boolean expressions in if statements; avoid integers or strings as conditions
Use strict comparison (===, !==) instead of loose comparison (==, !=)
Avoid duplicating code in both if and else branches
Do not use empty(); prefer explicit checks (e.g., === null, === '', count(...) === 0)

Files:

  • app/Assets/Helpers.php
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: 3️⃣ PHP dist / 8.3 - sqlite
  • GitHub Check: 3️⃣ PHP dist / 8.4 - sqlite
  • GitHub Check: 3️⃣ PHP dist / 8.4 - mariadb
  • GitHub Check: 3️⃣ PHP dist / 8.3 - postgresql
  • GitHub Check: 3️⃣ PHP dist / 8.4 - postgresql
  • GitHub Check: 3️⃣ PHP dist / 8.3 - mariadb
  • GitHub Check: 2️⃣ PHP tests / 8.4 - sqlite -- Unit,Feature_v2
  • GitHub Check: 2️⃣ PHP tests / 8.3 - postgresql -- Unit,Feature_v2
  • GitHub Check: 2️⃣ PHP tests / 8.3 - sqlite -- Unit,Feature_v2
  • GitHub Check: 2️⃣ PHP tests / 8.4 - mariadb -- Unit,Feature_v2
  • GitHub Check: 2️⃣ PHP tests / 8.4 - postgresql -- Unit,Feature_v2
  • GitHub Check: 2️⃣ PHP tests / 8.3 - mariadb -- Unit,Feature_v2
🔇 Additional comments (2)
app/Assets/Helpers.php (2)

14-18: Safe filesystem imports: LGTM

Using Safe\rmdir and Safe\unlink is appropriate here and aligns with explicit exception handling.


285-293: Symlink handling inside the tree: well done

Treating symlinks like files (unlink without following) avoids rmdir() failures and prevents unintended traversal.

@ildyria ildyria merged commit c70bc54 into master Aug 31, 2025
36 checks passed
@ildyria ildyria deleted the fix-clean-up-action branch August 31, 2025 13:07
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.

1 participant