Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
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
0
Merge Requests
0
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
Joshua
wendelin.core
Commits
931eebf5
Commit
931eebf5
authored
Mar 21, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
12d448f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
21 deletions
+47
-21
wcfs/misc.go
wcfs/misc.go
+42
-0
wcfs/wcfs.go
wcfs/wcfs.go
+5
-21
No files found.
wcfs/misc.go
View file @
931eebf5
...
...
@@ -25,6 +25,7 @@ import (
"fmt"
"io"
"math"
"strings"
"sync/atomic"
"syscall"
...
...
@@ -601,6 +602,47 @@ func tidmin(a, b zodb.Tid) zodb.Tid {
}
}
// ---- parsing ----
// parseWatch parses watch request wcfs received over /head/watch.
//
// watch <file> (@<at>|-)
func
parseWatch
(
msg
string
)
(
oid
zodb
.
Oid
,
at
zodb
.
Tid
,
err
error
)
{
defer
func
()
{
if
err
!=
nil
{
oid
=
zodb
.
InvalidOid
at
=
zodb
.
InvalidTid
err
=
fmt
.
Errorf
(
"bad watch: %s"
,
err
)
}
}()
msg
=
strings
.
TrimSuffix
(
msg
,
"
\n
"
)
if
!
strings
.
HasPrefix
(
msg
,
"watch "
)
{
return
0
,
0
,
fmt
.
Errorf
(
"not a watch request"
)
}
argv
:=
strings
.
Split
(
msg
[
len
(
"watch "
)
:
],
" "
)
if
len
(
argv
)
!=
2
{
return
0
,
0
,
fmt
.
Errorf
(
"expected 2 arguments, got %d"
,
len
(
argv
))
}
oid
,
err
=
zodb
.
ParseOid
(
argv
[
0
])
if
err
!=
nil
{
return
0
,
0
,
fmt
.
Errorf
(
"invalid oid"
)
}
switch
{
case
argv
[
1
]
==
"-"
:
at
=
zodb
.
InvalidTid
case
strings
.
HasPrefix
(
argv
[
1
],
"@"
)
:
at
,
err
=
zodb
.
ParseTid
(
argv
[
1
][
1
:
])
default
:
err
=
fmt
.
Errorf
(
"x"
)
// XXX just anything
}
if
err
!=
nil
{
return
0
,
0
,
fmt
.
Errorf
(
"invalid at"
)
}
return
oid
,
at
,
nil
}
// ---- make df happy (else it complains "function not supported") ----
...
...
wcfs/wcfs.go
View file @
931eebf5
...
...
@@ -1250,7 +1250,7 @@ func (watch *Watch) Open(flags uint32, fctx *fuse.Context) (nodefs.File, fuse.St
// XXX check flags?
w
:=
&
Watcher
{
sk
:
NewFileSock
(),
id
:
atomic
.
AddInt32
(
&
watch
.
id
,
+
1
),
id
:
atomic
.
AddInt32
(
&
watch
.
id
Next
,
+
1
),
fileTab
:
make
(
map
[
*
FileWatch
]
struct
{}),
}
...
...
@@ -1267,6 +1267,7 @@ func (watch *Watch) Open(flags uint32, fctx *fuse.Context) (nodefs.File, fuse.St
func
(
w
*
Watcher
)
serve
()
{
err
:=
w
.
_serve
()
// XXX log error if !close
// XXX close if was not closed?
// XXX locking
delete
(
w
.
head
.
watchTab
,
w
)
}
...
...
@@ -1316,29 +1317,12 @@ func (w *Watcher) _serve() (err error) {
}
// client-initiated request
msg
=
strings
.
TrimSuffix
(
msg
,
"
\n
"
)
msgv
=
strings
.
Split
(
msg
,
" "
)
if
!
(
len
(
msgv
)
==
3
&&
msgv
[
0
]
!=
"watch"
)
{
// XXX write to peer too
return
fmt
.
Errorf
(
"rx %d: invalid request"
,
stream
)
}
oid
,
err
:=
zodb
.
ParseOid
(
msgv
[
1
])
oid
,
at
,
err
=
parseWatch
(
msg
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"rx %d: bad watch: invalid oid"
)
// XXX write to peer too
return
fmt
.
Errorf
(
"rx %d: %s"
,
err
)
}
var
at
zodb
.
Tid
switch
{
case
msgv
[
2
]
==
"-"
:
at
=
zodb
.
InvalidTid
case
strings
.
HasPrefix
(
msgv
[
2
],
"@"
)
:
at
,
err
=
zodb
.
ParseTid
(
msgv
[
2
][
1
:
])
default
:
err
=
fmt
.
Errorf
(
"x"
)
// XXX just anything
}
if
err
!=
nil
{
return
fmt
.
Errorf
(
"rx %d: bad watch: invalid at"
)
}
}
}
...
...
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