Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions appcontext/appcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ func (ctx *AppContext) ImporterOpts() *importer.Options {
Architecture: ctx.Architecture,
CWD: ctx.CWD,
MaxConcurrency: ctx.MaxConcurrency,
Stdin: ctx.Stdin,
Stdout: ctx.Stdout,
Stderr: ctx.Stderr,
}
}

Expand Down
32 changes: 16 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ func entryPoint() int {

if opt_disableSecurityCheck {
ctx.GetCookies().SetDisabledSecurityCheck()
fmt.Fprintln(ctx.Stdout, "security check disabled !")
fmt.Println("security check disabled !")
return 1
} else {
opt_disableSecurityCheck = ctx.GetCookies().IsDisabledSecurityCheck()
}

if opt_enableSecurityCheck {
ctx.GetCookies().RemoveDisabledSecurityCheck()
fmt.Fprintln(ctx.Stdout, "security check enabled !")
fmt.Println("security check enabled !")
return 1
}

Expand Down Expand Up @@ -486,20 +486,20 @@ func checkUpdate(ctx *appcontext.AppContext, disableSecurityCheck bool) {
return
}

fmt.Fprintln(ctx.Stdout, "Welcome to plakar !")
fmt.Fprintln(ctx.Stdout, "")
fmt.Fprintln(ctx.Stdout, "By default, plakar checks for security updates on the releases feed once every 24h.")
fmt.Fprintln(ctx.Stdout, "It will notify you if there are important updates that you need to install.")
fmt.Fprintln(ctx.Stdout, "")
fmt.Fprintln(ctx.Stdout, "If you prefer to watch yourself, you can disable this permanently by running:")
fmt.Fprintln(ctx.Stdout, "")
fmt.Fprintln(ctx.Stdout, "\tplakar -disable-security-check")
fmt.Fprintln(ctx.Stdout, "")
fmt.Fprintln(ctx.Stdout, "If you change your mind, run:")
fmt.Fprintln(ctx.Stdout, "")
fmt.Fprintln(ctx.Stdout, "\tplakar -enable-security-check")
fmt.Fprintln(ctx.Stdout, "")
fmt.Fprintln(ctx.Stdout, "EOT")
fmt.Println("Welcome to plakar !")
fmt.Println("")
fmt.Println("By default, plakar checks for security updates on the releases feed once every 24h.")
fmt.Println("It will notify you if there are important updates that you need to install.")
fmt.Println("")
fmt.Println("If you prefer to watch yourself, you can disable this permanently by running:")
fmt.Println("")
fmt.Println("\tplakar -disable-security-check")
fmt.Println("")
fmt.Println("If you change your mind, run:")
fmt.Println("")
fmt.Println("\tplakar -enable-security-check")
fmt.Println("")
fmt.Println("EOT")
return
}

Expand Down
4 changes: 2 additions & 2 deletions subcommands/agent/cached.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (cmd *Cached) handleCachedClient(ctx *appcontext.AppContext, conn net.Conn)
return
}
ctx.GetLogger().Warn("Failed to decode RPC: %v", err)
fmt.Fprintf(clientContext.Stderr, "%s\n", err)
//fmt.Fprintf(clientContext.Stderr, "%s\n", err)
return
}

Expand All @@ -296,7 +296,7 @@ func (cmd *Cached) handleCachedClient(ctx *appcontext.AppContext, conn net.Conn)
subcommand := &cached.CachedReq{}
if err := msgpack.Unmarshal(request, subcommand); err != nil {
ctx.GetLogger().Warn("Failed to decode client request: %v", err)
fmt.Fprintf(clientContext.Stderr, "Failed to decode client request: %s\n", err)
//fmt.Fprintf(clientContext.Stderr, "Failed to decode client request: %s\n", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion subcommands/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (cmd *Archive) Execute(ctx *appcontext.AppContext, repo *repository.Reposit

var out io.Writer
if cmd.Output == "-" {
out = ctx.Stdout
out = os.Stdout
} else {
tmp, err := os.CreateTemp("", "plakar-archive-")
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions subcommands/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ func executeHook(ctx *appcontext.AppContext, hook string) error {
cmd = exec.Command("/bin/sh", "-c", hook)
}

cmd.Stdout = ctx.Stdout
cmd.Stderr = ctx.Stderr
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

Expand Down Expand Up @@ -436,10 +436,10 @@ func dryrun(ctx *appcontext.AppContext, imp importer.Importer, excludePatterns [
switch {
case record.Error != nil:
errors = true
fmt.Fprintf(ctx.Stderr, "%s: %s\n",
fmt.Fprintf(os.Stderr, "%s: %s\n",
record.Error.Pathname, record.Error.Err)
case record.Record != nil:
fmt.Fprintln(ctx.Stdout, record.Record.Pathname)
fmt.Println(record.Record.Pathname)
record.Record.Close()
}
}
Expand Down
5 changes: 3 additions & 2 deletions subcommands/cat/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"flag"
"fmt"
"io"
"os"

"github.com/PlakarKorp/kloset/locate"
"github.com/PlakarKorp/kloset/repository"
Expand Down Expand Up @@ -153,7 +154,7 @@ func (cmd *Cat) Execute(ctx *appcontext.AppContext, repo *repository.Repository)
break
}

errFormat := formatter.Format(ctx.Stdout, style, iterator)
errFormat := formatter.Format(os.Stdout, style, iterator)
if errFormat != nil {
ctx.GetLogger().Error("cat: %s: %s", pathname, errFormat)
errors++
Expand All @@ -173,7 +174,7 @@ func (cmd *Cat) Execute(ctx *appcontext.AppContext, repo *repository.Repository)
}
}
} else {
_, err = io.Copy(ctx.Stdout, rd)
_, err = io.Copy(os.Stdout, rd)
}
file.Close()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion subcommands/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/hex"
"flag"
"fmt"
"os"

"github.com/PlakarKorp/kloset/locate"
"github.com/PlakarKorp/kloset/repository"
Expand Down Expand Up @@ -90,7 +91,7 @@ func (cmd *Check) Execute(ctx *appcontext.AppContext, repo *repository.Repositor
cmd.LocateOptions.Filters.IDs = []string{prefix}
snapshotIDs, err := locate.LocateSnapshotIDs(repo, cmd.LocateOptions)
if err != nil {
fmt.Fprintln(ctx.Stderr, err)
fmt.Fprintln(os.Stderr, err)
return 1, err
}

Expand Down
32 changes: 16 additions & 16 deletions subcommands/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
case "add":
p := flag.NewFlagSet("add", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name> <location> [<key>=<value>...]\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name> <location> [<key>=<value>...]\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand Down Expand Up @@ -115,7 +115,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
case "check":
p := flag.NewFlagSet("check", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name>\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name>\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand Down Expand Up @@ -170,12 +170,12 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
flags.StringVar(&opt_config, "config", "", "import from a file")
flags.BoolVar(&opt_overwrite, "overwrite", false, "overwrite existing configurations")
flags.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s [OPTIONS] <section>...\n", cmd, flags.Name())
fmt.Printf("Usage: plakar %s %s [OPTIONS] <section>...\n", cmd, flags.Name())
flags.PrintDefaults()
}
flags.Parse(args)

var rd io.Reader = ctx.Stdin
var rd io.Reader = os.Stdin
if opt_config != "" {
if strings.HasPrefix(opt_config, "http://") || strings.HasPrefix(opt_config, "https://") {
resp, err := http.Get(opt_config)
Expand Down Expand Up @@ -210,7 +210,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
if flags.NArg() == 0 {
for name, section := range newConfMap {
if hasFunc(name) && !opt_overwrite {
fmt.Fprintf(ctx.Stderr, "%s %q already exists, skipping\n", cmd, name)
fmt.Fprintf(os.Stderr, "%s %q already exists, skipping\n", cmd, name)
continue
}
cfgMap[name] = make(map[string]string)
Expand All @@ -223,16 +223,16 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
targetName = normalizeName(origName)
}
if origName == "" || targetName == "" {
fmt.Fprintf(ctx.Stderr, "%s empty section name in %q, skipping\n", cmd, requestedName)
fmt.Fprintf(os.Stderr, "%s empty section name in %q, skipping\n", cmd, requestedName)
continue
}

if hasFunc(targetName) && !opt_overwrite {
fmt.Fprintf(ctx.Stderr, "%s %q already exists, skipping\n", cmd, targetName)
fmt.Fprintf(os.Stderr, "%s %q already exists, skipping\n", cmd, targetName)
continue
}
if section, ok := newConfMap[origName]; !ok {
fmt.Fprintf(ctx.Stderr, "%s %q does not exist in config\n", cmd, origName)
fmt.Fprintf(os.Stderr, "%s %q does not exist in config\n", cmd, origName)
continue
} else {
cfgMap[targetName] = make(map[string]string)
Expand All @@ -248,7 +248,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
case "rm":
p := flag.NewFlagSet("rm", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name>\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name>\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand All @@ -267,7 +267,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
case "set":
p := flag.NewFlagSet("set", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name> <key>=<value>...\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name> <key>=<value>...\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand Down Expand Up @@ -295,7 +295,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
var opt_show_secrets bool
p := flag.NewFlagSet("show", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s [<name>...]\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s [<name>...]\n", cmd, p.Name())
p.PrintDefaults()
}

Expand All @@ -318,7 +318,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
for _, name := range names {
name = normalizeName(name)
if !hasFunc(name) {
fmt.Fprintf(ctx.Stderr, "%s %q does not exist\n", cmd, name)
fmt.Fprintf(os.Stderr, "%s %q does not exist\n", cmd, name)
hasErrors = true
continue
}
Expand Down Expand Up @@ -352,11 +352,11 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a

var err error
if opt_json {
err = json.NewEncoder(ctx.Stdout).Encode(map[string]map[string]string{name: cfgMap[name]})
err = json.NewEncoder(os.Stdout).Encode(map[string]map[string]string{name: cfgMap[name]})
} else if opt_ini {
err = MarshalINISections(name, cfgMap[name], ctx.Stdout)
err = MarshalINISections(name, cfgMap[name], os.Stdout)
} else {
err = yaml.NewEncoder(ctx.Stdout).Encode(map[string]map[string]string{name: cfgMap[name]})
err = yaml.NewEncoder(os.Stdout).Encode(map[string]map[string]string{name: cfgMap[name]})
}
if err != nil {
return fmt.Errorf("failed to encode store %q: %w", name, err)
Expand All @@ -370,7 +370,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a
case "unset":
p := flag.NewFlagSet("unset", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name> <key>...\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name> <key>...\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand Down
13 changes: 7 additions & 6 deletions subcommands/config/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -57,7 +58,7 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin
case "add":
p := flag.NewFlagSet("add", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name> [<key>=<value>...]\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name> [<key>=<value>...]\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand Down Expand Up @@ -85,7 +86,7 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin
case "rm":
p := flag.NewFlagSet("rm", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name>\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name>\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand All @@ -104,7 +105,7 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin
case "set":
p := flag.NewFlagSet("set", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name> <key>=<value>...\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name> <key>=<value>...\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand Down Expand Up @@ -133,7 +134,7 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin
var opt_yaml bool
p := flag.NewFlagSet("show", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s [<name>...]\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s [<name>...]\n", cmd, p.Name())
p.PrintDefaults()
}

Expand All @@ -154,12 +155,12 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin
format = "ini"
}

return config.Dump(ctx.Stdout, format, names)
return config.Dump(os.Stdout, format, names)

case "unset":
p := flag.NewFlagSet("unset", flag.ExitOnError)
p.Usage = func() {
fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s <name> <key>...\n", cmd, p.Name())
fmt.Printf("Usage: plakar %s %s <name> <key>...\n", cmd, p.Name())
p.PrintDefaults()
}
p.Parse(args)
Expand Down
12 changes: 6 additions & 6 deletions subcommands/diag/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,47 @@ func (cmd *DiagBlob) Execute(ctx *appcontext.AppContext, repo *repository.Reposi
return 1, fmt.Errorf("failed to deserialize %s %x: %w",
blobtype, mac, err)
}
fmt.Fprintf(ctx.Stdout, "%+v\n", hdr)
fmt.Printf("%+v\n", hdr)

case resources.RT_OBJECT:
obj, err := objects.NewObjectFromBytes(buf)
if err != nil {
return 1, fmt.Errorf("failed to deserialize %s %x: %w",
blobtype, mac, err)
}
fmt.Fprintf(ctx.Stdout, "%+v\n", obj)
fmt.Printf("%+v\n", obj)

case resources.RT_CHUNK:
chunk, err := objects.NewChunkFromBytes(buf)
if err != nil {
return 1, fmt.Errorf("failed to deserialize %s %x: %w",
blobtype, mac, err)
}
fmt.Fprintf(ctx.Stdout, "%+v\n", chunk)
fmt.Printf("%+v\n", chunk)

case resources.RT_VFS_ENTRY:
entry, err := vfs.EntryFromBytes(buf)
if err != nil {
return 1, fmt.Errorf("failed to deserialize %s %x: %w",
blobtype, mac, err)
}
fmt.Fprintf(ctx.Stdout, "%+v\n", entry)
fmt.Printf("%+v\n", entry)

case resources.RT_ERROR_ENTRY:
error, err := vfs.ErrorItemFromBytes(buf)
if err != nil {
return 1, fmt.Errorf("failed to deserialize %s %x: %w",
blobtype, mac, err)
}
fmt.Fprintf(ctx.Stdout, "%+v\n", error)
fmt.Printf("%+v\n", error)

case resources.RT_XATTR_ENTRY:
xattr, err := vfs.XattrFromBytes(buf)
if err != nil {
return 1, fmt.Errorf("failed to deserialize %s %x: %w",
blobtype, mac, err)
}
fmt.Fprintf(ctx.Stdout, "%+v\n", xattr)
fmt.Printf("%+v\n", xattr)

default:
return 1, fmt.Errorf("don't know how to deserialize %s", blobtype)
Expand Down
Loading
Loading