Skip to content

Commit

Permalink
fixup! Add dumping windows extended file attributes for encrypted dis…
Browse files Browse the repository at this point in the history
…k store
  • Loading branch information
pchila committed Jun 19, 2024
1 parent 27179aa commit 9e783f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions internal/pkg/agent/storage/encrypted_disk_storage_debug_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
package storage

import (
"encoding/json"
"fmt"
"os"
"syscall"
"strings"
)

type loggerFunc func(fmtString string, args ...any)

func printFileInfo(info os.FileInfo) string {
buf := new(strings.Builder)
encoder := json.NewEncoder(buf)
encoder.SetIndent("", " ")
err := encoder.Encode(info)
if err != nil {
return fmt.Sprintf("error encoding FileInfo: %s", err)
}
return buf.String()
}

func DumpFilesystemInfo(path string, logF loggerFunc) {
stat, staterr := os.Stat(path)
if staterr != nil {
logF("Error stat()ing %s: %s", path, staterr)
} else {
logF("%s stat:\n%+v\n", path, stat)
logF("%s win stat:\n%+v\n", path, stat.Sys().(*syscall.Win32FileAttributeData))
logF("%s stat:\n%s\n", path, printFileInfo(stat))
}
}
4 changes: 2 additions & 2 deletions internal/pkg/agent/storage/encrypted_disk_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func (d *EncryptedDiskStore) ensureKey(ctx context.Context) error {
// Specifically it will write to a .tmp file then rotate the file to the target name to ensure that an error does not corrupt the previously written file.
func (d *EncryptedDiskStore) Save(in io.Reader) error {
if d.target == paths.AgentConfigFile() {
fmt.Fprintf(os.Stderr, "Save of %s started at %s", paths.AgentConfigFile(), time.Now())
fmt.Fprintf(os.Stderr, "Save of %s started at %s\n", paths.AgentConfigFile(), time.Now())
defer func() {
fmt.Fprintf(os.Stderr, "Save of %s finished at %s", paths.AgentConfigFile(), time.Now())
fmt.Fprintf(os.Stderr, "Save of %s finished at %s\n", paths.AgentConfigFile(), time.Now())
}()
}

Expand Down

0 comments on commit 9e783f2

Please sign in to comment.