summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-21 11:51:52 -0500
committerJeff Carr <[email protected]>2025-10-21 11:51:52 -0500
commit25a911f0f764e35a800eb9423acef964f4c83028 (patch)
tree5b5bb47f813b5b676c010b61ed32b35fb43dcbbf
parentc1600cff482abf314bf66bcf758979969672bfca (diff)
housecleaning
-rw-r--r--backup.go3
-rw-r--r--changed.go2
-rw-r--r--common.go36
-rw-r--r--loadByAppname.go41
-rw-r--r--loadCache.go2
-rw-r--r--loadConfig.go5
6 files changed, 41 insertions, 48 deletions
diff --git a/backup.go b/backup.go
index de87880..6d50a18 100644
--- a/backup.go
+++ b/backup.go
@@ -1,8 +1,5 @@
package config
-// thank chatgpt for this because why. why write this if you can have it
-// kick this out in 30 seconds
-
/*
func (f *Forge) backupConfig() error {
// make a new dir to backup the files
diff --git a/changed.go b/changed.go
index c5ede96..67b6ffb 100644
--- a/changed.go
+++ b/changed.go
@@ -7,7 +7,7 @@ import (
"sync"
)
-// this package can provide a trivial way to track which
+// this provides a trivial way to track which
// protobufs have been modified and need to be written to disk
// todo: autogenpb could generate code to work with this
diff --git a/common.go b/common.go
new file mode 100644
index 0000000..d9ef0ce
--- /dev/null
+++ b/common.go
@@ -0,0 +1,36 @@
+package config
+
+import (
+ "os"
+ "runtime"
+ "strings"
+ "sync"
+)
+
+// todo: move these somewhere else
+
+// a simple function name shortcut
+func Exists(filename string) bool {
+ _, err := os.Stat(Path(filename))
+ if os.IsNotExist(err) {
+ return false
+ }
+ return true
+}
+
+// simple function name shortcut
+func IsDir(dirname string) bool {
+ info, err := os.Stat(Path(dirname))
+ if os.IsNotExist(err) {
+ return false
+ }
+ return info.IsDir()
+}
+
+// notsure if this is a thing anymore. don't care much either
+func Path(filename string) string {
+ if runtime.GOOS == "windows" {
+ filename = strings.Replace(filename, "/", "\\", -1)
+ }
+ return filename
+}
diff --git a/loadByAppname.go b/loadByAppname.go
index 28f7fee..42a44a9 100644
--- a/loadByAppname.go
+++ b/loadByAppname.go
@@ -23,7 +23,7 @@ func LoadAppnameCache(pb proto.Message, appname string) error {
return err
}
if curfilename == "" {
- log.Printf("ConfigLoad() reading in %s\n", fullname)
+ // log.Printf("ConfigLoad() read in %s\n", fullname)
}
err = loadPB(pb, fullname)
@@ -43,42 +43,3 @@ func LoadAppnameCache(pb proto.Message, appname string) error {
}
return nil
}
-
-/*
-// deprecate
-func LoadByAppname(pb proto.Message, appname string) error {
- protoname, err := GetProtobufName(pb) // defined in the foo.proto file
- if err != nil {
- return err
- }
-
- // Get ~/.cache/appname/protoname.text
- fullname := makeCacheFilename(appname, protoname)
-
- // get the current filename in the protobuf file
- curfilename, err := GetFilename(pb)
- if err != nil {
- return err
- }
- if curfilename == "" {
- log.Printf("ConfigLoad() reading in %s\n", fullname)
- }
-
- err = loadPB(pb, fullname)
- if err != nil {
- return ErrMarshal
- }
-
- // If the cache file is new or has moved, this updates it to correct filename
- // (the filename is what is used by pb.Save()
- if curfilename != fullname {
- _, err := SetFilename(pb, fullname)
- if err != nil {
- log.Info("FILENAME COULD NOT BE SET old=", curfilename)
- log.Info("FILENAME COULD NOT BE SET new=", fullname)
- return errors.Join(err, errors.New("something is wrong in lib/config"))
- }
- }
- return nil
-}
-*/
diff --git a/loadCache.go b/loadCache.go
index c45c6d7..2c8b9a9 100644
--- a/loadCache.go
+++ b/loadCache.go
@@ -34,7 +34,7 @@ func CacheLoad(pb proto.Message) error {
return err
}
if curfilename == "" {
- log.Printf("ConfigLoad() reading in %s\n", fullname)
+ // log.Printf("ConfigLoad() read in %s\n", fullname)
}
err = loadPB(pb, fullname)
diff --git a/loadConfig.go b/loadConfig.go
index 43b40e1..8c7cee8 100644
--- a/loadConfig.go
+++ b/loadConfig.go
@@ -84,8 +84,7 @@ func ConfigLoadByName(pb proto.Message, customName string) (string, error) {
// return fullname, err
}
if curfilename == "" {
- // reading in new file
- // log.Printf("ConfigLoadByName() reading in %s\n", fullname)
+ // log.Printf("ConfigLoadByName() read in %s\n", fullname)
}
if err = loadTEXT(pb, fullname); err == nil {
@@ -142,7 +141,7 @@ func LoadByAppName(pb proto.Message, customName string, appName string) (string,
// return fullname, err
}
if curfilename == "" {
- log.Printf("ConfigLoadByName() reading in %s\n", fullname)
+ // log.Printf("ConfigLoadByName() read in %s\n", fullname)
}
if err = loadTEXT(pb, fullname); err == nil {