Fix Ls2JsonWriter
by allowing more spaces in the ls response. by sending the error response of the list file system route only when no content has been written.
This commit is contained in:
@ -134,15 +134,17 @@ func (r *NomadJob) ListFileSystem(
|
|||||||
defer ls2json.Close()
|
defer ls2json.Close()
|
||||||
retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("%s %q", command, path)}).FullCommand()
|
retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("%s %q", command, path)}).FullCommand()
|
||||||
exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, privilegedExecution,
|
exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, privilegedExecution,
|
||||||
&nullio.Reader{}, ls2json, io.Discard)
|
&nullio.Reader{Ctx: ctx}, ls2json, io.Discard)
|
||||||
if err != nil {
|
switch {
|
||||||
return fmt.Errorf("%w: nomad error during retrieve file headers: %v",
|
case ls2json.HasStartedWriting():
|
||||||
|
err = nil
|
||||||
|
case err != nil:
|
||||||
|
err = fmt.Errorf("%w: nomad error during retrieve file headers: %v",
|
||||||
nomad.ErrorExecutorCommunicationFailed, err)
|
nomad.ErrorExecutorCommunicationFailed, err)
|
||||||
|
case exitCode != 0:
|
||||||
|
err = ErrFileNotFound
|
||||||
}
|
}
|
||||||
if exitCode != 0 {
|
return err
|
||||||
return ErrFileNotFound
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *NomadJob) UpdateFileSystem(copyRequest *dto.UpdateFileSystemRequest) error {
|
func (r *NomadJob) UpdateFileSystem(copyRequest *dto.UpdateFileSystemRequest) error {
|
||||||
@ -188,7 +190,7 @@ func (r *NomadJob) GetFileContent(
|
|||||||
}).FullCommand()
|
}).FullCommand()
|
||||||
// Improve: Instead of using io.Discard use a **fixed-sized** buffer. With that we could improve the error message.
|
// Improve: Instead of using io.Discard use a **fixed-sized** buffer. With that we could improve the error message.
|
||||||
exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, privilegedExecution,
|
exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, privilegedExecution,
|
||||||
&nullio.Reader{}, contentLengthWriter, io.Discard)
|
&nullio.Reader{Ctx: ctx}, contentLengthWriter, io.Discard)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%w: nomad error during retrieve file content copy: %v",
|
return fmt.Errorf("%w: nomad error during retrieve file content copy: %v",
|
||||||
|
@ -15,7 +15,8 @@ import (
|
|||||||
var (
|
var (
|
||||||
log = logging.GetLogger("nullio")
|
log = logging.GetLogger("nullio")
|
||||||
pathLineRegex = regexp.MustCompile(`(.*):$`)
|
pathLineRegex = regexp.MustCompile(`(.*):$`)
|
||||||
headerLineRegex = regexp.MustCompile(`([-aAbcCdDlMnpPsw?])([-rwxXsStT]{9})([+ ])\d+ (.+?) (.+?) +(\d+) (\d+) (.*)$`)
|
headerLineRegex = regexp.
|
||||||
|
MustCompile(`([-aAbcCdDlMnpPsw?])([-rwxXsStT]{9})(\+?) +\d+ +(.+?) +(.+?) +(\d+) +(\d+) +(.*)$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -39,6 +40,10 @@ type Ls2JsonWriter struct {
|
|||||||
latestPath []byte
|
latestPath []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Ls2JsonWriter) HasStartedWriting() bool {
|
||||||
|
return w.jsonStartSent
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Ls2JsonWriter) Write(p []byte) (int, error) {
|
func (w *Ls2JsonWriter) Write(p []byte) (int, error) {
|
||||||
i, err := w.initializeJSONObject()
|
i, err := w.initializeJSONObject()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user