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

Turn off following symlinks #2195

Open
kmkacpermajor opened this issue Jul 26, 2024 Discussed in #2194 · 3 comments
Open

Turn off following symlinks #2195

kmkacpermajor opened this issue Jul 26, 2024 Discussed in #2194 · 3 comments

Comments

@kmkacpermajor
Copy link

Discussed in #2194

Originally posted by kmkacpermajor July 25, 2024
Hi,
Is it possible to turn off following symlinks in gomplate.config?

I have all files excluded except for !*.tmpl, and it still tries to follow symlinks (even though their names don't end with .tmpl).
Because files that symlinks should follow don't exist on my computer, gomplate ends with an error "failed to gather templates for rendering: walkDir: ignore matching failed for ../..: applyPatterns: stat: stat testSymlink: no such file or directory".

I can't seem to find an option to turn off following symlinks in gomplate.

If there would be a config option to change os.Stat() to os.Lstat(), it would be great.
It would read the information off of symlink, and then for my usage it would just be excluded.

@hairyhenderson
Copy link
Owner

@kmkacpermajor thanks for filing this - can you provide some more concrete details? what exactly does your configuration and/or gomplate commandline look like?

@kmkacpermajor
Copy link
Author

kmkacpermajor commented Jul 26, 2024

Sure,
To recreate this:

  • touch test_file
  • ln -s test_file test_link
  • rm test_file
  • create gomplate.config (below)
  • gomplate --config gomplate.config

Error: failed to gather templates for rendering: walkDir: ignore matching failed for.: applyPatterns: stat: stat test_link: no such file or directory.

gomplate.config

excludes:
  - '*'
  - '!*.tmpl'

inputDir: .

outputMap:  |
  {{ .in | strings.ReplaceAll ".tmpl" "" }}

I'm on Ubuntu 22.04.1 LTS on WSL2, gomplate v4.1.0

@kmkacpermajor
Copy link
Author

I can see that it is a problem with xignore library.

I think that if we operate only on files instead of links, then if the file doesn't exist it would be okay to mark it as unmatched.
Problem is that it uses fs.Stat to check if current "file" is a file or a directory (in applyPatterns and makeResult).

Workaround would be to just ignore (continue in for) non existing files. They won't appear neither in matchedFiles or unmatchedFiles, so that is probably not a great fix...
It would be great to just use os.Lstat since we only check if it is a dir. It returns FileInfo just like fs.Stat.
But I'm not a GO developer, so I don't really know if it would hurt compatibilty-wise or something...

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

No branches or pull requests

2 participants