Skip to content

Commit b7c01b3

Browse files
committed
mem: add rudimentary FileInfo.Sys() implementation
This allows downstream users to act on file ownership. Signed-off-by: Dominik Menke <dom@digineo.de>
1 parent b0a534a commit b7c01b3

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

mem/file.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ func (s *FileInfo) IsDir() bool {
318318
defer s.Unlock()
319319
return s.dir
320320
}
321-
func (s *FileInfo) Sys() interface{} { return nil }
321+
func (s *FileInfo) Sys() interface{} {
322+
s.Lock()
323+
defer s.Unlock()
324+
return sysFromFileInfo(s)
325+
}
322326
func (s *FileInfo) Size() int64 {
323327
if s.IsDir() {
324328
return int64(42)

mem/file_unix.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright © 2015 Steve Francia <spf@spf13.com>.
2+
// Copyright 2013 tsuru authors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// +build linux aix darwin openbsd freebsd netbsd dragonfly js
16+
17+
package mem
18+
19+
import "syscall"
20+
21+
func sysFromFileInfo(s *FileInfo) interface{} {
22+
sys := &syscall.Stat_t{
23+
Uid: uint32(s.uid),
24+
Gid: uint32(s.gid),
25+
Size: 42,
26+
}
27+
if !s.dir {
28+
sys.Size = int64(len(s.data))
29+
}
30+
return sys
31+
}

mem/file_windows.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright © 2015 Steve Francia <spf@spf13.com>.
2+
// Copyright 2013 tsuru authors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// +build windows
16+
17+
package mem
18+
19+
func sysFromFileInfo(s *FileInfo) interface{} { return nil }

0 commit comments

Comments
 (0)