This commit is contained in:
Alex Yatskov 2015-05-28 18:20:38 +09:00
parent 0613779a78
commit e512bd689e
8 changed files with 70 additions and 15 deletions

View File

@ -32,11 +32,12 @@ import (
"path/filepath"
"regexp"
"strconv"
"sync/atomic"
"time"
)
var inodeCnt uint64
//
// database
//
type database struct {
base string
@ -175,7 +176,3 @@ func (this *database) parseVerName(name string) (time.Time, error) {
return time.Unix(timestamp, 0), nil
}
func allocInode() uint64 {
return atomic.AddUint64(&inodeCnt, 1)
}

4
dir.go
View File

@ -30,6 +30,10 @@ import (
"path"
)
//
// versionedDir
//
type versionedDir struct {
dirs map[string]*versionedDir
files map[string]*versionedFile

View File

@ -30,6 +30,10 @@ import (
"os"
)
//
// versionedFile
//
type versionedFile struct {
node *versionedNode
inode uint64

View File

@ -29,6 +29,10 @@ import (
"strings"
)
//
// versionMetadata
//
type versionMetadata struct {
Deleted []string `json:"deleted"`
path string

17
node.go
View File

@ -24,12 +24,15 @@ package main
import (
"bazil.org/fuse"
"fmt"
"os"
"syscall"
"time"
)
//
// versionedNode
//
type versionedNode struct {
path string
info os.FileInfo
@ -110,6 +113,14 @@ func (this *versionedNode) rebasedPath() string {
return this.ver.rebasePath(this.path)
}
func (this *versionedNode) rebasedTermPath() string {
if this.ver.terminus == nil {
return this.rebasedPath()
}
return this.ver.terminus.rebasePath(this.path)
}
func (this *versionedNode) owner() (gid, uid uint32) {
stat := this.info.Sys().(*syscall.Stat_t)
@ -138,7 +149,3 @@ func (this *versionedNode) attr(attr *fuse.Attr) {
attr.Gid, attr.Uid = this.owner()
attr.Rdev = uint32(stat.Rdev)
}
func (this *versionedNode) String() string {
return fmt.Sprintf("%s (%s)", this.path, this.rebasedPath())
}

35
util.go Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package main
import "sync/atomic"
//
// utilities
//
var inodeCnt uint64
func allocInode() uint64 {
return atomic.AddUint64(&inodeCnt, 1)
}

View File

@ -32,6 +32,10 @@ import (
"time"
)
//
// version
//
type version struct {
base string
parent *version
@ -141,10 +145,6 @@ func (this *version) rebasePath(paths ...string) string {
return filepath.Join(combined...)
}
func (this *version) Root() (fs.Node, error) {
return this.root, nil
}
func (this *version) dump(root *versionedDir, depth int) {
indent := strings.Repeat("\t", depth)
for name, dir := range root.dirs {
@ -159,3 +159,7 @@ func (this *version) dump(root *versionedDir, depth int) {
func (this *version) dumpRoot() {
this.dump(this.root, 0)
}
func (this *version) Root() (fs.Node, error) {
return this.root, nil
}

BIN
vfs Executable file

Binary file not shown.