Skip to content

Conversation

GLobyNew
Copy link
Contributor

@GLobyNew GLobyNew commented Mar 6, 2025

This should fix #3075
Not an elegant solution, but all tests are passed and works as expected

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @GLobyNew, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses issue #3075, allowing the use of a trailing slash in cp and mv commands. The changes modify the directMove functions in internal/store/leaf/move.go and internal/store/root/move.go to handle trailing slashes in the destination path. Specifically, if the destination path ends with a slash, the code now appends the base name of the source file to the destination path, effectively creating a new directory and moving/copying the source file into it. Additionally, the store prefix removal logic in internal/store/root/move.go was adjusted to avoid removing the prefix from the destination path, as it might represent a new folder.

Highlights

  • Bug Fix: Fixes issue #3075, enabling the use of trailing slashes with cp and mv commands.
  • Trailing Slash Handling: Implements logic to interpret a trailing slash in the destination path as a request to create a new directory and move/copy the source file into it.
  • Store Prefix Handling: Adjusts store prefix removal logic in internal/store/root/move.go to correctly handle destination paths that may represent new folders.

Changelog

  • internal/store/leaf/move.go
    • Added a check for a trailing slash in the destination path (to).
    • If a trailing slash is present, the base name of the source file is appended to the destination path.
    • This ensures that the file is moved/copied into a new directory with the same name.
  • internal/store/root/move.go
    • Modified the directMove function to handle trailing slashes in the destination path.
    • The store prefix is no longer removed from the destination path (to) to allow for creating new folders.
    • Adjusted the getStore call to only remove the store prefix from the source path (from).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A trailing slash, a simple sign,
To move a file, a new design.
In gopass code, the fix takes hold,
A folder made, a story told.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a fix to allow the use of a trailing slash for the cp and mv commands. This change modifies the directMove functions in both the leaf and root store implementations to handle destinations with trailing slashes, treating them as requests to create a new folder and move/copy the source file into it. The changes also adjust how the destination path is handled in the root store to accommodate this new behavior. Overall, the changes seem reasonable, but there are a few areas that could be improved for clarity and robustness.

Summary of Findings

  • Inconsistent destination path handling: The root store's directMove function modifies how the destination path is processed, potentially leading to inconsistencies in how paths are handled across different store types. This could introduce unexpected behavior or bugs in other parts of the application.
  • Lack of input validation: The code does not explicitly validate the destination path to ensure it's a valid directory name. This could lead to issues if the destination contains invalid characters or is otherwise malformed.
  • Potential for directory creation failure: The code assumes that the destination directory will be created successfully. However, there is no explicit error handling for the case where directory creation fails, which could lead to unexpected behavior or data loss.

Merge Readiness

The pull request addresses a specific issue and includes passing tests, suggesting it resolves the reported problem. However, the potential inconsistencies in destination path handling and the lack of explicit error handling for directory creation failures raise concerns. I recommend addressing these issues before merging. I am unable to approve this pull request, and users should have others review and approve this code before merging.

@GLobyNew
Copy link
Contributor Author

GLobyNew commented Mar 6, 2025

Holy, this gemini is annoying.

Copy link

I understand your frustration, GLobyNew. Is there something specific about my feedback that you find annoying? Knowing what's bothering you will help me improve and provide more useful reviews in the future.

Signed-off-by: Ilya Eryomenko <ilya@eryomenko.com>
@GLobyNew
Copy link
Contributor Author

GLobyNew commented Mar 6, 2025

Forced-pushed a few new conditions, to make sure everything works fine even if folder/file already exist

@GLobyNew
Copy link
Contributor Author

Is something wrong with pull request?
If so, please don't hesitate to @ me, I will try my best to make things work in a way you see :)

@dominikschulz
Copy link
Member

@GLobyNew sorry, I couldn't get around to do a proper review, yet. Some PRs look trivial but others I want to try myself first and I don't always have the setup to do that.

You should get proper feedback in a few days at most.

@dominikschulz
Copy link
Member

This doesn't seem to break anything, but I wonder if it has the intended effects. Please help me understand your intentions @GLobyNew .

I did try to reproduce the issue and the fix and don't see any difference between moving with or without a trailing slash. Also I couldn't spot the difference between head and this PR.

@GLobyNew
Copy link
Contributor Author

@dominikschulz That's really strange.

Have you tried it in REPL mode?
It works absolutely fine in zsh/bash, but not in REPL.

For me issue is still persist in current HEAD/master branch. Take a loot of this:

gopass> ls
gopass
├── entry1
└── entry2

gopass> mv entry1 folder1/folder2/
gopass> ls
gopass
├── entry2
└── folder1/
    └── folder2

I had entry1 and entry2. But when I tried to mv entry1 to non-existent folder2 it just moves it to folder1 and renames entry1 to folder2.
Which is not intuitive, because user has added a trailing slash to make sure, that last element in path should be folder, and the entry should be placed in that folder.

Now lets try my PR:

gopass> ls
gopass
├── entry1
└── entry2

gopass> mv entry1 folder1/folder2/
gopass> ls
gopass
├── entry2
└── folder1/
    └── folder2/
        └── entry1

Now it moves entry1 to desired folder2.

Basically my code only changes 2 things:

  1. In internal/store/root/move.go it doesn't change the original to variable. Because we must check if the to path has trailing slash or not in leaf/move.go file
  2. In internal/store/leaf/move.go it now has check for trailing slash, and if it has it then we change path, to make sure that last folder will be created.
    And also there is basic check on existence of destination entry/folder.

I hope this clears things out.
Thank you for fast reply!

Copy link
Member

@dominikschulz dominikschulz left a comment

Choose a reason for hiding this comment

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

Thanks a lot. I was missing two key pieces: (a) that it old affects REPL and (b) that we were trying to move to a non-existing folder.

@dominikschulz dominikschulz merged commit 9a5ae11 into gopasspw:master Mar 12, 2025
8 checks passed
@GLobyNew GLobyNew deleted the trailingSlashDir branch March 13, 2025 04:49
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.

gopass mv foo bar/ ignores the trailing slash if bar directory doesn't exist yet
2 participants