Commit 027c123a authored by Nick Thomas's avatar Nick Thomas

Merge branch 'jv-upload-filters' into 'master'

Make upload filter code (EXIF, LSIF) more uniform

See merge request gitlab-org/gitlab-workhorse!525
parents 71cd15d1 edb7ec1f
...@@ -125,26 +125,22 @@ func (rew *rewriter) handleFilePart(ctx context.Context, name string, p *multipa ...@@ -125,26 +125,22 @@ func (rew *rewriter) handleFilePart(ctx context.Context, name string, p *multipa
opts.TempFilePrefix = filename opts.TempFilePrefix = filename
var inputReader io.Reader var inputReader io.Reader
if exif.IsExifFile(filename) { var err error
log.WithContextFields(ctx, log.Fields{ switch {
"filename": filename, case exif.IsExifFile(filename):
}).Print("running exiftool to remove any metadata") inputReader, err = handleExifUpload(ctx, p, filename)
cleaner, err := exif.NewCleaner(ctx, p)
if err != nil { if err != nil {
return fmt.Errorf("failed to start EXIF metadata cleaner: %v", err) return err
} }
case rew.preauth.ProcessLsif:
inputReader = cleaner inputReader, err = handleLsifUpload(ctx, p, opts.LocalTempPath, filename)
} else { if err != nil {
return err
}
default:
inputReader = p inputReader = p
} }
inputReader, err := rew.handleLsifUpload(ctx, inputReader, opts.LocalTempPath, filename)
if err != nil {
return err
}
fh, err := filestore.SaveFileFromReader(ctx, inputReader, -1, opts) fh, err := filestore.SaveFileFromReader(ctx, inputReader, -1, opts)
if err != nil { if err != nil {
switch err { switch err {
...@@ -170,28 +166,32 @@ func (rew *rewriter) handleFilePart(ctx context.Context, name string, p *multipa ...@@ -170,28 +166,32 @@ func (rew *rewriter) handleFilePart(ctx context.Context, name string, p *multipa
return rew.filter.ProcessFile(ctx, name, fh, rew.writer) return rew.filter.ProcessFile(ctx, name, fh, rew.writer)
} }
func (rew *rewriter) handleLsifUpload(ctx context.Context, reader io.Reader, tempPath, filename string) (io.Reader, error) { func handleExifUpload(ctx context.Context, r io.Reader, filename string) (io.Reader, error) {
if rew.preauth.ProcessLsif { log.WithContextFields(ctx, log.Fields{
p, err := parser.NewParser(reader, tempPath) "filename": filename,
if err != nil { }).Print("running exiftool to remove any metadata")
return nil, err
}
z, err := p.ZipReader() return exif.NewCleaner(ctx, r)
if err != nil { }
return nil, err
}
if err := p.Close(); err != nil { func handleLsifUpload(ctx context.Context, reader io.Reader, tempPath, filename string) (io.Reader, error) {
log.WithContextFields(ctx, log.Fields{ p, err := parser.NewParser(reader, tempPath)
"filename": filename, if err != nil {
}).Print("failed to close lsif parser: " + err.Error()) return nil, err
} }
z, err := p.ZipReader()
if err != nil {
return nil, err
}
return z, nil if err := p.Close(); err != nil {
log.WithContextFields(ctx, log.Fields{
"filename": filename,
}).Print("failed to close lsif parser: " + err.Error())
} }
return reader, nil return z, nil
} }
func (rew *rewriter) copyPart(ctx context.Context, name string, p *multipart.Part) error { func (rew *rewriter) copyPart(ctx context.Context, name string, p *multipart.Part) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment