Skip to content

Commit

Permalink
fix .resource_types folder and content purge skip (#198)
Browse files Browse the repository at this point in the history
* fix .resource_types folder and content purge skip

* remove .resource_types from purge_allowlist as it should be allowed by default

* add correct test of implicit .resource_types purge prevention
  • Loading branch information
xorpaul authored May 25, 2022
1 parent 97696e0 commit 5a7d7dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion g10k_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,11 @@ func TestPurgeStaleContent(t *testing.T) {
defer f.Close()
f.WriteString("foobar")
f.Sync()
createOrPurgeDir("/tmp/example/single/.resource_types", funcName)
r, _ := os.Create("/tmp/example/single/.resource_types/test.pp")
defer r.Close()
r.WriteString("foobar")
r.Sync()

cmd := exec.Command(os.Args[0], "-test.run="+funcName+"$")
cmd.Env = append(os.Environ(), "TEST_FOR_CRASH_"+funcName+"=1")
Expand All @@ -2231,7 +2236,7 @@ func TestPurgeStaleContent(t *testing.T) {
if expectedExitCode != exitCode {
t.Errorf("terminated with %v, but we expected exit status %v", exitCode, expectedExitCode)
}
//fmt.Println(string(out))
// fmt.Println(string(out))

expectedLines := []string{
"DEBUG checkForStaleContent(): filepath.Walk'ing directory /tmp/example/single",
Expand Down Expand Up @@ -2259,6 +2264,10 @@ func TestPurgeStaleContent(t *testing.T) {
t.Errorf("Missing module file that should be there")
}

if !fileExists("/tmp/example/single/.resource_types/test.pp") {
t.Errorf("Missing resource_types file /tmp/example/single/.resource_types/test.pp that should be there")
}

purgeDir(cacheDir, funcName)
purgeDir("/tmp/example", funcName)
}
Expand Down
4 changes: 2 additions & 2 deletions stale.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func checkForStaleContent(workDir string) {
}

checkForStaleContent := func(path string, info os.FileInfo, err error) error {
//Debugf("filepath.Walk'ing found path: " + path)
stale := true
if strings.HasSuffix(path, ".resource_types") && isDir(path) {
// never purge .resource_types dir and its content
if strings.HasSuffix(path, ".resource_types") || strings.HasSuffix(filepath.Dir(path), ".resource_types") {
stale = false
} else {
for _, desiredFile := range desiredContent {
Expand Down
2 changes: 1 addition & 1 deletion tests/TestConfigExamplePurgeEnvironment.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
:cachedir: '/tmp/g10k'
purge_levels: ['environment']
purge_allowlist: [ '.latest_revision', '.resource_types', '.resource_types/*.pp' ]
purge_allowlist: [ '.latest_revision' ]

sources:
example:
Expand Down

0 comments on commit 5a7d7dd

Please sign in to comment.