Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem with ListFiles producing an unwanted Newline character when zero files are matched #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MrTbag
Copy link

@MrTbag MrTbag commented Jul 13, 2023

In this PR I tried to fix #110

Here I take into consideration whether any files are matched at all or not and then ListFiles() only produces an output if files are matched.

To fix the issue with the ListFiles function, you would need to handle the case where the provided path argument refers to a single file instead of a directory. Currently, the function assumes that if an error occurs while reading the directory, it's because the path matches exactly one file. However, this assumption is incorrect in some cases.

In the updated code:

  • We use os.Stat to check whether the path argument refers to a directory or a file.
  • If it's a file, we return it as the output by creating a new Pipe and using Echo to set its content to the file path.
  • If it's a directory, we proceed with the original logic of walking through the directory and appending file paths to the matches slice.

By making these changes, the ListFiles function will correctly handle both directory and file inputs.

#web_1402_issue

@bitfield
Copy link
Owner

Hi, @MrTbag! Thanks for the contribution—it's most welcome!

I'm not sure if I'm completely clear on the problem that this is fixing—could you help me out by supplying a couple of test cases that fail without this change?

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.

ListFiles() Produces an Unwanted Newline Character When Zero Files Are Matched
2 participants