Commit Graph

26 Commits

Author SHA1 Message Date
Oliver Bone 428eac8624
Add Chmod() method to File
`os.File` offers a `Chmod()` method. This is often safer and more direct
to use than `os.Chmod()` because it operates on an open file descriptor
rather than having to lookup the file by name. Without this, it's
possible for the target file to be renamed, in which case an
`os.Chmod()` would either fail or apply to any file that's taken its
place.

Therefore, add the `Chmod()` method to the `File` interface, and
implement it for all `File` implementations. The bulk of this change is
in `MemMapFs`, which required moving the chmod functionality down into
the `mem` package so that it can be shared between both `mem.File` and
`MemMapFs`.
2022-05-20 14:02:18 +01:00
KastenMike c2c1d1206e add modTime on folder creation 2022-01-10 11:50:49 +01:00
tdakkota 7b47fea3fc
fix(mem): do not overwrite old data in some cases (fixes #286) 2021-02-12 13:02:47 +03:00
Mike Futerko f3723fe04d Fix a typo 2020-12-08 20:57:36 +02:00
Mike Futerko cb1d580bf4 Fix Chown() pull request errors 2020-12-07 15:19:45 +02:00
Rafal Zajac d175ebcca8 mem.File.Truncate should use lock
Fixes: #272
2020-11-13 22:59:22 +01:00
Yerden Zhumabekov 84f9c83b7e mem: fix Write setting wrong offset
Signed-off-by: Yerden Zhumabekov <yerden.zhumabekov@gmail.com>
2020-09-02 11:39:23 +06:00
Yerden Zhumabekov d2521ec52d mem: fix code style in Seek
Signed-off-by: Yerden Zhumabekov <yerden.zhumabekov@gmail.com>
2020-09-02 11:39:23 +06:00
Michail Kargakis 900cf72eec
Merge pull request #167 from jslching/master
Return closed error in mem.File.Write() after Close()
2020-04-10 23:44:32 +02:00
Bohdan Lisovskyi 30c3c32863 add chown method 2020-01-22 16:25:31 +02:00
Brian Tiger Chow e151fe9493 fix ReadAt 2018-11-20 13:34:41 -05:00
Bjørn Erik Pedersen 787d034dfe Return error in Readdir on regular mem file
Fixes #169
2018-05-31 11:51:01 +02:00
elv-jon 0408d604d0 Return closed error in mem.File.Write() after Close() 2018-05-17 15:45:50 -07:00
Bjørn Erik Pedersen ec3a3111d1
mem: Make the File return io.ErrUnexpectedEOF
Instead of panic when reading beyond its borders.

This is in line with how the OS File works.

Fixes #152
2017-12-28 12:02:27 +01:00
Corentin Debains d29940f63d mem/file.go - Fix some races in accessing fields of FileData
* Splitting SetModeTime to avoid double locking
* Adding locks all over the place.
2017-09-30 22:59:59 -07:00
Sotirios Mantziaris 72b3142684 Eliminate go vet warnings 2017-01-09 23:53:20 +01:00
Jamie Wilkinson 52e4a6cfac Fixes a pass-by-value error in FileData.Name()
Fixes a pass-by-value error in FileData.Name() which causes the mutex to be copied, and use that method to retrieve the name of the file from a mem.File.  This really fixes the data race that motivated PR #95. (#96)

I can't explain why moving the lock improves the situation, nor why calling through the accessor Name() instead of locking and reading f.fileData.name is not the same, but go vet indicates that the mutex in fileData was being copied, not preserved.

The reproducing test case upstream is:
check out github.com/google/mtail
make install_deps
go test -race -timeout 1m -v -run TestProcessEvents --count=10000 ./vm

Prior to this change, the test reports a data race 3 times out of 10000, after, 0 times consistently.
2016-09-19 23:01:14 +02:00
Jamie Wilkinson 40ffa2c25c Fixes a data race caused by not locking the mem.FileData for read access. 2016-08-20 23:27:14 +10:00
Hanno Hecker bb3fe39966 set modtime on any write 2016-01-04 19:34:24 +01:00
Martin Bertschler f0b9fc1bdb Implement and test read only MemMapFs file handles
Fixes #53
2016-01-04 01:54:48 +01:00
Martin Bertschler a5f01f1106 replace mem.File handles with mem.FileData when mem.FileData is all we need 2016-01-04 00:36:01 +01:00
Martin Bertschler 0321b04b21 fix mem.DirMap and mem.Dir to only use *FileData and not *File handles 2016-01-04 00:18:26 +01:00
Martin Bertschler 7096d68458 mem.File is now mem.FileData and mem.File is a file handle with a pointer to a mem.FileData 2016-01-03 23:59:42 +01:00
Steve Francia 12f79b29b2 Update mem to keep things private 2015-12-10 15:13:36 -05:00
Martin Bertschler 37f7afc8d7 Fix artefacts from moving MemMapFs types into subpackage mem 2015-12-10 18:55:43 +01:00
Steve Francia 965d098e7c Moving memory structures and interfaces into sub package 2015-12-10 12:26:38 -05:00