Skip to content

check type of snaggled file & copy to /bin or /lib64 accordingly#61

Merged
MusicalNinjaDad merged 3 commits into
mainfrom
lib_target
Oct 27, 2025
Merged

check type of snaggled file & copy to /bin or /lib64 accordingly#61
MusicalNinjaDad merged 3 commits into
mainfrom
lib_target

Conversation

@MusicalNinjaDad

@MusicalNinjaDad MusicalNinjaDad commented Oct 27, 2025

Copy link
Copy Markdown
Owner

Closes #56

Summary by Sourcery

Detect file type to link executables into /bin and libraries into /lib64, introduce a dedicated AssertLinkedFile helper, and update tests and ExpectedOutput accordingly

New Features:

  • Add AssertLinkedFile helper for verifying hard links
  • Route executables to /bin and libraries to /lib64 in ExpectedOutput
  • Update Snaggle to link files based on file type to the appropriate directory

Enhancements:

  • Remove mustBeLink flag from AssertSameFile and split link assertion into a dedicated function

Tests:

  • Refactor tests to use AssertLinkedFile and AssertSameFile without a boolean parameter
  • Adjust testdata to expect executables in bin and libraries in lib64

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2025

Copy link
Copy Markdown

Reviewer's Guide

Refactors internal assertion helpers, updates test data to dynamically route executables to /bin and libraries to /lib64, modifies Snaggle to branch linking based on file type, and adjusts tests to use the new assertions.

Entity relationship diagram for dynamic routing of executables and libraries in testdata.go

erDiagram
    ELF {
        string Name
        string Path
        string Interpreter
        string[] Dependencies
    }
    binaryDetails {
        ELF Elf
        bool Exe
        bool HasInterpreter
    }
    ELF ||--o{ binaryDetails : contains
    binaryDetails ||--o{ files : generates
    files {
        string key
        string value
    }
Loading

Class diagram for updated assertion helpers in comparisons.go

classDiagram
    class AssertSameFile {
        +AssertSameFile(t *testing.T, path1 string, path2 string)
    }
    class AssertLinkedFile {
        +AssertLinkedFile(t *testing.T, path1 string, path2 string)
    }
    AssertSameFile --> sameFile
    AssertLinkedFile --> sameInode
Loading

Flow diagram for Snaggle file linking based on file type

flowchart TD
    A["Snaggle(path, root)"] --> B["Check if file.IsExe()"]
    B -- Yes --> C["link(path, binDir)"]
    B -- No --> D["link(path, libDir)"]
    C --> E["If file.Interpreter != ''"]
    D --> E
    E -- Yes --> F["link(file.Interpreter, libDir)"]
Loading

File-Level Changes

Change Details Files
Refactor file assertion helpers
  • Removed mustBeLink parameter from AssertSameFile
  • Unified error handling and assertions in AssertSameFile
  • Introduced AssertLinkedFile for inode-based checks
internal/comparisons.go
Dynamic path selection in ExpectedOutput
  • Defined binBasePath and libBasePath variables
  • Conditionally set elfPath based on tc.Exe flag
  • Updated stdout messages and files map to use dynamic paths
internal/testing/testdata.go
Update tests for new assertion API
  • Moved Assert := assert.New(t) into each subtest
  • Replaced AssertSameFile(..., true) with AssertLinkedFile
  • Removed mustBeLink arguments from AssertSameFile calls
snaggle_test.go
snaggle/cli_test.go
Branch linking logic in Snaggle
  • Added conditional to call link(path, binDir) or link(path, libDir)
  • Used file.IsExe() to determine target directory
snaggle.go
Minor refinements in elf tests
  • Reorganized Assert.New(t) placement and variable declarations
  • Added and adjusted assertions for parsed metadata (Name, Path, IsExe, IsLib)
elf/elf_errors_test.go
elf/elf_test.go

Assessment against linked issues

Issue Objective Addressed Explanation
#56 Check the type of the snaggled file (executable or library) before copying.
#56 Copy the snaggled file to /bin if it is an executable, or to /lib64 if it is a library.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider extracting the common error-checking and assertion logic from AssertSameFile and AssertLinkedFile into a shared helper to reduce duplication.
  • In ExpectedOutput, the repeated construction of binBasePath and libBasePath could be factored into a small helper to make the code more declarative and avoid repetition.
  • In Snaggle, you could compute targetDir based on file.IsExe() once and then invoke link in a single linkerrs.Go call, rather than branching around separate calls for cleaner control flow.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the common error-checking and assertion logic from AssertSameFile and AssertLinkedFile into a shared helper to reduce duplication.
- In ExpectedOutput, the repeated construction of binBasePath and libBasePath could be factored into a small helper to make the code more declarative and avoid repetition.
- In Snaggle, you could compute targetDir based on file.IsExe() once and then invoke link in a single linkerrs.Go call, rather than branching around separate calls for cleaner control flow.

## Individual Comments

### Comment 1
<location> `snaggle.go:158-161` </location>
<code_context>
 	linkerrs := new(errgroup.Group)

-	linkerrs.Go(func() error { return link(path, binDir) })
+	if file.IsExe() {
+		linkerrs.Go(func() error { return link(path, binDir) })
+	} else {
+		linkerrs.Go(func() error { return link(path, libDir) })
+	}
 	// TODO: #50 make linking interpreter safer
</code_context>

<issue_to_address>
**suggestion:** The branching for linking could be refactored for maintainability.

Assign the target directory based on file type, then call linkerrs.Go once. This streamlines the code and simplifies future updates.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov

codecov Bot commented Oct 27, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.35%. Comparing base (afefb6c) to head (00adb41).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
+ Coverage   73.86%   74.35%   +0.49%     
==========================================
  Files           8        8              
  Lines         417      425       +8     
==========================================
+ Hits          308      316       +8     
  Misses         77       77              
  Partials       32       32              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MusicalNinjaDad MusicalNinjaDad merged commit 853728b into main Oct 27, 2025
12 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the lib_target branch October 27, 2025 12:16
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.

check type of snaggled file & copy to /bin or /lib64 accordingly

1 participant