Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
liber
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
liber
Commits
d245fcb5
Commit
d245fcb5
authored
7 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Do not call os.Open directly but use FileStorage.Open
parent
e26a7a72
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
opf.go
+3
-4
3 additions, 4 deletions
opf.go
sync.go
+4
-5
4 additions, 5 deletions
sync.go
with
7 additions
and
9 deletions
opf.go
+
3
−
4
View file @
d245fcb5
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"encoding/xml"
"encoding/xml"
"errors"
"errors"
"io"
"io"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
)
)
...
@@ -67,8 +66,8 @@ func opfParse(r io.Reader) (*Metadata, error) {
...
@@ -67,8 +66,8 @@ func opfParse(r io.Reader) (*Metadata, error) {
return
opf
.
Meta
.
ToMetadata
(),
nil
return
opf
.
Meta
.
ToMetadata
(),
nil
}
}
func
opfOpen
(
path
string
)
(
*
Metadata
,
error
)
{
func
opfOpen
(
storage
*
FileStorage
,
path
string
)
(
*
Metadata
,
error
)
{
file
,
err
:=
o
s
.
Open
(
path
)
file
,
err
:=
s
torage
.
Open
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -88,7 +87,7 @@ func (p *opfProvider) Lookup(storage *FileStorage, path, filetype string) (*Meta
...
@@ -88,7 +87,7 @@ func (p *opfProvider) Lookup(storage *FileStorage, path, filetype string) (*Meta
replaceExt
(
path
,
".opf"
),
replaceExt
(
path
,
".opf"
),
}
}
for
_
,
opfpath
:=
range
paths
{
for
_
,
opfpath
:=
range
paths
{
if
m
,
err
:=
opfOpen
(
storage
.
Abs
(
opfpath
)
)
;
err
==
nil
{
if
m
,
err
:=
opfOpen
(
storage
,
opfpath
);
err
==
nil
{
return
m
,
err
return
m
,
err
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
sync.go
+
4
−
5
View file @
d245fcb5
...
@@ -9,7 +9,6 @@ import (
...
@@ -9,7 +9,6 @@ import (
"mime/multipart"
"mime/multipart"
"net/http"
"net/http"
"net/url"
"net/url"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
"sync"
"sync"
...
@@ -91,8 +90,8 @@ func (r *remoteServer) DiffRequest(diffreq *diffRequest) (*diffResponse, error)
...
@@ -91,8 +90,8 @@ func (r *remoteServer) DiffRequest(diffreq *diffRequest) (*diffResponse, error)
return
&
diffresp
,
nil
return
&
diffresp
,
nil
}
}
func
addFilePart
(
w
*
multipart
.
Writer
,
varname
,
filename
,
mimeFilename
string
)
error
{
func
addFilePart
(
w
*
multipart
.
Writer
,
varname
string
,
storage
*
FileStorage
,
filename
,
mimeFilename
string
)
error
{
file
,
err
:=
o
s
.
Open
(
filename
)
file
,
err
:=
s
torage
.
Open
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -128,14 +127,14 @@ func (r *remoteServer) SendBook(book *Book, storage *FileStorage, files []*File)
...
@@ -128,14 +127,14 @@ func (r *remoteServer) SendBook(book *Book, storage *FileStorage, files []*File)
for
i
,
f
:=
range
files
{
for
i
,
f
:=
range
files
{
varname
:=
fmt
.
Sprintf
(
"book%d"
,
i
)
varname
:=
fmt
.
Sprintf
(
"book%d"
,
i
)
filename
:=
fmt
.
Sprintf
(
"%d%s"
,
book
.
Id
,
f
.
FileType
)
filename
:=
fmt
.
Sprintf
(
"%d%s"
,
book
.
Id
,
f
.
FileType
)
if
err
:=
addFilePart
(
w
,
varname
,
storage
.
Abs
(
f
.
Path
)
,
filename
);
err
!=
nil
{
if
err
:=
addFilePart
(
w
,
varname
,
storage
,
f
.
Path
,
filename
);
err
!=
nil
{
w
.
Close
()
w
.
Close
()
return
err
return
err
}
}
}
}
if
book
.
CoverPath
!=
""
{
if
book
.
CoverPath
!=
""
{
if
err
:=
addFilePart
(
w
,
"cover"
,
storage
.
Abs
(
book
.
CoverPath
)
,
"cover.jpg"
);
err
!=
nil
{
if
err
:=
addFilePart
(
w
,
"cover"
,
storage
,
book
.
CoverPath
,
"cover.jpg"
);
err
!=
nil
{
w
.
Close
()
w
.
Close
()
return
err
return
err
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment