Skip to content

Commit

Permalink
Prevent apps with the same folder name from colliding (#270)
Browse files Browse the repository at this point in the history
before this commit if two symlinks were targeting distinct folders having the same name the app were considered to be the same
  • Loading branch information
hellvinz authored Jan 13, 2021
1 parent 3c14306 commit 566b636
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cmd/puma-dev/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/sha1"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -237,8 +238,12 @@ func runPlatformAgnosticTestScenarios(t *testing.T) {
panic(err)
}

assert.NoError(t, pollForEvent(t, "rack-hi-puma", "killing_app", "restart.txt touched"))
assert.NoError(t, pollForEvent(t, "rack-hi-puma", "shutdown", ""))
appRoot := filepath.Join(ProjectRoot, "etc", "rack-hi-puma")
h := sha1.New()
h.Write([]byte(appRoot))
appName := fmt.Sprintf("rack-hi-puma-%.4x", h.Sum(nil))
assert.NoError(t, pollForEvent(t, appName, "killing_app", "restart.txt touched"))
assert.NoError(t, pollForEvent(t, appName, "shutdown", ""))
})

t.Run("unknown app", func(t *testing.T) {
Expand Down
7 changes: 5 additions & 2 deletions dev/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev
import (
"bufio"
"bytes"
"crypto/sha1"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -514,8 +515,10 @@ func (a *AppPool) App(name string) (*App, error) {
destStat, err := os.Stat(destPath)
if err == nil {
destName := destStat.Name()
if destName != canonicalName {
canonicalName = destName
if destName != name {
h := sha1.New()
h.Write([]byte(destPath))
canonicalName = fmt.Sprintf("%s-%.4x", destStat.Name(), h.Sum(nil))
aliasName = name
}
}
Expand Down

0 comments on commit 566b636

Please sign in to comment.