working commit
This commit is contained in:
+20
-10
@@ -24,20 +24,21 @@ import (
|
||||
"mstore/pkg/auxhttp"
|
||||
)
|
||||
|
||||
func (cli *Client) FileExists(ctx context.Context, fileuri string) (bool, error) {
|
||||
var res bool
|
||||
func (cli *Client) FileInfo(ctx context.Context, fileuri string) (bool, *descr.File, error) {
|
||||
var exists bool
|
||||
var err error
|
||||
file := &descr.File{}
|
||||
fileuri, username, password, err := repackServiceURI(fileuri)
|
||||
if err != nil {
|
||||
return res, err
|
||||
return exists, file, err
|
||||
}
|
||||
fileuri, err = convertFileURI(fileuri)
|
||||
if err != nil {
|
||||
return res, err
|
||||
return exists, file, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodHead, fileuri, nil)
|
||||
if err != nil {
|
||||
return res, err
|
||||
return exists, file, err
|
||||
}
|
||||
if username != "" && password != "" {
|
||||
basic := auxhttp.EncodeBasicAuth(username, password)
|
||||
@@ -46,13 +47,23 @@ func (cli *Client) FileExists(ctx context.Context, fileuri string) (bool, error)
|
||||
client := makeHTTPClient()
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return res, err
|
||||
return exists, file, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
res = true
|
||||
file.Collection = resp.Header.Get("Content-Collection")
|
||||
file.Name = resp.Header.Get("Content-Name")
|
||||
contentSize := resp.Header.Get("Content-Size")
|
||||
size, err := strconv.ParseInt(contentSize, 10, 64)
|
||||
if err != nil {
|
||||
return exists, file, err
|
||||
}
|
||||
file.Size = size
|
||||
file.Type = resp.Header.Get("Content-Type")
|
||||
file.Checksum = resp.Header.Get("Content-Digest")
|
||||
exists = true
|
||||
}
|
||||
return res, err
|
||||
return exists, file, err
|
||||
}
|
||||
|
||||
func (cli *Client) PutFile(ctx context.Context, filename, fileuri string) error {
|
||||
@@ -164,7 +175,7 @@ func (cli *Client) GetFile(ctx context.Context, fileuri, filename string) (int64
|
||||
return size, err
|
||||
}
|
||||
|
||||
func (cli *Client) DeleteFile(ctx context.Context, fileuri, filename string) error {
|
||||
func (cli *Client) DeleteFile(ctx context.Context, fileuri string) error {
|
||||
var err error
|
||||
|
||||
fileuri, username, password, err := repackServiceURI(fileuri)
|
||||
@@ -247,7 +258,6 @@ func (cli *Client) ListFiles(ctx context.Context, catalogURI string) ([]descr.Fi
|
||||
err := fmt.Errorf("Mismatch Content-Length and recorded filesize")
|
||||
return res, err
|
||||
}
|
||||
fmt.Printf("list: %s\n",string(respBytes))
|
||||
err = json.Unmarshal(respBytes, &res)
|
||||
if err != nil {
|
||||
return res, err
|
||||
|
||||
Reference in New Issue
Block a user