Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
edb7ec1f
Commit
edb7ec1f
authored
Jul 03, 2020
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make upload filter code more uniform
parent
71cd15d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
32 deletions
+32
-32
internal/upload/rewrite.go
internal/upload/rewrite.go
+32
-32
No files found.
internal/upload/rewrite.go
View file @
edb7ec1f
...
...
@@ -125,26 +125,22 @@ 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
)
return
err
}
inputReader
=
cleaner
}
else
{
case
rew
.
preauth
.
ProcessLsif
:
inputReader
,
err
=
handleLsifUpload
(
ctx
,
p
,
opts
.
LocalTempPath
,
filename
)
if
err
!=
nil
{
return
err
}
default
:
inputReader
=
p
}
inputReader
,
err
:=
rew
.
handleLsifUpload
(
ctx
,
inputReader
,
opts
.
LocalTempPath
,
filename
)
if
err
!=
nil
{
return
err
}
fh
,
err
:=
filestore
.
SaveFileFromReader
(
ctx
,
inputReader
,
-
1
,
opts
)
if
err
!=
nil
{
switch
err
{
...
...
@@ -170,28 +166,32 @@ 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
{
p
,
err
:=
parser
.
NewParser
(
reader
,
tempPath
)
if
err
!=
nil
{
return
nil
,
err
}
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"
)
z
,
err
:=
p
.
ZipReader
()
if
err
!=
nil
{
return
nil
,
err
}
return
exif
.
NewCleaner
(
ctx
,
r
)
}
if
err
:=
p
.
Close
();
err
!=
nil
{
log
.
WithContextFields
(
ctx
,
log
.
Fields
{
"filename"
:
filename
,
})
.
Print
(
"failed to close lsif parser: "
+
err
.
Error
())
}
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
}
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment