[Fix]: Ignore hidden files during Astro IDE project export#1946
[Fix]: Ignore hidden files during Astro IDE project export#1946
Conversation
cloud/ide/project.go
Outdated
| return nil | ||
| } | ||
|
|
||
| // Skip all hidden dotfiles and dot-directories, except allow the root ".astro" file |
There was a problem hiding this comment.
.astro is a dir rather than a file. Astro projects also include .gitignore and .dockerignore which we shouldn't be dropping.
Maybe we could do this a different way. The default Astro project .gitignore file excludes .git, .venv, and other files we shouldn't include, so perhaps we could use the go-git package to figure out which paths are allowed by .gitignore and only include those? (I've done something similar for an internal component of Astro IDE)
Pull Request Test Coverage Report for Build 4f7399df-91ef-4c62-b46a-22beea9a00baDetails
💛 - Coveralls |
cloud/ide/project.go
Outdated
| // gitignoreMatcher creates a matcher from .gitignore patterns in the given root. | ||
| func gitignoreMatcher(root string) gitignore.Matcher { | ||
| fs := osfs.New(root) | ||
| patterns, _ := gitignore.ReadPatterns(fs, []string{}) |
There was a problem hiding this comment.
We shouldn't ignore the error. If it returns one can we print a warning that it couldn't be parsed (including the error we're given) and continue without doing the gitignore filtering?
cloud/ide/project.go
Outdated
| } | ||
|
|
||
| // decideArchiveEntry determines whether to include a path, skip it, or skip its subtree. | ||
| func decideArchiveEntry(relPath string, info os.FileInfo, matcher gitignore.Matcher) (skipEntry, skipDir bool) { |
There was a problem hiding this comment.
Can we name it shouldSkipArchiveEntry and return a single bool? The caller can use info.IsDir() to determine whether to return nil or SkipDir
| @@ -351,6 +355,8 @@ func ExportProject(client astrocore.CoreClient, projectID, organizationID, works | |||
|
|
|||
| // createTarGzArchive creates a tar.gz archive of the given directory | |||
| func createTarGzArchive(sourceDir, targetFile string) error { | |||
There was a problem hiding this comment.
We should add unit tests for this and the extract function, which covers the existing archive activity and the new gitignore skipping.
Description
This PR changes update Astro IDE export command to ignore hidden files i.e. (.)files to prevent exporting local virtual environment, .git files and other unwanted files to Astro IDE.
🎟 Issue(s)
Related #XXX
🧪 Functional Testing
Tested the change locally:
📸 Screenshots
📋 Checklist
make testbefore taking out of draftmake lintbefore taking out of draft