mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-21 18:28:27 -05:00
+4
-2
@@ -263,11 +263,13 @@ func (s *svc) Handler() http.Handler {
|
||||
rw.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
|
||||
// create the archive
|
||||
var closeArchive func()
|
||||
if userAgent.OS == ua.Windows {
|
||||
err = arch.CreateZip(ctx, rw)
|
||||
closeArchive, err = arch.CreateZip(ctx, rw)
|
||||
} else {
|
||||
err = arch.CreateTar(ctx, rw)
|
||||
closeArchive, err = arch.CreateTar(ctx, rw)
|
||||
}
|
||||
defer closeArchive()
|
||||
|
||||
if err != nil {
|
||||
s.writeHTTPError(rw, err)
|
||||
|
||||
Generated
Vendored
+12
-6
@@ -61,8 +61,11 @@ func NewArchiver(r []*provider.ResourceId, w walker.Walker, d downloader.Downloa
|
||||
}
|
||||
|
||||
// CreateTar creates a tar and write it into the dst Writer
|
||||
func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) error {
|
||||
func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) (func(), error) {
|
||||
w := tar.NewWriter(dst)
|
||||
closer := func() {
|
||||
_ = w.Close()
|
||||
}
|
||||
|
||||
var filesCount, sizeFiles int64
|
||||
|
||||
@@ -125,16 +128,19 @@ func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return closer, err
|
||||
}
|
||||
|
||||
}
|
||||
return w.Close()
|
||||
return closer, nil
|
||||
}
|
||||
|
||||
// CreateZip creates a zip and write it into the dst Writer
|
||||
func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) error {
|
||||
func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) (func(), error) {
|
||||
w := zip.NewWriter(dst)
|
||||
closer := func() {
|
||||
_ = w.Close()
|
||||
}
|
||||
|
||||
var filesCount, sizeFiles int64
|
||||
|
||||
@@ -193,11 +199,11 @@ func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return closer, err
|
||||
}
|
||||
|
||||
}
|
||||
return w.Close()
|
||||
return closer, nil
|
||||
}
|
||||
|
||||
func isSpaceRoot(info *provider.ResourceInfo) bool {
|
||||
|
||||
Generated
Vendored
+18
-1
@@ -308,7 +308,8 @@ func (h *Handler) CreateShare(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
s := conversions.PublicShare2ShareData(share, r, h.publicURL)
|
||||
h.addFileInfo(ctx, s, statRes.Info)
|
||||
h.addFileInfo(ctx, s, statRes.GetInfo())
|
||||
h.addPath(ctx, s, statRes.GetInfo())
|
||||
h.mapUserIds(ctx, client, s)
|
||||
|
||||
response.WriteOCSSuccess(w, r, s)
|
||||
@@ -1225,6 +1226,22 @@ func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, inf
|
||||
s.SpaceAlias = utils.ReadPlainFromOpaque(info.GetSpace().GetOpaque(), "spaceAlias")
|
||||
}
|
||||
|
||||
// addPath adds the complete path of the `ResourceInfo` to the `ShareData`. It is an expensive operation and might leak data so use it with care.
|
||||
func (h *Handler) addPath(ctx context.Context, s *conversions.ShareData, info *provider.ResourceInfo) {
|
||||
log := appctx.GetLogger(ctx)
|
||||
client, err := h.getClient()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("addPath failed: cannot get gateway client")
|
||||
return
|
||||
}
|
||||
gpRes, err := client.GetPath(ctx, &provider.GetPathRequest{ResourceId: info.Id})
|
||||
if err != nil || gpRes.GetStatus().GetCode() != rpc.Code_CODE_OK {
|
||||
log.Error().Err(err).Interface("rpc response code", gpRes.GetStatus().GetCode()).Msg("addPath failed: cannot get path")
|
||||
return
|
||||
}
|
||||
s.Path = gpRes.GetPath()
|
||||
}
|
||||
|
||||
// mustGetIdentifiers always returns a struct with identifiers, if the user or group could not be found they will all be empty
|
||||
func (h *Handler) mustGetIdentifiers(ctx context.Context, client gateway.GatewayAPIClient, id string, isGroup bool) *userIdentifiers {
|
||||
sublog := appctx.GetLogger(ctx).With().Str("id", id).Logger()
|
||||
|
||||
Reference in New Issue
Block a user