diff options
author | Janoš Guljaš <janos@users.noreply.github.com> | 2018-08-10 22:12:55 +0800 |
---|---|---|
committer | Balint Gabor <balint.g@gmail.com> | 2018-08-10 22:12:55 +0800 |
commit | 6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36 (patch) | |
tree | 3bcd5ab444bd7486a9011656c85baeee00216286 /swarm/api/api.go | |
parent | 3ec5dda4d2dd0dec6d5bd465752f30e8f6ce208c (diff) | |
download | go-tangerine-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.tar go-tangerine-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.tar.gz go-tangerine-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.tar.bz2 go-tangerine-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.tar.lz go-tangerine-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.tar.xz go-tangerine-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.tar.zst go-tangerine-6d1e292eefa70b5cb76cd03ff61fc6c4550d7c36.zip |
Manifest cli fix and upload defaultpath only once (#17375)
* cmd/swarm: fix manifest subcommands and add tests
* cmd/swarm: manifest update: update default entry for non-encrypted uploads
* swarm/api: upload defaultpath file only once
* swarm/api/client: improve UploadDirectory default path handling
* cmd/swarm: support absolute and relative default path values
* cmd/swarm: fix a typo in test
* cmd/swarm: check encrypted uploads in manifest update tests
Diffstat (limited to 'swarm/api/api.go')
-rw-r--r-- | swarm/api/api.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/swarm/api/api.go b/swarm/api/api.go index b418c45e1..99d971b10 100644 --- a/swarm/api/api.go +++ b/swarm/api/api.go @@ -704,11 +704,12 @@ func (a *API) AddFile(ctx context.Context, mhash, path, fname string, content [] return fkey, newMkey.String(), nil } -func (a *API) UploadTar(ctx context.Context, bodyReader io.ReadCloser, manifestPath string, mw *ManifestWriter) (storage.Address, error) { +func (a *API) UploadTar(ctx context.Context, bodyReader io.ReadCloser, manifestPath, defaultPath string, mw *ManifestWriter) (storage.Address, error) { apiUploadTarCount.Inc(1) var contentKey storage.Address tr := tar.NewReader(bodyReader) defer bodyReader.Close() + var defaultPathFound bool for { hdr, err := tr.Next() if err == io.EOF { @@ -737,6 +738,25 @@ func (a *API) UploadTar(ctx context.Context, bodyReader io.ReadCloser, manifestP apiUploadTarFail.Inc(1) return nil, fmt.Errorf("error adding manifest entry from tar stream: %s", err) } + if hdr.Name == defaultPath { + entry := &ManifestEntry{ + Hash: contentKey.Hex(), + Path: "", // default entry + ContentType: hdr.Xattrs["user.swarm.content-type"], + Mode: hdr.Mode, + Size: hdr.Size, + ModTime: hdr.ModTime, + } + contentKey, err = mw.AddEntry(ctx, nil, entry) + if err != nil { + apiUploadTarFail.Inc(1) + return nil, fmt.Errorf("error adding default manifest entry from tar stream: %s", err) + } + defaultPathFound = true + } + } + if defaultPath != "" && !defaultPathFound { + return contentKey, fmt.Errorf("default path %q not found", defaultPath) } return contentKey, nil } |