Cleanup
This commit is contained in:
parent
0613779a78
commit
e512bd689e
@ -32,11 +32,12 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var inodeCnt uint64
|
//
|
||||||
|
// database
|
||||||
|
//
|
||||||
|
|
||||||
type database struct {
|
type database struct {
|
||||||
base string
|
base string
|
||||||
@ -175,7 +176,3 @@ func (this *database) parseVerName(name string) (time.Time, error) {
|
|||||||
|
|
||||||
return time.Unix(timestamp, 0), nil
|
return time.Unix(timestamp, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func allocInode() uint64 {
|
|
||||||
return atomic.AddUint64(&inodeCnt, 1)
|
|
||||||
}
|
|
||||||
|
4
dir.go
4
dir.go
@ -30,6 +30,10 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
// versionedDir
|
||||||
|
//
|
||||||
|
|
||||||
type versionedDir struct {
|
type versionedDir struct {
|
||||||
dirs map[string]*versionedDir
|
dirs map[string]*versionedDir
|
||||||
files map[string]*versionedFile
|
files map[string]*versionedFile
|
||||||
|
4
file.go
4
file.go
@ -30,6 +30,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
// versionedFile
|
||||||
|
//
|
||||||
|
|
||||||
type versionedFile struct {
|
type versionedFile struct {
|
||||||
node *versionedNode
|
node *versionedNode
|
||||||
inode uint64
|
inode uint64
|
||||||
|
4
meta.go
4
meta.go
@ -29,6 +29,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
// versionMetadata
|
||||||
|
//
|
||||||
|
|
||||||
type versionMetadata struct {
|
type versionMetadata struct {
|
||||||
Deleted []string `json:"deleted"`
|
Deleted []string `json:"deleted"`
|
||||||
path string
|
path string
|
||||||
|
17
node.go
17
node.go
@ -24,12 +24,15 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bazil.org/fuse"
|
"bazil.org/fuse"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
// versionedNode
|
||||||
|
//
|
||||||
|
|
||||||
type versionedNode struct {
|
type versionedNode struct {
|
||||||
path string
|
path string
|
||||||
info os.FileInfo
|
info os.FileInfo
|
||||||
@ -110,6 +113,14 @@ func (this *versionedNode) rebasedPath() string {
|
|||||||
return this.ver.rebasePath(this.path)
|
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) {
|
func (this *versionedNode) owner() (gid, uid uint32) {
|
||||||
stat := this.info.Sys().(*syscall.Stat_t)
|
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.Gid, attr.Uid = this.owner()
|
||||||
attr.Rdev = uint32(stat.Rdev)
|
attr.Rdev = uint32(stat.Rdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *versionedNode) String() string {
|
|
||||||
return fmt.Sprintf("%s (%s)", this.path, this.rebasedPath())
|
|
||||||
}
|
|
||||||
|
35
util.go
Normal file
35
util.go
Normal 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)
|
||||||
|
}
|
12
version.go
12
version.go
@ -32,6 +32,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
// version
|
||||||
|
//
|
||||||
|
|
||||||
type version struct {
|
type version struct {
|
||||||
base string
|
base string
|
||||||
parent *version
|
parent *version
|
||||||
@ -141,10 +145,6 @@ func (this *version) rebasePath(paths ...string) string {
|
|||||||
return filepath.Join(combined...)
|
return filepath.Join(combined...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *version) Root() (fs.Node, error) {
|
|
||||||
return this.root, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *version) dump(root *versionedDir, depth int) {
|
func (this *version) dump(root *versionedDir, depth int) {
|
||||||
indent := strings.Repeat("\t", depth)
|
indent := strings.Repeat("\t", depth)
|
||||||
for name, dir := range root.dirs {
|
for name, dir := range root.dirs {
|
||||||
@ -159,3 +159,7 @@ func (this *version) dump(root *versionedDir, depth int) {
|
|||||||
func (this *version) dumpRoot() {
|
func (this *version) dumpRoot() {
|
||||||
this.dump(this.root, 0)
|
this.dump(this.root, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *version) Root() (fs.Node, error) {
|
||||||
|
return this.root, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user