@@ -33,7 +33,7 @@ func New() *Memory {
33
33
34
34
// Create returns a new file in memory from a given filename.
35
35
func (fs * Memory ) Create (filename string ) (billy.File , error ) {
36
- return fs .OpenFile (filename , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0 )
36
+ return fs .OpenFile (filename , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0666 )
37
37
}
38
38
39
39
// Open returns a readonly file from a given name.
@@ -51,15 +51,15 @@ func (fs *Memory) OpenFile(filename string, flag int, perm os.FileMode) (billy.F
51
51
return nil , os .ErrNotExist
52
52
}
53
53
54
- fs .s .files [fullpath ] = newFile (fs .base , fullpath , flag )
54
+ fs .s .files [fullpath ] = newFile (fs .base , fullpath , perm , flag )
55
55
return fs .s .files [fullpath ], nil
56
56
}
57
57
58
58
if f .isDir {
59
59
return nil , fmt .Errorf ("cannot open directory: %s" , filename )
60
60
}
61
61
62
- n := newFile (fs .base , fullpath , flag )
62
+ n := newFile (fs .base , fullpath , perm , flag )
63
63
n .content = f .content
64
64
65
65
if isAppend (flag ) {
@@ -79,12 +79,12 @@ func (fs *Memory) Stat(filename string) (billy.FileInfo, error) {
79
79
80
80
f , ok := fs .s .files [fullpath ]
81
81
if ok && ! f .isDir {
82
- return newFileInfo (fs .base , fullpath , fs .s .files [fullpath ].content .Len ()), nil
82
+ return newFileInfo (fs .base , fullpath , f . mode , fs .s .files [fullpath ].content .Len ()), nil
83
83
}
84
84
85
85
info , err := fs .ReadDir (fullpath )
86
86
if err == nil && len (info ) != 0 || f != nil && f .isDir {
87
- fi := newFileInfo (fs .base , fullpath , len (info ))
87
+ fi := newFileInfo (fs .base , fullpath , 0 , len (info ))
88
88
fi .isDir = true
89
89
return fi , nil
90
90
}
@@ -110,15 +110,15 @@ func (fs *Memory) ReadDir(base string) (entries []billy.FileInfo, err error) {
110
110
entries = append (entries , & fileInfo {name : parts [0 ], isDir : true })
111
111
}
112
112
113
- entries = append (entries , & fileInfo {name : parts [0 ], size : f .content .Len ()})
113
+ entries = append (entries , & fileInfo {name : parts [0 ], mode : f . mode , size : f .content .Len ()})
114
114
continue
115
115
}
116
116
117
117
if _ , ok := appendedDirs [parts [0 ]]; ok {
118
118
continue
119
119
}
120
120
121
- entries = append (entries , & fileInfo {name : parts [0 ], isDir : true })
121
+ entries = append (entries , & fileInfo {name : parts [0 ], mode : f . mode , isDir : true })
122
122
appendedDirs [parts [0 ]] = true
123
123
}
124
124
@@ -232,15 +232,17 @@ type file struct {
232
232
content * content
233
233
position int64
234
234
flag int
235
+ mode os.FileMode
235
236
isDir bool
236
237
}
237
238
238
- func newFile (base , fullpath string , flag int ) * file {
239
+ func newFile (base , fullpath string , mode os. FileMode , flag int ) * file {
239
240
filename , _ := filepath .Rel (base , fullpath )
240
241
241
242
return & file {
242
243
BaseFile : billy.BaseFile {BaseFilename : filename },
243
244
content : & content {},
245
+ mode : mode ,
244
246
flag : flag ,
245
247
}
246
248
}
@@ -318,14 +320,16 @@ func (f *file) Open() error {
318
320
type fileInfo struct {
319
321
name string
320
322
size int
323
+ mode os.FileMode
321
324
isDir bool
322
325
}
323
326
324
- func newFileInfo (base , fullpath string , size int ) * fileInfo {
327
+ func newFileInfo (base , fullpath string , mode os. FileMode , size int ) * fileInfo {
325
328
filename , _ := filepath .Rel (base , fullpath )
326
329
327
330
return & fileInfo {
328
331
name : filename ,
332
+ mode : mode ,
329
333
size : size ,
330
334
}
331
335
}
@@ -339,7 +343,7 @@ func (fi *fileInfo) Size() int64 {
339
343
}
340
344
341
345
func (fi * fileInfo ) Mode () os.FileMode {
342
- return os . FileMode ( 0 )
346
+ return fi . mode
343
347
}
344
348
345
349
func (* fileInfo ) ModTime () time.Time {
0 commit comments