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
eb8e2553
Commit
eb8e2553
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
pass a FileStorage to Sync() so that it can find the files
parent
9285ee23
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/liber/liber.go
+4
-3
4 additions, 3 deletions
cmd/liber/liber.go
sync.go
+6
-6
6 additions, 6 deletions
sync.go
sync_test.go
+2
-1
2 additions, 1 deletion
sync_test.go
with
12 additions
and
10 deletions
cmd/liber/liber.go
+
4
−
3
View file @
eb8e2553
...
...
@@ -150,8 +150,9 @@ func doUpdate(db *liber.Database, dir string) {
}
func
doSync
(
db
*
liber
.
Database
,
remoteAddr
string
)
{
storage
:=
liber
.
NewFileStorage
(
expandTilde
(
*
bookDir
))
sc
:=
liber
.
NewRemoteServer
(
remoteAddr
)
if
err
:=
db
.
Sync
(
sc
);
err
!=
nil
{
if
err
:=
db
.
Sync
(
storage
,
sc
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
...
...
@@ -178,8 +179,8 @@ func doSearch(db *liber.Database, query string) {
}
func
doHttpServer
(
db
*
liber
.
Database
,
addr
string
)
{
storage
:=
liber
.
NewFileStorage
(
expandTilde
(
*
bookDir
),
2
)
cache
:=
liber
.
NewFileStorage
(
filepath
.
Join
(
expandTilde
(
*
databaseDir
),
"cache"
),
2
)
storage
:=
liber
.
New
RW
FileStorage
(
expandTilde
(
*
bookDir
),
2
)
cache
:=
liber
.
New
RW
FileStorage
(
filepath
.
Join
(
expandTilde
(
*
databaseDir
),
"cache"
),
2
)
server
:=
liber
.
NewHttpServer
(
db
,
storage
,
cache
,
addr
)
log
.
Fatal
(
server
.
ListenAndServe
())
}
...
...
This diff is collapsed.
Click to expand it.
sync.go
+
6
−
6
View file @
eb8e2553
...
...
@@ -23,7 +23,7 @@ const (
type
SyncClient
interface
{
DiffRequest
(
*
diffRequest
)
(
*
diffResponse
,
error
)
SendBook
(
*
Book
,
[]
*
File
)
error
SendBook
(
*
Book
,
*
FileStorage
,
[]
*
File
)
error
}
type
remoteServer
struct
{
...
...
@@ -110,7 +110,7 @@ func addFilePart(w *multipart.Writer, varname, filename, mimeFilename string) er
}
// SendBook uploads a book to the remote server.
func
(
r
*
remoteServer
)
SendBook
(
book
*
Book
,
files
[]
*
File
)
error
{
func
(
r
*
remoteServer
)
SendBook
(
book
*
Book
,
storage
*
FileStorage
,
files
[]
*
File
)
error
{
// Create a multipart request with the JSON-encoded metadata
// and the actual file contents as two separate mime/multipart
// sections.
...
...
@@ -125,14 +125,14 @@ func (r *remoteServer) SendBook(book *Book, files []*File) error {
for
i
,
f
:=
range
files
{
varname
:=
fmt
.
Sprintf
(
"book%d"
,
i
)
filename
:=
fmt
.
Sprintf
(
"%d%s"
,
book
.
Id
,
f
.
FileType
)
if
err
:=
addFilePart
(
w
,
varname
,
f
.
Path
,
filename
);
err
!=
nil
{
if
err
:=
addFilePart
(
w
,
varname
,
storage
.
Abs
(
f
.
Path
)
,
filename
);
err
!=
nil
{
w
.
Close
()
return
err
}
}
if
book
.
CoverPath
!=
""
{
if
err
:=
addFilePart
(
w
,
"cover"
,
book
.
CoverPath
,
"cover.jpg"
);
err
!=
nil
{
if
err
:=
addFilePart
(
w
,
"cover"
,
storage
.
Abs
(
book
.
CoverPath
)
,
"cover.jpg"
);
err
!=
nil
{
w
.
Close
()
return
err
}
...
...
@@ -220,7 +220,7 @@ func (db *Database) findMissing(srv SyncClient) chan string {
// Sync the local database with a remote one. This is a one-way
// synchronization: files missing on the remote side will be uploaded
// to it.
func
(
db
*
Database
)
Sync
(
remote
SyncClient
)
error
{
func
(
db
*
Database
)
Sync
(
storage
*
FileStorage
,
remote
SyncClient
)
error
{
var
wg
sync
.
WaitGroup
ch
:=
db
.
findMissing
(
remote
)
...
...
@@ -232,7 +232,7 @@ func (db *Database) Sync(remote SyncClient) error {
bookid
:=
ParseID
(
id
)
if
book
,
err
:=
db
.
GetBook
(
bookid
);
err
==
nil
{
if
files
,
err
:=
db
.
GetBookFiles
(
bookid
);
err
==
nil
{
if
err
:=
remote
.
SendBook
(
book
,
files
);
err
!=
nil
{
if
err
:=
remote
.
SendBook
(
book
,
storage
,
files
);
err
!=
nil
{
log
.
Printf
(
"SendBook(%s): %v"
,
id
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
sync_test.go
+
2
−
1
View file @
eb8e2553
...
...
@@ -24,6 +24,7 @@ func TestSync_Sync(t *testing.T) {
// Create a temporary directory to store uploads.
updir
,
_
:=
ioutil
.
TempDir
(
""
,
"ebook-upload-"
)
defer
os
.
RemoveAll
(
updir
)
clientStorage
:=
NewFileStorage
(
updir
)
td
,
db
:=
newTestDatabase
(
t
)
defer
td
.
Close
()
...
...
@@ -49,7 +50,7 @@ func TestSync_Sync(t *testing.T) {
defer
srv
.
Close
()
cl
:=
NewRemoteServer
(
srv
.
URL
)
err
:=
db
.
Sync
(
cl
)
err
:=
db
.
Sync
(
clientStorage
,
cl
)
if
err
!=
nil
{
t
.
Fatalf
(
"Sync(): %v"
,
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