2023-12-30 22:44:31 +00:00
|
|
|
//go:build linux
|
2014-10-23 00:59:50 +00:00
|
|
|
|
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2014 The Perkeep Authors
|
2014-10-23 00:59:50 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2018-01-14 00:37:49 +00:00
|
|
|
"context"
|
2014-10-23 00:59:50 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"bazil.org/fuse"
|
|
|
|
"bazil.org/fuse/fs"
|
|
|
|
"go4.org/syncutil"
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/blob"
|
|
|
|
"perkeep.org/pkg/search"
|
2014-10-23 00:59:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const versionsRefreshTime = 1 * time.Minute
|
|
|
|
|
|
|
|
// versionsDir implements fuse.Node containing all roots. Within this node,
|
|
|
|
// - a directory permanode is represented with a fuse directory (roVersionsDir)
|
|
|
|
// - a file permanode is represented with a fuse directory (roFileVersionsDir)
|
|
|
|
// - a file version is represented with a fuse file (roFileVersion)
|
|
|
|
// In this way you can navigate to a file at a specific point in time.
|
|
|
|
// Basically is like `at` magic folder but the path (not the date) goes first.
|
|
|
|
// It is read-only.
|
|
|
|
type versionsDir struct {
|
|
|
|
fs *CamliFileSystem
|
|
|
|
|
|
|
|
mu sync.Mutex
|
|
|
|
lastQuery time.Time
|
2021-08-09 15:34:14 +00:00
|
|
|
m map[string]blob.Ref // ent name => permanode
|
|
|
|
children map[string]fs.Node // ent name => child node
|
2014-10-23 00:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *versionsDir) isRO() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *versionsDir) dirMode() os.FileMode {
|
|
|
|
if n.isRO() {
|
|
|
|
return 0500
|
|
|
|
}
|
|
|
|
return 0700
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *versionsDir) Attr(ctx context.Context, a *fuse.Attr) error {
|
|
|
|
a.Mode = os.ModeDir | n.dirMode()
|
|
|
|
a.Uid = uint32(os.Getuid())
|
|
|
|
a.Gid = uint32(os.Getgid())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *versionsDir) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
|
|
|
|
n.mu.Lock()
|
|
|
|
defer n.mu.Unlock()
|
|
|
|
if err := n.condRefresh(ctx); err != nil {
|
2022-06-20 21:04:57 +00:00
|
|
|
return nil, handleEIOorEINTR(err)
|
2014-10-23 00:59:50 +00:00
|
|
|
}
|
|
|
|
var ents []fuse.Dirent
|
|
|
|
for name := range n.m {
|
|
|
|
ents = append(ents, fuse.Dirent{Name: name})
|
|
|
|
}
|
2018-05-16 17:42:05 +00:00
|
|
|
Logger.Printf("fs.versions.ReadDir() -> %v", ents)
|
2014-10-23 00:59:50 +00:00
|
|
|
return ents, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *versionsDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
2018-05-16 17:42:05 +00:00
|
|
|
Logger.Printf("fs.versions: Lookup(%q)", name)
|
2014-10-23 00:59:50 +00:00
|
|
|
n.mu.Lock()
|
|
|
|
defer n.mu.Unlock()
|
|
|
|
if err := n.condRefresh(ctx); err != nil {
|
2022-06-20 21:04:57 +00:00
|
|
|
return nil, handleEIOorEINTR(err)
|
2014-10-23 00:59:50 +00:00
|
|
|
}
|
|
|
|
br := n.m[name]
|
|
|
|
if !br.Valid() {
|
|
|
|
return nil, fuse.ENOENT
|
|
|
|
}
|
|
|
|
|
|
|
|
nod, ok := n.children[name]
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
return nod, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nod = newROVersionsDir(n.fs, br, name)
|
|
|
|
|
|
|
|
n.children[name] = nod
|
|
|
|
|
|
|
|
return nod, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// requires n.mu is held
|
|
|
|
func (n *versionsDir) condRefresh(ctx context.Context) error {
|
|
|
|
if n.lastQuery.After(time.Now().Add(-versionsRefreshTime)) {
|
|
|
|
return nil
|
|
|
|
}
|
2018-05-16 17:42:05 +00:00
|
|
|
Logger.Printf("fs.versions: querying")
|
2014-10-23 00:59:50 +00:00
|
|
|
|
|
|
|
var rootRes, impRes *search.WithAttrResponse
|
|
|
|
var grp syncutil.Group
|
|
|
|
grp.Go(func() (err error) {
|
2018-01-16 23:03:16 +00:00
|
|
|
rootRes, err = n.fs.client.GetPermanodesWithAttr(ctx, &search.WithAttrRequest{N: 100, Attr: "camliRoot"})
|
2014-10-23 00:59:50 +00:00
|
|
|
return
|
|
|
|
})
|
|
|
|
grp.Go(func() (err error) {
|
2018-01-16 23:03:16 +00:00
|
|
|
impRes, err = n.fs.client.GetPermanodesWithAttr(ctx, &search.WithAttrRequest{N: 100, Attr: "camliImportRoot"})
|
2014-10-23 00:59:50 +00:00
|
|
|
return
|
|
|
|
})
|
|
|
|
if err := grp.Err(); err != nil {
|
2018-05-16 17:42:05 +00:00
|
|
|
Logger.Printf("fs.versions: GetRecentPermanodes error in ReadDir: %v", err)
|
2022-06-20 21:04:57 +00:00
|
|
|
return err
|
2014-10-23 00:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n.m = make(map[string]blob.Ref)
|
|
|
|
if n.children == nil {
|
|
|
|
n.children = make(map[string]fs.Node)
|
|
|
|
}
|
|
|
|
|
|
|
|
dr := &search.DescribeRequest{
|
|
|
|
Depth: 1,
|
|
|
|
}
|
|
|
|
for _, wi := range rootRes.WithAttr {
|
|
|
|
dr.BlobRefs = append(dr.BlobRefs, wi.Permanode)
|
|
|
|
}
|
|
|
|
for _, wi := range impRes.WithAttr {
|
|
|
|
dr.BlobRefs = append(dr.BlobRefs, wi.Permanode)
|
|
|
|
}
|
|
|
|
if len(dr.BlobRefs) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
dres, err := n.fs.client.Describe(ctx, dr)
|
|
|
|
if err != nil {
|
2018-05-16 17:42:05 +00:00
|
|
|
Logger.Printf("Describe failure: %v", err)
|
2022-06-20 21:04:57 +00:00
|
|
|
return err
|
2014-10-23 00:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Roots
|
|
|
|
currentRoots := map[string]bool{}
|
|
|
|
for _, wi := range rootRes.WithAttr {
|
|
|
|
pn := wi.Permanode
|
|
|
|
db := dres.Meta[pn.String()]
|
|
|
|
if db != nil && db.Permanode != nil {
|
|
|
|
name := db.Permanode.Attr.Get("camliRoot")
|
|
|
|
if name != "" {
|
|
|
|
currentRoots[name] = true
|
|
|
|
n.m[name] = pn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any children objects we have mapped that are no
|
|
|
|
// longer relevant.
|
|
|
|
for name := range n.children {
|
|
|
|
if !currentRoots[name] {
|
|
|
|
delete(n.children, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Importers (mapped as roots for now)
|
|
|
|
for _, wi := range impRes.WithAttr {
|
|
|
|
pn := wi.Permanode
|
|
|
|
db := dres.Meta[pn.String()]
|
|
|
|
if db != nil && db.Permanode != nil {
|
|
|
|
name := db.Permanode.Attr.Get("camliImportRoot")
|
|
|
|
if name != "" {
|
|
|
|
name = strings.Replace(name, ":", "-", -1)
|
|
|
|
name = strings.Replace(name, "/", "-", -1)
|
|
|
|
n.m["importer-"+name] = pn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n.lastQuery = time.Now()
|
|
|
|
return nil
|
|
|
|
}
|