Skip to content

Commit f3e17ae

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 2fb20ad commit f3e17ae

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

mem/file.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (s *FileInfo) IsDir() bool {
353353
defer s.Unlock()
354354
return s.dir
355355
}
356-
func (s *FileInfo) Sys() interface{} { return nil }
356+
357357
func (s *FileInfo) Size() int64 {
358358
if s.IsDir() {
359359
return int64(42)
@@ -363,6 +363,12 @@ func (s *FileInfo) Size() int64 {
363363
return int64(len(s.data))
364364
}
365365

366+
func (s *FileInfo) Sys() interface{} {
367+
s.Lock()
368+
defer s.Unlock()
369+
return sysFromFileInfo(s)
370+
}
371+
366372
var (
367373
ErrFileClosed = errors.New("File is closed")
368374
ErrOutOfRange = errors.New("out of range")

mem/file_unix.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
//go:build !windows
16+
// +build !windows
17+
18+
package mem
19+
20+
import "syscall"
21+
22+
func sysFromFileInfo(s *FileInfo) interface{} {
23+
sys := &syscall.Stat_t{
24+
Uid: uint32(s.uid),
25+
Gid: uint32(s.gid),
26+
Size: 42,
27+
}
28+
if !s.dir {
29+
sys.Size = int64(len(s.data))
30+
}
31+
return sys
32+
}

mem/file_windows.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
//go:build windows
16+
// +build windows
17+
18+
package mem
19+
20+
func sysFromFileInfo(s *FileInfo) interface{} { return nil }

0 commit comments

Comments
 (0)