-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add RemoveAll #12
add RemoveAll #12
Conversation
Don't merge; there is something wrong with this PR. Fixed |
* memfs: fix Stat for directories: isDir now returns true for them. * memfs: fix FileInfo Size for directories. * test: added further tests for Stat on directories
RemoveAll delegates to filesystem's RemoveAll if it is implemented. Otherwise, it falls back to a generic implementation. Semantics are the same as os.RemoveAll.
Codecov Report
@@ Coverage Diff @@
## master #12 +/- ##
==========================================
+ Coverage 82.55% 84.58% +2.02%
==========================================
Files 2 2
Lines 258 279 +21
==========================================
+ Hits 213 236 +23
+ Misses 29 28 -1
+ Partials 16 15 -1
Continue to review full report at Codecov.
|
memfs/memory.go
Outdated
} | ||
|
||
if p == "." || p == ".." { | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can test this easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, I haven't found any case where this can be reproduced from public methods...
memfs/memory.go
Outdated
func isInDir(dir, path string) bool { | ||
p, err := filepath.Rel(dir, path) | ||
if err != nil { | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can test it easily creating a path that cannot be relative from dir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only way to reproduce that (from public methods) is using Windows paths :s
* test: add test passing a relative path to RemoveAll. * memfs: simplify isInDir code using path package.
This PR adds RemoveAll function, with native implementation for
os
and fallback for other filesystems.RemoveAll code is based on standard
os.RemoveAll
and has the same behavior.Other fixes for Stat, ReadDir and Remove behavior with respect to directories.