Remove fileshare logs (#1814)

This commit is contained in:
Evan Simkowitz 2025-01-23 12:38:55 -08:00 committed by GitHub
parent 2304b8be22
commit 965ed288f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 31 deletions

View File

@ -22,14 +22,12 @@ const (
// CreateFileShareClient creates a fileshare client based on the connection string // CreateFileShareClient creates a fileshare client based on the connection string
// Returns the client and the parsed connection // Returns the client and the parsed connection
func CreateFileShareClient(ctx context.Context, connection string) (fstype.FileShareClient, *connparse.Connection) { func CreateFileShareClient(ctx context.Context, connection string) (fstype.FileShareClient, *connparse.Connection) {
log.Printf("CreateFileShareClient: connection=%s", connection)
conn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, connection) conn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, connection)
if err != nil { if err != nil {
log.Printf("error parsing connection: %v", err) log.Printf("error parsing connection: %v", err)
return nil, nil return nil, nil
} }
conntype := conn.GetType() conntype := conn.GetType()
log.Printf("CreateFileShareClient: conntype=%s", conntype)
if conntype == connparse.ConnectionTypeS3 { if conntype == connparse.ConnectionTypeS3 {
config, err := awsconn.GetConfig(ctx, connection) config, err := awsconn.GetConfig(ctx, connection)
if err != nil { if err != nil {
@ -48,7 +46,6 @@ func CreateFileShareClient(ctx context.Context, connection string) (fstype.FileS
} }
func Read(ctx context.Context, data wshrpc.FileData) (*wshrpc.FileData, error) { func Read(ctx context.Context, data wshrpc.FileData) (*wshrpc.FileData, error) {
log.Printf("Read: path=%s", data.Info.Path)
client, conn := CreateFileShareClient(ctx, data.Info.Path) client, conn := CreateFileShareClient(ctx, data.Info.Path)
if conn == nil || client == nil { if conn == nil || client == nil {
return nil, fmt.Errorf(ErrorParsingConnection, data.Info.Path) return nil, fmt.Errorf(ErrorParsingConnection, data.Info.Path)
@ -57,7 +54,6 @@ func Read(ctx context.Context, data wshrpc.FileData) (*wshrpc.FileData, error) {
} }
func ReadStream(ctx context.Context, data wshrpc.FileData) <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData] { func ReadStream(ctx context.Context, data wshrpc.FileData) <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData] {
log.Printf("ReadStream: path=%s", data.Info.Path)
client, conn := CreateFileShareClient(ctx, data.Info.Path) client, conn := CreateFileShareClient(ctx, data.Info.Path)
if conn == nil || client == nil { if conn == nil || client == nil {
return wshutil.SendErrCh[wshrpc.FileData](fmt.Errorf(ErrorParsingConnection, data.Info.Path)) return wshutil.SendErrCh[wshrpc.FileData](fmt.Errorf(ErrorParsingConnection, data.Info.Path))
@ -66,7 +62,6 @@ func ReadStream(ctx context.Context, data wshrpc.FileData) <-chan wshrpc.RespOrE
} }
func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData) <-chan wshrpc.RespOrErrorUnion[[]byte] { func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData) <-chan wshrpc.RespOrErrorUnion[[]byte] {
log.Printf("ReadTarStream: path=%s", data.Path)
client, conn := CreateFileShareClient(ctx, data.Path) client, conn := CreateFileShareClient(ctx, data.Path)
if conn == nil || client == nil { if conn == nil || client == nil {
return wshutil.SendErrCh[[]byte](fmt.Errorf(ErrorParsingConnection, data.Path)) return wshutil.SendErrCh[[]byte](fmt.Errorf(ErrorParsingConnection, data.Path))
@ -75,7 +70,6 @@ func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData)
} }
func ListEntries(ctx context.Context, path string, opts *wshrpc.FileListOpts) ([]*wshrpc.FileInfo, error) { func ListEntries(ctx context.Context, path string, opts *wshrpc.FileListOpts) ([]*wshrpc.FileInfo, error) {
log.Printf("ListEntries: path=%s", path)
client, conn := CreateFileShareClient(ctx, path) client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil { if conn == nil || client == nil {
return nil, fmt.Errorf(ErrorParsingConnection, path) return nil, fmt.Errorf(ErrorParsingConnection, path)
@ -84,7 +78,6 @@ func ListEntries(ctx context.Context, path string, opts *wshrpc.FileListOpts) ([
} }
func ListEntriesStream(ctx context.Context, path string, opts *wshrpc.FileListOpts) <-chan wshrpc.RespOrErrorUnion[wshrpc.CommandRemoteListEntriesRtnData] { func ListEntriesStream(ctx context.Context, path string, opts *wshrpc.FileListOpts) <-chan wshrpc.RespOrErrorUnion[wshrpc.CommandRemoteListEntriesRtnData] {
log.Printf("ListEntriesStream: path=%s", path)
client, conn := CreateFileShareClient(ctx, path) client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil { if conn == nil || client == nil {
return wshutil.SendErrCh[wshrpc.CommandRemoteListEntriesRtnData](fmt.Errorf(ErrorParsingConnection, path)) return wshutil.SendErrCh[wshrpc.CommandRemoteListEntriesRtnData](fmt.Errorf(ErrorParsingConnection, path))
@ -93,7 +86,6 @@ func ListEntriesStream(ctx context.Context, path string, opts *wshrpc.FileListOp
} }
func Stat(ctx context.Context, path string) (*wshrpc.FileInfo, error) { func Stat(ctx context.Context, path string) (*wshrpc.FileInfo, error) {
log.Printf("Stat: path=%s", path)
client, conn := CreateFileShareClient(ctx, path) client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil { if conn == nil || client == nil {
return nil, fmt.Errorf(ErrorParsingConnection, path) return nil, fmt.Errorf(ErrorParsingConnection, path)
@ -102,7 +94,6 @@ func Stat(ctx context.Context, path string) (*wshrpc.FileInfo, error) {
} }
func PutFile(ctx context.Context, data wshrpc.FileData) error { func PutFile(ctx context.Context, data wshrpc.FileData) error {
log.Printf("PutFile: path=%s", data.Info.Path)
client, conn := CreateFileShareClient(ctx, data.Info.Path) client, conn := CreateFileShareClient(ctx, data.Info.Path)
if conn == nil || client == nil { if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, data.Info.Path) return fmt.Errorf(ErrorParsingConnection, data.Info.Path)
@ -111,7 +102,6 @@ func PutFile(ctx context.Context, data wshrpc.FileData) error {
} }
func Mkdir(ctx context.Context, path string) error { func Mkdir(ctx context.Context, path string) error {
log.Printf("Mkdir: path=%s", path)
client, conn := CreateFileShareClient(ctx, path) client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil { if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, path) return fmt.Errorf(ErrorParsingConnection, path)
@ -120,7 +110,6 @@ func Mkdir(ctx context.Context, path string) error {
} }
func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error { func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error {
log.Printf("Move: src=%s, dest=%s", data.SrcUri, data.DestUri)
srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, data.SrcUri) srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, data.SrcUri)
if err != nil { if err != nil {
return fmt.Errorf("error parsing source connection %s: %v", data.SrcUri, err) return fmt.Errorf("error parsing source connection %s: %v", data.SrcUri, err)
@ -133,7 +122,6 @@ func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error {
} }
func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error { func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error {
log.Printf("Copy: src=%s, dest=%s", data.SrcUri, data.DestUri)
srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, data.SrcUri) srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, data.SrcUri)
if err != nil { if err != nil {
return fmt.Errorf("error parsing source connection %s: %v", data.SrcUri, err) return fmt.Errorf("error parsing source connection %s: %v", data.SrcUri, err)
@ -146,7 +134,6 @@ func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error {
} }
func Delete(ctx context.Context, path string) error { func Delete(ctx context.Context, path string) error {
log.Printf("Delete: path=%s", path)
client, conn := CreateFileShareClient(ctx, path) client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil { if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, path) return fmt.Errorf(ErrorParsingConnection, path)
@ -155,7 +142,6 @@ func Delete(ctx context.Context, path string) error {
} }
func Join(ctx context.Context, path string, parts ...string) (string, error) { func Join(ctx context.Context, path string, parts ...string) (string, error) {
log.Printf("Join: path=%s, parts=%v", path, parts)
client, conn := CreateFileShareClient(ctx, path) client, conn := CreateFileShareClient(ctx, path)
if conn == nil || client == nil { if conn == nil || client == nil {
return "", fmt.Errorf(ErrorParsingConnection, path) return "", fmt.Errorf(ErrorParsingConnection, path)
@ -164,7 +150,6 @@ func Join(ctx context.Context, path string, parts ...string) (string, error) {
} }
func Append(ctx context.Context, data wshrpc.FileData) error { func Append(ctx context.Context, data wshrpc.FileData) error {
log.Printf("Append: path=%s", data.Info.Path)
client, conn := CreateFileShareClient(ctx, data.Info.Path) client, conn := CreateFileShareClient(ctx, data.Info.Path)
if conn == nil || client == nil { if conn == nil || client == nil {
return fmt.Errorf(ErrorParsingConnection, data.Info.Path) return fmt.Errorf(ErrorParsingConnection, data.Info.Path)

View File

@ -105,13 +105,13 @@ func (impl *ServerImpl) remoteStreamFileDir(ctx context.Context, path string, by
innerFileInfo := statToFileInfo(filepath.Join(path, innerFileInfoInt.Name()), innerFileInfoInt, false) innerFileInfo := statToFileInfo(filepath.Join(path, innerFileInfoInt.Name()), innerFileInfoInt, false)
fileInfoArr = append(fileInfoArr, innerFileInfo) fileInfoArr = append(fileInfoArr, innerFileInfo)
if len(fileInfoArr) >= wshrpc.DirChunkSize { if len(fileInfoArr) >= wshrpc.DirChunkSize {
log.Printf("sending %d entries\n", len(fileInfoArr)) logPrintfDev("sending %d entries\n", len(fileInfoArr))
dataCallback(fileInfoArr, nil, byteRange) dataCallback(fileInfoArr, nil, byteRange)
fileInfoArr = nil fileInfoArr = nil
} }
} }
if len(fileInfoArr) > 0 { if len(fileInfoArr) > 0 {
log.Printf("sending %d entries\n", len(fileInfoArr)) logPrintfDev("sending %d entries\n", len(fileInfoArr))
dataCallback(fileInfoArr, nil, byteRange) dataCallback(fileInfoArr, nil, byteRange)
} }
return nil return nil
@ -204,7 +204,7 @@ func (impl *ServerImpl) RemoteStreamFileCommand(ctx context.Context, data wshrpc
resp.Data64 = base64.StdEncoding.EncodeToString(data) resp.Data64 = base64.StdEncoding.EncodeToString(data)
resp.At = &wshrpc.FileDataAt{Offset: byteRange.Start, Size: len(data)} resp.At = &wshrpc.FileDataAt{Offset: byteRange.Start, Size: len(data)}
} }
log.Printf("callback -- sending response %d\n", len(resp.Data64)) logPrintfDev("callback -- sending response %d\n", len(resp.Data64))
ch <- wshrpc.RespOrErrorUnion[wshrpc.FileData]{Response: resp} ch <- wshrpc.RespOrErrorUnion[wshrpc.FileData]{Response: resp}
}) })
if err != nil { if err != nil {
@ -254,9 +254,9 @@ func (impl *ServerImpl) RemoteTarStreamCommand(ctx context.Context, data wshrpc.
return return
} }
defer tarWriter.Close() defer tarWriter.Close()
log.Printf("creating tar stream for %q\n", path) logPrintfDev("creating tar stream for %q\n", path)
if finfo.IsDir() { if finfo.IsDir() {
log.Printf("%q is a directory, recursive: %v\n", path, recursive) logPrintfDev("%q is a directory, recursive: %v\n", path, recursive)
if !recursive { if !recursive {
rtn <- wshutil.RespErr[[]byte](fmt.Errorf("cannot create tar stream for %q: %w", path, errors.New("directory copy requires recursive option"))) rtn <- wshutil.RespErr[[]byte](fmt.Errorf("cannot create tar stream for %q: %w", path, errors.New("directory copy requires recursive option")))
return return
@ -288,7 +288,7 @@ func (impl *ServerImpl) RemoteTarStreamCommand(ctx context.Context, data wshrpc.
log.Printf("error copying file %q: %v\n", file, err) log.Printf("error copying file %q: %v\n", file, err)
return err return err
} else { } else {
log.Printf("wrote %d bytes to tar stream\n", n) logPrintfDev("wrote %d bytes to tar stream\n", n)
} }
} }
time.Sleep(time.Millisecond * 10) time.Sleep(time.Millisecond * 10)
@ -297,9 +297,9 @@ func (impl *ServerImpl) RemoteTarStreamCommand(ctx context.Context, data wshrpc.
if err != nil { if err != nil {
rtn <- wshutil.RespErr[[]byte](fmt.Errorf("cannot create tar stream for %q: %w", path, err)) rtn <- wshutil.RespErr[[]byte](fmt.Errorf("cannot create tar stream for %q: %w", path, err))
} }
log.Printf("returning tar stream\n") logPrintfDev("returning tar stream\n")
}() }()
log.Printf("returning channel\n") logPrintfDev("returning channel\n")
return rtn return rtn
} }
@ -334,13 +334,13 @@ func (impl *ServerImpl) RemoteFileCopyCommand(ctx context.Context, data wshrpc.C
} else if !errors.Is(err, fs.ErrNotExist) { } else if !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("cannot stat destination %q: %w", destPathCleaned, err) return fmt.Errorf("cannot stat destination %q: %w", destPathCleaned, err)
} }
log.Printf("copying %q to %q\n", srcUri, destUri) logPrintfDev("copying %q to %q\n", srcUri, destUri)
srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, srcUri) srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, srcUri)
if err != nil { if err != nil {
return fmt.Errorf("cannot parse source URI %q: %w", srcUri, err) return fmt.Errorf("cannot parse source URI %q: %w", srcUri, err)
} }
if srcConn.Host == destConn.Host { if srcConn.Host == destConn.Host {
log.Printf("same host, copying file\n") logPrintfDev("same host, copying file\n")
srcPathCleaned := filepath.Clean(wavebase.ExpandHomeDirSafe(srcConn.Path)) srcPathCleaned := filepath.Clean(wavebase.ExpandHomeDirSafe(srcConn.Path))
err := os.Rename(srcPathCleaned, destPathCleaned) err := os.Rename(srcPathCleaned, destPathCleaned)
if err != nil { if err != nil {
@ -654,7 +654,7 @@ func (impl *ServerImpl) RemoteFileTouchCommand(ctx context.Context, path string)
} }
func (impl *ServerImpl) RemoteFileMoveCommand(ctx context.Context, data wshrpc.CommandRemoteFileCopyData) error { func (impl *ServerImpl) RemoteFileMoveCommand(ctx context.Context, data wshrpc.CommandRemoteFileCopyData) error {
log.Printf("RemoteFileCopyCommand: src=%s, dest=%s\n", data.SrcUri, data.DestUri) logPrintfDev("RemoteFileCopyCommand: src=%s, dest=%s\n", data.SrcUri, data.DestUri)
opts := data.Opts opts := data.Opts
destUri := data.DestUri destUri := data.DestUri
srcUri := data.SrcUri srcUri := data.SrcUri
@ -680,16 +680,16 @@ func (impl *ServerImpl) RemoteFileMoveCommand(ctx context.Context, data wshrpc.C
} else if !errors.Is(err, fs.ErrNotExist) { } else if !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("cannot stat destination %q: %w", destUri, err) return fmt.Errorf("cannot stat destination %q: %w", destUri, err)
} }
log.Printf("moving %q to %q\n", srcUri, destUri) logPrintfDev("moving %q to %q\n", srcUri, destUri)
srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, srcUri) srcConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, srcUri)
if err != nil { if err != nil {
return fmt.Errorf("cannot parse source URI %q: %w", srcUri, err) return fmt.Errorf("cannot parse source URI %q: %w", srcUri, err)
} }
log.Printf("source host: %q, destination host: %q\n", srcConn.Host, destConn.Host) logPrintfDev("source host: %q, destination host: %q\n", srcConn.Host, destConn.Host)
if srcConn.Host == destConn.Host { if srcConn.Host == destConn.Host {
log.Printf("moving file on same host\n") logPrintfDev("moving file on same host\n")
srcPathCleaned := filepath.Clean(wavebase.ExpandHomeDirSafe(srcConn.Path)) srcPathCleaned := filepath.Clean(wavebase.ExpandHomeDirSafe(srcConn.Path))
log.Printf("moving %q to %q\n", srcPathCleaned, destPathCleaned) logPrintfDev("moving %q to %q\n", srcPathCleaned, destPathCleaned)
err := os.Rename(srcPathCleaned, destPathCleaned) err := os.Rename(srcPathCleaned, destPathCleaned)
if err != nil { if err != nil {
return fmt.Errorf("cannot move file %q to %q: %w", srcPathCleaned, destPathCleaned, err) return fmt.Errorf("cannot move file %q to %q: %w", srcPathCleaned, destPathCleaned, err)
@ -776,7 +776,7 @@ func (*ServerImpl) RemoteWriteFileCommand(ctx context.Context, data wshrpc.FileD
if err != nil { if err != nil {
return fmt.Errorf("cannot write to file %q: %w", path, err) return fmt.Errorf("cannot write to file %q: %w", path, err)
} }
log.Printf("wrote %d bytes to file %q at offset %d\n", n, path, atOffset) logPrintfDev("wrote %d bytes to file %q at offset %d\n", n, path, atOffset)
return nil return nil
} }
@ -800,3 +800,9 @@ func (*ServerImpl) RemoteGetInfoCommand(ctx context.Context) (wshrpc.RemoteInfo,
func (*ServerImpl) RemoteInstallRcFilesCommand(ctx context.Context) error { func (*ServerImpl) RemoteInstallRcFilesCommand(ctx context.Context) error {
return wshutil.InstallRcFiles() return wshutil.InstallRcFiles()
} }
func logPrintfDev(format string, args ...interface{}) {
if wavebase.IsDevMode() {
log.Printf(format, args...)
}
}