force file mode on write (and update deps)
This commit is contained in:
@ -66,7 +66,8 @@ func Files(cfg *config.Config, filters ...string) (err error) {
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
log.Print("failed to write file ", file.Path, ": ", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,5 +86,9 @@ func writeFile(path string, content []byte, fileMode, dirMode os.FileMode, cfg *
|
||||
err = fmt.Errorf("failed to write %s: %v", path, err)
|
||||
}
|
||||
|
||||
if chmodErr := os.Chmod(path, fileMode); chmodErr != nil {
|
||||
log.Print("- failed chmod: ", chmodErr)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
40
pkg/cmd/files/files.go
Normal file
40
pkg/cmd/files/files.go
Normal file
@ -0,0 +1,40 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
pconfig "novit.nc/direktil/pkg/config"
|
||||
)
|
||||
|
||||
var (
|
||||
configPath string
|
||||
config *pconfig.Config
|
||||
)
|
||||
|
||||
func Command() (cmd *cobra.Command) {
|
||||
cmd = &cobra.Command{
|
||||
Use: "files",
|
||||
Args: cobra.NoArgs,
|
||||
|
||||
PersistentPreRun: loadConfig,
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().StringVar(&configPath, "config", "/boot/config.yaml", "path to the boot config")
|
||||
|
||||
cmd.AddCommand(
|
||||
listCommand(),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func loadConfig(_ *cobra.Command, _ []string) {
|
||||
c, err := pconfig.Load(configPath)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("failed to load config: ", err)
|
||||
}
|
||||
|
||||
config = c
|
||||
}
|
47
pkg/cmd/files/list.go
Normal file
47
pkg/cmd/files/list.go
Normal file
@ -0,0 +1,47 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
pconfig "novit.nc/direktil/pkg/config"
|
||||
)
|
||||
|
||||
func listCommand() (cmd *cobra.Command) {
|
||||
return &cobra.Command{
|
||||
Use: "list",
|
||||
Run: list,
|
||||
}
|
||||
}
|
||||
|
||||
func list(_ *cobra.Command, args []string) {
|
||||
for _, file := range filteredFiles(args) {
|
||||
fmt.Println(file.Path)
|
||||
}
|
||||
}
|
||||
|
||||
func filteredFiles(filters []string) (ret []pconfig.FileDef) {
|
||||
ret = make([]pconfig.FileDef, 0, len(config.Files))
|
||||
|
||||
for _, file := range config.Files {
|
||||
if len(filters) != 0 {
|
||||
match := false
|
||||
for _, filter := range filters {
|
||||
if ok, _ := filepath.Match(filter, file.Path); ok {
|
||||
match = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !match {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
ret = append(ret, file)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -10,7 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
ping "github.com/sparrc/go-ping"
|
||||
"github.com/go-ping/ping"
|
||||
"novit.nc/direktil/pkg/config"
|
||||
|
||||
"novit.nc/direktil/inits/pkg/sys"
|
||||
|
Reference in New Issue
Block a user