mirror of https://github.com/perkeep/perkeep.git
fuse: add Truncate method to Handle
Change-Id: I8aff0473356d1e0a95489ba9d3d0c4a0435b16eb
This commit is contained in:
parent
47df629eb9
commit
16047a787f
|
@ -219,6 +219,8 @@ func nodeAttr(inode uint64, n Node) (attr Attr) {
|
||||||
//
|
//
|
||||||
// Setlkw
|
// Setlkw
|
||||||
//
|
//
|
||||||
|
// Truncate
|
||||||
|
//
|
||||||
// Write
|
// Write
|
||||||
//
|
//
|
||||||
type Handle interface {
|
type Handle interface {
|
||||||
|
@ -486,6 +488,10 @@ func (c *Conn) serve(fs FS, r Request) {
|
||||||
type writeAll interface {
|
type writeAll interface {
|
||||||
WriteAll([]byte, Intr) Error
|
WriteAll([]byte, Intr) Error
|
||||||
}
|
}
|
||||||
|
type truncate interface {
|
||||||
|
Truncate(uint64, Intr) Error
|
||||||
|
}
|
||||||
|
var trunc truncate
|
||||||
switch r.Valid {
|
switch r.Valid {
|
||||||
case SetattrLockOwner | SetattrSize, SetattrSize:
|
case SetattrLockOwner | SetattrSize, SetattrSize:
|
||||||
// Seen on Linux. Handle isn't set.
|
// Seen on Linux. Handle isn't set.
|
||||||
|
@ -494,6 +500,8 @@ func (c *Conn) serve(fs FS, r Request) {
|
||||||
shandle := c.handle[hid]
|
shandle := c.handle[hid]
|
||||||
if _, ok := shandle.handle.(writeAll); ok {
|
if _, ok := shandle.handle.(writeAll); ok {
|
||||||
shandle.trunc = true
|
shandle.trunc = true
|
||||||
|
} else if h, ok := shandle.handle.(truncate); ok {
|
||||||
|
trunc = h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.meta.Unlock()
|
c.meta.Unlock()
|
||||||
|
@ -501,11 +509,21 @@ func (c *Conn) serve(fs FS, r Request) {
|
||||||
// Seen on OS X; the Handle is provided.
|
// Seen on OS X; the Handle is provided.
|
||||||
if _, ok := handle.(writeAll); ok {
|
if _, ok := handle.(writeAll); ok {
|
||||||
shandle.trunc = true
|
shandle.trunc = true
|
||||||
|
} else if h, ok := handle.(truncate); ok {
|
||||||
|
trunc = h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if trunc != nil {
|
||||||
|
if err := trunc.Truncate(r.Size, intr); err != nil {
|
||||||
|
done(err)
|
||||||
|
r.RespondError(err)
|
||||||
|
}
|
||||||
|
done(s)
|
||||||
|
r.Respond(s)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("setattr %v", r)
|
|
||||||
if n, ok := node.(interface {
|
if n, ok := node.(interface {
|
||||||
Setattr(*SetattrRequest, *SetattrResponse, Intr) Error
|
Setattr(*SetattrRequest, *SetattrResponse, Intr) Error
|
||||||
}); ok {
|
}); ok {
|
||||||
|
@ -714,7 +732,12 @@ func (c *Conn) serve(fs FS, r Request) {
|
||||||
c.saveLookup(&s.LookupResponse, snode, r.Name, n2)
|
c.saveLookup(&s.LookupResponse, snode, r.Name, n2)
|
||||||
h, shandle := c.saveHandle(h2, hdr.Node)
|
h, shandle := c.saveHandle(h2, hdr.Node)
|
||||||
s.Handle = h
|
s.Handle = h
|
||||||
shandle.trunc = true
|
// Only set trunc if the handle implements WriteAll.
|
||||||
|
if _, ok := h2.(interface {
|
||||||
|
WriteAll([]byte, Intr) Error
|
||||||
|
}); ok {
|
||||||
|
shandle.trunc = true
|
||||||
|
}
|
||||||
done(s)
|
done(s)
|
||||||
r.Respond(s)
|
r.Respond(s)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue