Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
Normalize logging
Browse files Browse the repository at this point in the history
Remove logging that's redundant because the API or FUSE layer already
logs the same info. Ensure each call to Exec logs what it's executing.

Signed-off-by: Michael Smith <michael.smith@puppet.com>
  • Loading branch information
MikaelSmith committed Apr 16, 2020
1 parent 851370d commit bcccf34
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions volume/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (e nonZeroError) Error() string {
}

func exec(ctx context.Context, executor plugin.Execable, cmdline []string, tty bool) (*bytes.Buffer, error) {
activity.Record(ctx, "Running %v on %v", cmdline, executor)
// Use Elevate because it's common to login to systems as a non-root user and sudo.
opts := plugin.ExecOptions{Elevate: true, Tty: tty}
cmd, err := plugin.Exec(ctx, executor, cmdline[0], cmdline[1:], opts)
Expand Down Expand Up @@ -105,7 +106,6 @@ func exec(ctx context.Context, executor plugin.Execable, cmdline []string, tty b
// VolumeList satisfies the Interface required by List to enumerate files.
func (d *FS) VolumeList(ctx context.Context, path string) (DirMap, error) {
cmdline := d.selectShellCommand(StatCmdPOSIX(path, d.maxdepth), StatCmdPowershell(path, d.maxdepth))
activity.Record(ctx, "Running %v on %v", cmdline, plugin.ID(d.executor))

// Use Tty if running Wash interactively so we get a reflection of the system consistent with
// being logged in as a user. `ls` will report different file types based on whether you're using
Expand All @@ -131,7 +131,6 @@ func (d *FS) VolumeList(ctx context.Context, path string) (DirMap, error) {
} else if err != nil {
return nil, err
}
activity.Record(ctx, "VolumeList complete")

// Always returns results normalized to the base.
switch d.loginShell() {
Expand All @@ -146,7 +145,6 @@ func (d *FS) VolumeList(ctx context.Context, path string) (DirMap, error) {

// VolumeRead satisfies the Interface required by List to read file contents.
func (d *FS) VolumeRead(ctx context.Context, path string) ([]byte, error) {
activity.Record(ctx, "Reading %v on %v", path, plugin.ID(d.executor))
command := d.selectShellCommand([]string{"cat", path}, []string{"Get-Content '" + path + "'"})

// Don't use Tty when outputting file content because it may convert LF to CRLF.
Expand All @@ -160,11 +158,11 @@ func (d *FS) VolumeRead(ctx context.Context, path string) ([]byte, error) {

// VolumeStream satisfies the Interface required by List to stream file contents.
func (d *FS) VolumeStream(ctx context.Context, path string) (io.ReadCloser, error) {
activity.Record(ctx, "Streaming %v on %v", path, plugin.ID(d.executor))
command := d.selectShellCommand(
[]string{"tail", "-f", path},
[]string{"Get-Content -Wait -Tail 10 '" + path + "'"},
)
activity.Record(ctx, "Running %v on %v", command, d.executor)

execOpts := plugin.ExecOptions{Elevate: true, Tty: true}
cmd, err := plugin.Exec(ctx, d.executor, command[0], command[1:], execOpts)
Expand Down Expand Up @@ -205,8 +203,8 @@ func (d *FS) VolumeStream(ctx context.Context, path string) (io.ReadCloser, erro

// VolumeWrite satisfies the Interface required by Write to write content to a file.
func (d *FS) VolumeWrite(ctx context.Context, path string, b []byte, _ os.FileMode) error {
activity.Record(ctx, "Writing %v bytes to %v on %v", len(b), path, plugin.ID(d.executor))
command := d.selectShellCommand([]string{"cp", "/dev/stdin", path}, []string{"$input | Set-Content '" + path + "'"})
activity.Record(ctx, "Running %v on %v", command, d.executor)

// Don't use Tty when writing file content because it may convert LF to CRLF.
// Use Elevate because it's common to login to systems as a non-root user and sudo.
Expand Down Expand Up @@ -243,7 +241,6 @@ func (d *FS) VolumeWrite(ctx context.Context, path string, b []byte, _ os.FileMo

// VolumeDelete satisfies the Interface required by Delete to delete volume nodes.
func (d *FS) VolumeDelete(ctx context.Context, path string) (bool, error) {
activity.Record(ctx, "Deleting %v on %v", path, plugin.ID(d.executor))
command := d.selectShellCommand(
[]string{"rm", "-rf", path},
[]string{"Remove-Item -Recurse -Force '" + path + "'"},
Expand Down

0 comments on commit bcccf34

Please sign in to comment.