aboutsummaryrefslogtreecommitdiff
path: root/objects
diff options
context:
space:
mode:
Diffstat (limited to 'objects')
-rw-r--r--objects/object.go4
-rw-r--r--objects/object_tree.go41
-rw-r--r--objects/object_tree_test.go4
3 files changed, 42 insertions, 7 deletions
diff --git a/objects/object.go b/objects/object.go
index 4e096ad..b192912 100644
--- a/objects/object.go
+++ b/objects/object.go
@@ -138,3 +138,7 @@ func (ro RawObject) Object() (o Object, err error) {
}
return
}
+
+func ToRawObject(o Object) RawObject {
+ return RawObject{Type: o.Type(), Payload: o.Payload()}
+}
diff --git a/objects/object_tree.go b/objects/object_tree.go
index 2a8f982..609aa7e 100644
--- a/objects/object_tree.go
+++ b/objects/object_tree.go
@@ -41,6 +41,15 @@ type TreeEntryBase struct {
user, group string
}
+func baseFromExec(exec bool) (base TreeEntryBase) {
+ if exec {
+ base.acl = acl.ACLFromUnixPerms(0755)
+ } else {
+ base.acl = acl.ACLFromUnixPerms(0644)
+ }
+ return
+}
+
func (teb TreeEntryBase) ACL() acl.ACL {
return teb.acl
}
@@ -54,11 +63,14 @@ func (teb TreeEntryBase) Group() string {
}
func (teb TreeEntryBase) toProperties() properties {
- return properties{
- "acl": teb.acl.String(),
- "user": teb.user,
- "group": teb.group,
+ props := properties{"acl": teb.acl.String()}
+ if teb.user != "" {
+ props["user"] = teb.user
+ }
+ if teb.group != "" {
+ props["group"] = teb.group
}
+ return props
}
func (a TreeEntryBase) equalContent(b TreeEntryBase) bool {
@@ -70,6 +82,13 @@ type TreeEntryFile struct {
Ref ObjectId
}
+func NewTreeEntryFile(ref ObjectId, exec bool) TreeEntryFile {
+ return TreeEntryFile{
+ TreeEntryBase: baseFromExec(exec),
+ Ref: ref,
+ }
+}
+
func (tef TreeEntryFile) Type() TreeEntryType {
return TETFile
}
@@ -90,6 +109,13 @@ type TreeEntryDir struct {
Ref ObjectId
}
+func NewTreeEntryDir(ref ObjectId, exec bool) TreeEntryDir {
+ return TreeEntryDir{
+ TreeEntryBase: baseFromExec(exec),
+ Ref: ref,
+ }
+}
+
func (ted TreeEntryDir) Type() TreeEntryType {
return TETDir
}
@@ -110,6 +136,13 @@ type TreeEntrySymlink struct {
Target string
}
+func NewTreeEntrySymlink(target string, exec bool) TreeEntrySymlink {
+ return TreeEntrySymlink{
+ TreeEntryBase: baseFromExec(exec),
+ Target: target,
+ }
+}
+
func (tes TreeEntrySymlink) Type() TreeEntryType {
return TETSymlink
}
diff --git a/objects/object_tree_test.go b/objects/object_tree_test.go
index 3ec9e25..1949375 100644
--- a/objects/object_tree_test.go
+++ b/objects/object_tree_test.go
@@ -49,8 +49,6 @@ var (
"": acl.PermR | acl.PermW,
},
},
- user: "user4",
- group: "group4",
},
Ref: genId(0x33),
},
@@ -59,7 +57,7 @@ var (
testTreeSerialization = []byte("" +
"acl=u::rw-,g::r--,o::r--&group=group1&name=foo&ref=sha3-256:1111111111111111111111111111111111111111111111111111111111111111&type=file&user=user1\n" +
"acl=u::rw-,g::r--,o::r--&group=group3&name=baz&target=%2ff%c3%b6%c3%b6%26b%c3%a4r%2f%f0%9f%92%be&type=symlink&user=user3\n" +
- "acl=u::rw-,u:user1:rw-,g::r--,o::r--,m::rw-&group=group4&name=%f0%9f%98%83&ref=sha3-256:3333333333333333333333333333333333333333333333333333333333333333&type=file&user=user4\n" +
+ "acl=u::rw-,u:user1:rw-,g::r--,o::r--,m::rw-&name=%f0%9f%98%83&ref=sha3-256:3333333333333333333333333333333333333333333333333333333333333333&type=file\n" +
"acl=u::rwx,g::r-x,o::r-x&group=group2&name=bar&ref=sha3-256:2222222222222222222222222222222222222222222222222222222222222222&type=dir&user=user2\n")
)