Convenience functions for flag testing

This commit is contained in:
Jakob Borg
2014-05-23 12:53:26 +02:00
parent 7bc36cbbd1
commit b60d648e22
6 changed files with 47 additions and 19 deletions

View File

@@ -149,9 +149,9 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo {
for _, repo := range m.nodeRepos[node] {
for _, f := range m.repoFiles[repo].Global() {
if f.Flags&protocol.FlagDeleted == 0 {
if !protocol.IsDeleted(f.Flags) {
size := f.Size
if f.Flags&protocol.FlagDirectory != 0 {
if protocol.IsDirectory(f.Flags) {
size = zeroEntrySize
}
tot += size
@@ -160,9 +160,9 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo {
}
for _, f := range m.repoFiles[repo].Need(m.cm.Get(node)) {
if f.Flags&protocol.FlagDeleted == 0 {
if !protocol.IsDeleted(f.Flags) {
size := f.Size
if f.Flags&protocol.FlagDirectory != 0 {
if protocol.IsDirectory(f.Flags) {
size = zeroEntrySize
}
have -= size
@@ -186,9 +186,9 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo {
func sizeOf(fs []scanner.File) (files, deleted int, bytes int64) {
for _, f := range fs {
if f.Flags&protocol.FlagDeleted == 0 {
if !protocol.IsDeleted(f.Flags) {
files++
if f.Flags&protocol.FlagDirectory == 0 {
if !protocol.IsDirectory(f.Flags) {
bytes += f.Size
} else {
bytes += zeroEntrySize
@@ -252,7 +252,7 @@ func (m *Model) Index(nodeID string, repo string, fs []protocol.FileInfo) {
lamport.Default.Tick(f.Version)
if debug {
var flagComment string
if f.Flags&protocol.FlagDeleted != 0 {
if protocol.IsDeleted(f.Flags) {
flagComment = " (deleted)"
}
l.Debugf("IDX(in): %s %q/%q m=%d f=%o%s v=%d (%d blocks)", nodeID, repo, f.Name, f.Modified, f.Flags, flagComment, f.Version, len(f.Blocks))
@@ -283,7 +283,7 @@ func (m *Model) IndexUpdate(nodeID string, repo string, fs []protocol.FileInfo)
lamport.Default.Tick(f.Version)
if debug {
var flagComment string
if f.Flags&protocol.FlagDeleted != 0 {
if protocol.IsDeleted(f.Flags) {
flagComment = " (deleted)"
}
l.Debugf("IDXUP(in): %s %q/%q m=%d f=%o%s v=%d (%d blocks)", nodeID, repo, f.Name, f.Modified, f.Flags, flagComment, f.Version, len(f.Blocks))
@@ -368,7 +368,7 @@ func (m *Model) Request(nodeID, repo, name string, offset int64, size int) ([]by
}
lf := r.Get(cid.LocalID, name)
if lf.Suppressed || lf.Flags&protocol.FlagDeleted != 0 {
if lf.Suppressed || protocol.IsDeleted(lf.Flags) {
if debug {
l.Debugf("REQ(in): %s: %q / %q o=%d s=%d; invalid: %v", nodeID, repo, name, offset, size, lf)
}
@@ -502,7 +502,7 @@ func (m *Model) protocolIndex(repo string) []protocol.FileInfo {
mf := fileInfoFromFile(f)
if debug {
var flagComment string
if mf.Flags&protocol.FlagDeleted != 0 {
if protocol.IsDeleted(mf.Flags) {
flagComment = " (deleted)"
}
l.Debugf("IDX(out): %q/%q m=%d f=%o%s v=%d (%d blocks)", repo, mf.Name, mf.Modified, mf.Flags, flagComment, mf.Version, len(mf.Blocks))

View File

@@ -232,7 +232,7 @@ func (p *puller) fixupDirectories() {
return nil
}
if cur.Flags&protocol.FlagDeleted != 0 {
if protocol.IsDeleted(cur.Flags) {
if debug {
l.Debugf("queue delete dir: %v", cur)
}
@@ -245,7 +245,7 @@ func (p *puller) fixupDirectories() {
return nil
}
if cur.Flags&uint32(os.ModePerm) != uint32(info.Mode()&os.ModePerm) {
if !permsEqual(cur.Flags, uint32(info.Mode())) {
err := os.Chmod(path, os.FileMode(cur.Flags)&os.ModePerm)
if err != nil {
l.Warnln("Restoring folder flags: %q: %v", path, err)
@@ -336,8 +336,8 @@ func (p *puller) handleBlock(b bqBlock) bool {
// For directories, making sure they exist is enough.
// Deleted directories we mark as handled and delete later.
if f.Flags&protocol.FlagDirectory != 0 {
if f.Flags&protocol.FlagDeleted == 0 {
if protocol.IsDirectory(f.Flags) {
if !protocol.IsDeleted(f.Flags) {
path := filepath.Join(p.dir, f.Name)
_, err := os.Stat(path)
if err != nil && os.IsNotExist(err) {
@@ -520,7 +520,7 @@ func (p *puller) handleEmptyBlock(b bqBlock) {
}
}
if f.Flags&protocol.FlagDeleted != 0 {
if protocol.IsDeleted(f.Flags) {
if debug {
l.Debugf("pull: delete %q", f.Name)
}

View File

@@ -109,3 +109,15 @@ func compareClusterConfig(local, remote protocol.ClusterConfigMessage) error {
return nil
}
func permsEqual(a, b uint32) bool {
switch runtime.GOOS {
case "windows":
// There is only writeable and read only, represented for user, group
// and other equally. We only compare against user.
return a&0600 == b&0600
default:
// All bits count
return a&0777 == b&0777
}
}