Skip to content

Conversation

zodiacg
Copy link

@zodiacg zodiacg commented Sep 16, 2025

To fix unnecessary overwrite warning mentioned in #6277

Description

The $currentdir variable in scoop-update.ps1 is not normalized. Under certain settings (e.g. path with a trailing '' in root_path config), it will cause unnecessary warnings about overwriting scoop shims during update.

For example:

  • If the root_path config has a trailing \, the $currentdir variable will carry a double \ when passed to shim function.
  • The warn_on_overwrite checks the shim file and path to compare app names. Due to the double slashes, the get_app_name function will failed to match the correct app name (scoop in this case), and return a ''. Thus causing the warning.

Motivation and Context

Relates to #6277 or #6194.

It fixes my errors but I'm not quite sure about other possible causes.

Anyway, normalizing a path variable should be considered good practice regardless.

How Has This Been Tested?

Checklist:

  • I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

Summary by CodeRabbit

  • Bug Fixes
    • Improved path handling in the update process by using absolute paths, preventing failures caused by relative path resolution.
    • Ensures reliable detection of the current installation and associated repository, regardless of the working directory.
    • Reduces errors in file operations during updates (e.g., checking repository state and related actions).

Copy link

coderabbitai bot commented Sep 16, 2025

Walkthrough

Updated Sync-Scoop in libexec/scoop-update.ps1 to set $currentdir using Convert-Path on versiondir 'scoop' 'current', yielding an absolute path. Subsequent path checks and file operations that depend on $currentdir now resolve against an absolute path. No other logic or public interfaces changed.

Changes

Cohort / File(s) Summary
Path resolution update
libexec/scoop-update.ps1
Replaced $currentdir = versiondir 'scoop' 'current' with $currentdir = Convert-Path (versiondir 'scoop' 'current') to ensure $currentdir is an absolute path for downstream operations (e.g., "$currentdir\.git" checks).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I hopped through paths both near and far,
Turned “current” into where we are—
An absolute warren, tidy and bright,
No more guessing in the moonlit night.
With Convert-Path, the trail is clear,
Update hums—carrots and cheer! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change: normalizing the $currentdir variable in scoop-update to prevent an unnecessary overwrite warning, and it includes the related issue for context; it is a single, focused sentence specific to the affected component and matches the PR objectives and diff.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 0

🧹 Nitpick comments (1)
libexec/scoop-update.ps1 (1)

78-78: Good normalization; add a safe fallback to avoid Convert-Path throws and potential junction deref surprises.

Convert-Path requires the path to exist and may dereference junctions on some setups. A guarded fallback keeps behavior robust if 'apps\scoop\current' is missing/broken and avoids accidentally renaming the resolved target instead of the 'current' link during the non-git → git migration path.

Apply one of the following:

Option A (keep Convert-Path, add fallback)

-    $currentdir = Convert-Path (versiondir 'scoop' 'current')
+    $currentdir = versiondir 'scoop' 'current'
+    try {
+        $currentdir = Convert-Path -Path $currentdir
+    } catch {
+        # Path might not exist or be a broken junction; normalize without requiring existence.
+        $currentdir = [System.IO.Path]::GetFullPath($currentdir)
+    }

Option B (simpler, no existence requirement)

-    $currentdir = Convert-Path (versiondir 'scoop' 'current')
+    $currentdir = [System.IO.Path]::GetFullPath((versiondir 'scoop' 'current'))

Verification checklist (please run on Windows PowerShell 5+):

  • With a trailing backslash in root_path, confirm shim "$currentdir\bin\scoop.ps1" no longer triggers warn_on_overwrite for scoop.
  • When 'current' is a junction to a version dir, ensure Rename-Item behavior matches intent (renames the link, not the target).
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04b7ce7 and 3f100b7.

📒 Files selected for processing (1)
  • libexec/scoop-update.ps1 (1 hunks)

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