Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ale
liber
Commits
78c5696d
Commit
78c5696d
authored
Feb 13, 2016
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved ExpandTilde to the util package
parent
2dd4bcbf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
13 deletions
+26
-13
cmd/liber/liber.go
cmd/liber/liber.go
+6
-13
util/tilde.go
util/tilde.go
+20
-0
No files found.
cmd/liber/liber.go
View file @
78c5696d
...
...
@@ -16,6 +16,7 @@ import (
"sync"
"git.autistici.org/ale/liber"
"git.autistici.org/ale/liber/util"
)
var
(
...
...
@@ -152,7 +153,7 @@ func doUpdate(db *liber.Database, dir string) {
}
func
doSync
(
db
*
liber
.
Database
,
remoteAddr
string
)
{
storage
:=
liber
.
NewFileStorage
(
e
xpandTilde
(
*
bookDir
))
storage
:=
liber
.
NewFileStorage
(
util
.
E
xpandTilde
(
*
bookDir
))
sc
:=
liber
.
NewRemoteServer
(
remoteAddr
)
if
err
:=
db
.
Sync
(
storage
,
sc
);
err
!=
nil
{
log
.
Fatal
(
err
)
...
...
@@ -181,8 +182,8 @@ func doSearch(db *liber.Database, query string) {
}
func
doHttpServer
(
db
*
liber
.
Database
,
addr
string
)
{
storage
:=
liber
.
NewRWFileStorage
(
e
xpandTilde
(
*
bookDir
),
2
)
cache
:=
liber
.
NewRWFileStorage
(
filepath
.
Join
(
e
xpandTilde
(
*
databaseDir
),
"cache"
),
2
)
storage
:=
liber
.
NewRWFileStorage
(
util
.
E
xpandTilde
(
*
bookDir
),
2
)
cache
:=
liber
.
NewRWFileStorage
(
filepath
.
Join
(
util
.
E
xpandTilde
(
*
databaseDir
),
"cache"
),
2
)
server
:=
liber
.
NewHttpServer
(
db
,
storage
,
cache
,
addr
)
log
.
Fatal
(
server
.
ListenAndServe
())
}
...
...
@@ -202,14 +203,6 @@ func b2i(b bool) int {
return
0
}
func
expandTilde
(
path
string
)
string
{
if
strings
.
HasPrefix
(
path
,
"~/"
)
{
curUser
,
_
:=
user
.
Current
()
return
filepath
.
Join
(
curUser
.
HomeDir
,
strings
.
TrimPrefix
(
path
,
"~/"
))
}
return
path
}
func
main
()
{
log
.
SetFlags
(
0
)
flag
.
Parse
()
...
...
@@ -221,7 +214,7 @@ func main() {
log
.
Fatal
(
"Must specify --book-dir"
)
}
dbdir
:=
e
xpandTilde
(
*
databaseDir
)
dbdir
:=
util
.
E
xpandTilde
(
*
databaseDir
)
db
,
err
:=
liber
.
NewDb
(
dbdir
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
...
...
@@ -237,7 +230,7 @@ func main() {
log
.
SetFlags
(
log
.
Ldate
|
log
.
Ltime
)
}
doUpdate
(
db
,
e
xpandTilde
(
*
bookDir
))
doUpdate
(
db
,
util
.
E
xpandTilde
(
*
bookDir
))
}
else
if
*
remotesync
!=
""
{
doSync
(
db
,
*
remotesync
)
}
else
if
*
search
{
...
...
util/tilde.go
0 → 100644
View file @
78c5696d
package
util
import
(
"os/user"
"path/filepath"
"strings"
)
// ExpandTilde replaces an initial "~/" in the given path with the
// current user's home directory. It is intended as a convenience for
// those cases where the provided path does not come from a shell,
// which would otherwise handle the expansion.
func
ExpandTilde
(
path
string
)
string
{
if
strings
.
HasPrefix
(
path
,
"~/"
)
{
if
u
,
err
:=
user
.
Current
();
err
==
nil
{
return
filepath
.
Join
(
u
.
HomeDir
,
path
[
2
:
])
}
}
return
path
}
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