2021-02-09 20:17:06 +01:00
|
|
|
package pngstructure
|
|
|
|
|
|
|
|
import (
|
2021-02-10 01:00:02 +01:00
|
|
|
"os"
|
|
|
|
"path"
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
"github.com/dsoprea/go-logging"
|
2021-02-09 20:17:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-02-10 01:00:02 +01:00
|
|
|
assetsPath = ""
|
2021-02-09 20:17:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func getModuleRootPath() string {
|
2021-02-10 01:00:02 +01:00
|
|
|
moduleRootPath := os.Getenv("PNG_MODULE_ROOT_PATH")
|
|
|
|
if moduleRootPath != "" {
|
|
|
|
return moduleRootPath
|
|
|
|
}
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
currentWd, err := os.Getwd()
|
|
|
|
log.PanicIf(err)
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
currentPath := currentWd
|
|
|
|
visited := make([]string, 0)
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
for {
|
|
|
|
tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
_, err := os.Stat(tryStampFilepath)
|
|
|
|
if err != nil && os.IsNotExist(err) != true {
|
|
|
|
log.Panic(err)
|
|
|
|
} else if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
visited = append(visited, tryStampFilepath)
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
currentPath = path.Dir(currentPath)
|
|
|
|
if currentPath == "/" {
|
|
|
|
log.Panicf("could not find module-root: %v", visited)
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
return currentPath
|
2021-02-09 20:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func getTestAssetsPath() string {
|
2021-02-10 01:00:02 +01:00
|
|
|
if assetsPath == "" {
|
|
|
|
moduleRootPath := getModuleRootPath()
|
|
|
|
assetsPath = path.Join(moduleRootPath, "assets")
|
|
|
|
}
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
return assetsPath
|
2021-02-09 20:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func getTestBasicImageFilepath() string {
|
2021-02-10 01:00:02 +01:00
|
|
|
assetsPath := getTestAssetsPath()
|
|
|
|
return path.Join(assetsPath, "libpng.png")
|
2021-02-09 20:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func getTestExifImageFilepath() string {
|
2021-02-10 01:00:02 +01:00
|
|
|
assetsPath := getTestAssetsPath()
|
|
|
|
return path.Join(assetsPath, "exif.png")
|
2021-02-09 20:17:06 +01:00
|
|
|
}
|