Skip to content

Commit e99fb5c

Browse files
committed
Fix block device case
Signed-off-by: Anton Sergunov <[email protected]>
1 parent 79246f4 commit e99fb5c

File tree

1 file changed

+18
-4
lines changed
  • internal/dataexport/cmd/list

1 file changed

+18
-4
lines changed

internal/dataexport/cmd/list/list.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ func downloadFunc(
9797
}
9898

9999
var req *http.Request
100-
if volumeMode == "Filesystem" {
100+
switch volumeMode {
101+
case "Filesystem":
101102
if srcPath == "" || srcPath[len(srcPath)-1:] != "/" {
102103
return fmt.Errorf("invalid source path: '%s'", srcPath)
103104
}
@@ -108,24 +109,33 @@ func downloadFunc(
108109

109110
log.Info("Start listing", slog.String("url", dataURL), slog.String("srcPath", srcPath))
110111
req, _ = http.NewRequest("GET", dataURL, nil)
111-
} else if volumeMode == "Block" {
112+
case "Block":
112113
log.Info("Start listing", slog.String("url", url))
113114
req, _ = http.NewRequest("HEAD", url, nil)
114115
}
115116

116-
resp, err := subClient.HttpDo(req)
117+
resp, err := subClient.HttpDo(req.WithContext(ctx))
117118
if err != nil {
118119
return fmt.Errorf("HttpDo: %s\n", err.Error())
119120
}
120121
defer resp.Body.Close()
121122

122123
if resp.StatusCode != 200 {
123-
msg, err := io.ReadAll(io.LimitReader(resp.Body, 1000))
124+
const maxLen = 4096
125+
msg, err := io.ReadAll(io.LimitReader(resp.Body, maxLen))
124126
if err == nil {
125127
return fmt.Errorf("Backend response \"%s\" Msg: %s", resp.Status, string(msg))
126128
}
127129
}
128130

131+
if volumeMode == "Block" {
132+
body := ""
133+
if contLen := resp.Header.Get("Content-Length"); contLen != "" {
134+
body = fmt.Sprintf("Content-Length: %s", contLen)
135+
}
136+
return foo(strings.NewReader(body))
137+
}
138+
129139
return foo(resp.Body)
130140
}
131141

@@ -185,8 +195,12 @@ func Run(ctx context.Context, log *slog.Logger, cmd *cobra.Command, args []strin
185195

186196
err = downloadFunc(ctx, log, namespace, deName, srcPath, publish, sClient, func(body io.Reader) error {
187197
_, err := io.Copy(os.Stdout, body)
198+
if err == io.EOF {
199+
err = nil
200+
}
188201
return err
189202
})
203+
190204
if err != nil {
191205
return err
192206
}

0 commit comments

Comments
 (0)