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,25 +125,21 @@ func (rew *rewriter) handleFilePart(ctx context.Context, name string, p *multipa
opts.TempFilePrefix = filename
var inputReader io.Reader
if exif.IsExifFile(filename) {
log.WithContextFields(ctx, log.Fields{
"filename": filename,
}).Print("running exiftool to remove any metadata")
cleaner, err := exif.NewCleaner(ctx, p)
var err error
switch {
case exif.IsExifFile(filename):
inputReader, err = handleExifUpload(ctx, p, filename)
if err != nil {
return fmt.Errorf("failed to start EXIF metadata cleaner: %v", err)
}
inputReader = cleaner
} else {
inputReader = p
return err
}
inputReader, err := rew.handleLsifUpload(ctx, inputReader, opts.LocalTempPath, filename)
case rew.preauth.ProcessLsif:
inputReader, err = handleLsifUpload(ctx, p, opts.LocalTempPath, filename)
if err != nil {
return err
}
default:
inputReader = p
}
fh, err := filestore.SaveFileFromReader(ctx, inputReader, -1, opts)
if err != nil {
......@@ -170,8 +166,15 @@ func (rew *rewriter) handleFilePart(ctx context.Context, name string, p *multipa
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) {
if rew.preauth.ProcessLsif {
func handleExifUpload(ctx context.Context, r io.Reader, filename string) (io.Reader, error) {
log.WithContextFields(ctx, log.Fields{
"filename": filename,
}).Print("running exiftool to remove any metadata")
return exif.NewCleaner(ctx, r)
}
func handleLsifUpload(ctx context.Context, reader io.Reader, tempPath, filename string) (io.Reader, error) {
p, err := parser.NewParser(reader, tempPath)
if err != nil {
return nil, err
......@@ -189,9 +192,6 @@ func (rew *rewriter) handleLsifUpload(ctx context.Context, reader io.Reader, tem
}
return z, nil
}
return reader, nil
}
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